user3796043
user3796043

Reputation: 33

How do I use opencv to fit a line into a curve like this

I am wondering how can I achieve this?

tangent line

This is is the line I want to fit to the image.

I have tried Houghline transform. But I am unable to achieve this result, and I got something like this:

tangent line attempt

properties of the line: The line has to be tangent to the black region, not cutting through it.

Upvotes: 1

Views: 1277

Answers (2)

Andrey  Smorodov
Andrey Smorodov

Reputation: 10852

You can find contours, apply convex hull algorithm, then select edge you need.

Upvotes: 2

George Profenza
George Profenza

Reputation: 51837

The image is already thresholded, therefore you can easily findContours() This will give you a detailed list of points for the largest contours (you can choose to retrieve the largest as a flag).

If you want to simplify it, you can using approxPolyDP. Play with the epsilon parameter to get a simpler path.

I'm not sure how a single line can be a tangent to the majority of this complex outline.

Upvotes: 1

Related Questions