admin管理员组文章数量:1387441
I need to find the center of a shape in an image. After contouring and some filtering, I get this shape
I need the center of the "inner" circle you can see on the picture. I tried with convex Hull and the traditional algorithm with distanceTransform, but in this case, the circle touches the external part of the contour. Is there a simple, or not-so-simple solution to get the center of this circle ?
[EDIT] some details
I need to find the center of a shape in an image. After contouring and some filtering, I get this shape
I need the center of the "inner" circle you can see on the picture. I tried with convex Hull and the traditional algorithm with distanceTransform, but in this case, the circle touches the external part of the contour. Is there a simple, or not-so-simple solution to get the center of this circle ?
[EDIT] some details
Share Improve this question asked Mar 17 at 15:38 rvil76rvil76 1599 bronze badges 2- There is no inner circle. A circle needs to be closed. The inner part of the lined curve is not a circle. Inner means in this case, inside your lined curve. Please identify exactly what part you want to extract. Also post your result and identify why it does not work. – fmw42 Commented Mar 17 at 16:23
- show the source data, before your contouring. when you present that, I've got a solution for you. – Christoph Rackwitz Commented Mar 17 at 17:37
1 Answer
Reset to default 0I have found a solution, using floodFill and convexHull : I first fill my "banana" in gray, then draw the convex hull and fill inside in white. With a threshold, I only keep the inner line of the banana.
mask = np.zeros(img.shape[:2], np.uint8)
cv2.drawContours(mask,contours, c[0], 128, 3) #c[0] is the indes of kept contour
dist = cv2.distanceTransform(mask, cv2.DIST_L2, 0)
_, max_val, _, max_indx = cv2.minMaxLoc(dist)
(x, y), radius = max_indx, max_val
cv2.floodFill(mask, None, (x, y), 128) # floodFill contour in gray
cv2.drawContours(mask,hull, c[0], 128, 3)# draw convexHull in gray
cv2.floodFill(mask, None, c[1:3], 255) #c[1:3] is the center of inscribed circle of hull
_,tresh = cv2.threshold(mask,192,255,cv2.THRESH_BINARY)
# now I can go back to standard contour process
本文标签: pythonCenter of inner part of bananashaped contourStack Overflow
版权声明:本文标题:python - Center of inner part of banana-shaped contour - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744550272a2612142.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论