【发布时间】:2017-05-24 12:33:56
【问题描述】:
我有一些检测圆形的代码,但我无法理解它是如何工作的。
从此代码:
- 如何找到圆的半径和中心点?
- `cv2.approxPolyDP' 检测圆的行为是什么?
现在在分段掩码中找到轮廓
contours, hierarchy = cv2.findContours(mask.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
按照轮廓矩形 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, ", ",
【问题讨论】:
标签: python opencv image-processing geometry