The convex hull indices are not monotonous
조회수 1073회
cv2.error: OpenCV(4.3.0) C:\opencv_sources\opencv-4.3.0\modules\imgproc\src\convhull.cpp:360: error: (-5:Bad argument) The convex hull indices are not monotonous, which can be in the case when the input contour contains self-intersections in function 'cv::convexityDefects'
에러가 어쩌다가 발생합니다. hull = cv.convexHull(max_contour, returnPoints=False)
defects = cv.convexityDefects(max_contour, hull)
코드를 사용했고 defects = cv.convexityDefects(max_contour, hull)부분에서 계속 에러가 생깁니다 아래는 소스코드 일부입니다.
무조건 에러는 아니고 실행되다가 갑자기 에러가 뜨면서 꺼져버립니다.
hull = cv2.convexHull(cnt) #cv2.convexHull()를 활용해 윤곽선에서 블록 껍질을 검출합니다.
#볼록선의 모든 좌표를 hull에 담아 리턴
#cv2.convexHull(윤곽선, 방향)을 의미합니다.
#윤곽선은 윤곽선 검출 함수에서 반환되는 구조를 사용합니다.
#방향은 검출된 볼록 껍질의 볼록점들의 인덱스 순서를 의미합니다.
#방향이 True라면 시계 방향, False라면 반시계 방향으로 정렬됩니다.
cv2.drawContours(drawing2, [hull], 0, (0, 0, 255), 0) # color red
#max_contour2 = np.squeeze(cnt)
#polygon = Polygon(max_contour2)
#Polygon 객체의 is_simple의 리턴값이 False라면 self-intersections가 컨투어에 포함된 것입니다.
#convexityDefects 함수 처리를 하지 못하도록 처리합니다.
#if polygon.is_simple == True:
#hull = cv.convexHull(max_contour, returnPoints=False)
#defects = cv.convexityDefects(max_contour, hull)
hull = cv2.convexHull(cnt, returnPoints=False) #반시계 방향으로 인덱스 순서,윤곽선과 외곽선의 교점만 반환 즉 꼭짓점 반환
defects = cv2.convexityDefects(cnt, hull)
-
(•́ ✖ •̀)
알 수 없는 사용자
댓글 입력