我有一些代码检测圆形形状,但我无法理解它是如何工作的。OpenCV - 检测圆形形状
从这个代码:
- 我怎样才能找到圆的半径和中心点?
- `cv2.approxPolyDP'用于检测圆圈的行为是什么?
现在找到的轮廓在分段面具
contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
排序轮廓WRT轮廓矩形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, ", ",