In OpenCV verfügen einige Funktionen über ein "überladenes Element" (z. B. Canny edge detection).Aufrufen einer "überladenen Elementfunktion" in opencv
Meine Frage ist: Wie kann ich diese überladene Funktion in meinem Code aufrufen? Wenn ich cv2.Canny() anrufe, wird es immer "standard Canny" aufrufen, egal welche Argumente.
Ich verwende Python 2.7 (? Vielleicht wird ein Thema für dieses Problem sein, im Vergleich zu C++) und OpenCV 3.1, auf Ubuntu 14.
Hier ist ein 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)
Danke
Welche Funktion erwarten Sie zu rufen? – Miki
Der erste Link. – Soltius
Können Sie Code anzeigen? [mcve] – Miki