원형 모양을 감지하는 코드가 있지만 어떻게 작동하는지 이해할 수 없습니다.OpenCV - 원형 모양 감지
- 어떻게 내가 원의 반지름과 중심점을 찾을 수 있습니다 :이 코드에서
?
- 'cv2.approxPolyDP'가 원을 감지하는 동작은 무엇입니까?
지금 세그먼트 마스크
contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
정렬에 윤곽을 찾을 윤곽 WRT 등고선 RECT X
contours.sort(key = lambda x:cv2.boundingRect(x)[0])
for contour in contours:
approx = cv2.approxPolyDP(contour, 0.01*cv2.arcLength(contour,True), True)
if len(approx) > 8:
# Find the bounding rect of contour.
contour_bounding_rect = cv2.boundingRect(contour)
mid_point = contour_bounding_rect[0] + contour_bounding_rect[2]/2, contour_bounding_rect[1] + contour_bounding_rect[3]/2
print mid_point[1]/single_element_height, ", ",