Calling an "overloaded member function" in opencv

280 views Asked by At

In OpenCV, some functions have an "overloaded member" counterpart (for example, Canny edge detection).

My question is : how do I call this overloaded function in my code? If I call cv2.Canny(), it will always call the "standard Canny" no matter the arguments.

I'm using Python 2.7 (maybe that will be an issue for this problem, compared to C++ ?) and OpenCV 3.1, on Ubuntu 14.

Here is a 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)

Thanks

1

There are 1 answers

3
Miki On BEST ANSWER

The overloaded Canny function you are trying to call is available from OpenCV 3.2 . You can see in the doc for OpenCV 3.1 that the function is not present.

Since you're using OpenCV 3.1, you don't have that function.

You can download the OpenCV 3.2 (still not released) from the github and compile it. from the main site