2012-12-05 2 views
2

나는 이미 게시물 herehere을 읽었지 만 오류가 해결되지 않습니다.함수에서 OpenCv 오류 ConvexityDefects

이 작동해야 위의 게시물에 따르면 내 코드

vector<Vec4i> defects; 
vector<vector<int> >hull(contours.size()); 
for (int i = 0; i < contours.size(); i++) 
{ 
    convexHull(contours[i], hull[i], false, false); 
    if(contours[i].size() > 3) 
     convexityDefects(contours[i], hull[i], defects[i]); 
} 

,하지만하지 않습니다. 나는 여전히 오류가 발생합니다.
error: (-215) hull.checkVector(1, CV_32S) > 2 in function convexityDefects
정말 여기에서 문제가 보이지 않습니다.

답변

2

좋아요, 문제는 주로 이상한 이유로 인해 선체가 단지 직선 (2 점만으로 구성된 의미) 인 매우 작은 윤곽을 가졌기 때문입니다. 그래서 오류가 벡터의 유형과 관련이있는 것으로 보이는 다른 게시물 이외의 선체 벡터의 크기를 참조했습니다. 단지 if(hulls[i].size() > 2)
if(contours[i].size() > 3) 를 교체 그래서

는 잘 작동합니다.

0

opencv references에 보도 된 바와 같이 : 특히

ConvexityDefects(contour, convexhull, storage) → convexity_defects 
    Finds the convexity defects of a contour. 

Parameters: 
    contour (CvArr or CvSeq) – Input contour 
    convexhull (CvSeq) – Convex hull obtained using ConvexHull2 that should contain pointers or indices to the contour points, not the hull points themselves (the return_points parameter in ConvexHull2 should be 0) 
    storage (CvMemStorage) – Container for the output sequence of convexity defects. If it is NULL, the contour or hull (in that order) storage is used 

는 두 번째 매개 변수를 살펴 : 당신이이 ConvexHull2 사용하여 얻을 수있다 확신?

+0

안녕하세요, 저는 OpenCV 2.1을 사용하고 있지 않습니다. 2.4에서 작동합니다. [opencv references] (http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=convexhull#convexitydefects)에 따르면 나는 사용해야하고 문서에 언급 된 convexHull 알고리즘을 사용하고 있습니다. 매개 변수 "returnPoints = false" – moatilliatta

+0

if 문을 제거하려고합니까? –

+0

아직 작동하지 않습니다. – moatilliatta