'OpenCV distance between a circle and the upper edge of the image
[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!
Solution 1:[1]
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:
extBottom[1]
Tell me if I misunderstood.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Olli |
