OpenCV 圆到图像上边缘的距离
[Screenshot] 1 我需要计算图像上边缘与灰度之间的距离圆圈,如所附屏幕截图所示。首先,如何提取圆的坐标?如何计算图像上边缘与这个灰色圆圈之间的垂直距离? 作为额外信息,灰色圆圈代表白色轮廓的最低点。我需要找到它的 x 和 y 坐标。我想到的一个方法是借助圆心和上边缘之间的垂直距离。或者圆心与 y=0 的水平线(即图像的第一行像素)之间的距离。 这就是我创建灰色圆圈的方法:
mask = cv2.dilate(mask, None, iterations=2)
cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = max(cnts, key=cv2.contourArea)
extBottom = tuple(c[c[:, :, 1].argmax()][0])
circle_Lowest = cv2.circle(mask, extBottom, 4, (127, 0, 0), -1)
提前谢谢您!
[Screenshot] 1 I need to calculate the distance between the upper edge of the image and the grey circle, as in the attached screenshot. Firstly, how do I extract the coordinates of the circle? And how do I calculate the vertical distance between the upper edge of the image and this grey circle?
As extra information, the grey circle represents the lowest point of the white contour. And I need to find its x and y coordinates. A method that I have thought of is with the help of this vertical distance between the center of the circle and the upper edge. Or the distance between the center of the circle and a horizontal line with y=0 (so the first line of pixels of the image).
This is how I got the grey circle to be created:
mask = cv2.dilate(mask, None, iterations=2)
cnts = cv2.findContours(mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
c = max(cnts, key=cv2.contourArea)
extBottom = tuple(c[c[:, :, 1].argmax()][0])
circle_Lowest = cv2.circle(mask, extBottom, 4, (127, 0, 0), -1)
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不清楚你觉得自己被困在哪里。
您的圈子坐标位于 extBottom 中。
圆心到图像顶部之间的距离就是它的 y 坐标,因为 OpenCV 中的坐标是从左到右的 x 和从上到下的 y:
如果我理解错误,请告诉我。
It's not clear to me where you feel you are stuck.
Your circle's coordinates are in extBottom.
The distance between the center of the circle to the top of the image is just its y coordinate as coordinates in OpenCV are x from left to right and y from top to bottom:
Tell me if I misunderstood.