Gil
Gil

Reputation: 77

OpenCV Best method to automatically draw a straight line through points

what OpenCV Python tool would be the best to draw a straight line between multiple 'points' on an image ? Something like a BestFitLine but for thresoldedimage, not a plot

Thanks

source image enter image description here

processed image (binary threshold) the black dot are supposed to be each individual crop source image (binary threshold

what I'd like to have

enter image description here

Upvotes: 0

Views: 1073

Answers (2)

Piotr Rarus
Piotr Rarus

Reputation: 952

I'm afraid Hough Lines will fail here. You could try ransac to get best estimated line, erase those points and run next ransac. Tough you still can encounter some troubles: exactly how many clusters do you want to recognize? You could set min score sample score for a line model. You'd also need to filter out horizontal lines.

There're ransac implementations in both scikit-learn and scikit-image.

Upvotes: 1

Lukashou-AGH
Lukashou-AGH

Reputation: 123

If you haven't tried yet, go with the OpenCV functions HoughLines() and HoughLinesP() to detect lines in an image.

Upvotes: 0

Related Questions