1 | initial version |
What here is the exact distance you're trying to measure? Between the tip and the vertical black?
Is the fiber always black and the reference surface always black while the rest is light colored? If so it might be pretty easy.
Since you're already doing contour detection, I'm assuming you know the basics.
Convert the image to grayscale and use a threshold to binarize the image between black and white. (This may take some work to get right. I just picked 100 as my threshold, and it worked great, but I expect you may not have totally consistent lighting.)
Now perform connected components (if you do the with stats version it gives you the bounding boxes already.) and you can see that your two largest components are the reference surface and the fiber. You can also distinguish the fiber because it's more rectangle than square and in the middle of the frame. (Again, up to your situation). So now you have the bounding box, and the edge of the surface, so there you go.
If the assumptions don't hold, edit your question with some more details and we'll se what we can do.