2016-12-20 1 views
1

OpenCV에서 일부 함수에는 "오버로드 된 멤버"가 있습니다 (예 : Canny edge detection).opencv에서 "오버로드 된 멤버 함수"호출

제 질문은 : 코드에서이 오버로드 된 함수를 어떻게 호출합니까? cv2.Canny()를 호출하면 인수에 상관없이 항상 "standard Canny"이 호출됩니다.

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) 

: 나는 파이썬 2.7을 사용하고

여기

우분투 (14)에, 그리고 OpenCV의 3.1 (? 어쩌면이 C++에 비해,이 문제에 대한 문제가 될 것입니다 것은)는 MWE입니다 감사합니다

+0

전화 할 것으로 예상되는 기능은 무엇입니까? – Miki

+0

첫 번째 링크에있는 링크입니다. – Soltius

+0

몇 가지 코드를 보여줄 수 있습니까? [mcve] – Miki

답변

1

전화하려고하는 overloaded Canny function은 OpenCV 3.2에서 사용할 수 있습니다. 문서에 OpenCV 3.1에 해당 기능이 없다는 것을 알 수 있습니다.

OpenCV 3.1을 사용하고 있으므로이 기능이 없습니다.

github에서 OpenCV 3.2 (아직 공개되지 않음)을 다운로드하여 컴파일 할 수 있습니다.main site

+0

오, 와우, 고마워. 나는 존재하지 않았고 그 문서를보고 있었다. 여러 가지 이유로 지금은 다운로드 할 수 없지만 시도 할 때 직접 시도해보고 답변을 수락합니다. – Soltius

+0

@ Soltius OpenCV 3.2가 출시되었습니다. D – Miki

+0

와우, 그들은 2016 년 4 분기에 석방 할 것이라고 말했고 그들은 그것에 매달 렸습니다! 감사 :) – Soltius

관련 문제