0

I am fairly new to openCV and am not sure how to proceed. I have this thresholded image:

thresholded image

And using this image, I need to calculate the distance between two points. The points are also unknown. Illustrated here: distance needed

I need to calculate 'd' value. It is the distance from the midpoint of the middle line to where the top line would have been. I am not sure how to proceed with identifying the points and getting the distance, any help would be appreciated!

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
  • What distance do you want to calculate? The number of pixels? For everything else you will need reference points and distances. – Klaus D. Jun 25 '21 at 05:32
  • Yes, I need the number of pixels. – Priya Sadh Jun 25 '21 at 06:07
  • I am by no means an OpenCV expert, but it seems to me you need to complete 4 steps to acheive this: 1) [cluster](https://stackoverflow.com/questions/17157296/detecting-clusters-of-white-pixels-in-an-image-using-opencv) the white pixels into the curved line ('middle line') and the horizontal line ('top line'). 2) [fit a curve](https://www.programmersought.com/article/31613718765/) to curved line and a [straight line](https://www.programmersought.com/article/66584665663/) to the horizontal line. 3)The bottom of the curved line should then be the minimum of the curve differentiated. – FinleyGibson Jun 25 '21 at 09:37
  • 4) use the x coordinate of point at the bottom of the curved line and the equation for the fit to the horizontal line to find the coordinate on the horizontal line, and then the difference between their respective y coordinates will be your distance d. – FinleyGibson Jun 25 '21 at 09:40
  • Thank you so much! I haven't tried it yet, but it seems like a viable solution. Although, how would I get the equation for the lines?? Won't I need a coordinate system for that? – Priya Sadh Jun 25 '21 at 14:25

1 Answers1

0

While I'm not sure about the selecting points part of your problem, calculating the distance between two points is trivial. You can imagine your two points as the beginning and end of the hypotenuse of a right triangle, and use Pythagoreans Theorem to find the length of that hypotenuse.

The math module has a distance method which takes two points, or you can just write the function yourself very simply.

Ben
  • 1
  • 1