在 opencv 中调用 "overloaded member function"

Calling an "overloaded member function" in opencv

在 OpenCV 中,某些函数具有 "overloaded member" 对应项(例如,Canny edge detection)。

我的问题是:如何在我的代码中调用这个重载函数?如果我调用 cv2.Canny(),无论参数如何,它总是会调用“standard Canny”。

我正在使用 Python 2.7(与 C++ 相比,这可能是这个问题的一个问题?)和 OpenCV 3.1,在 Ubuntu 14.

这是一个 MWE :

import cv2
import numpy as np

#getting gradient of image in x and y directions
def imgradient(img, sobel):
    sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=sobel)
    sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=sobel)
    return (sobelx,sobely)

#open image
IMG=cv2.imread("path_to_my_image") #replace with actual path
h = IMG.shape[0]; w = IMG.shape[1]

#Canny parameters : thresholds and kernel size
upper=5; lower=5; SIZE_KERNEL=3

#computing gradients (needed as arguments for overloaded Canny)
sobels=imgradient(IMG,3)
sobelx=sobels[0]
sobely=sobels[1];

output=np.zeros((h,w))

#trying to call overloaded Canny
cv2.Canny(sobelx,sobely,output,lower,upper);
#get error "only length-1 arrays can be converted to Python scalars"
#because the code is actually calling the standard Canny (second link)
edges = cv2.Canny(IMG, lower, upper, apertureSize=SIZE_KERNEL)
#works fine, but this is not the Canny I'm looking for (read this line in Obi-Wan's voice)

谢谢

overloaded Canny function you are trying to call is available from OpenCV 3.2 . You can see in the doc for OpenCV 3.1表示该功能不存在

由于您使用的是 OpenCV 3.1,因此您没有该功能。

您可以从 github and compile it. from the main site

下载 OpenCV 3.2 (仍未发布)