简体   繁体   English

OpenCV 通过点自动绘制直线的最佳方法

[英]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 ?哪种 OpenCV Python 工具最适合在图像上的多个“点”之间绘制直线? Something like a BestFitLine but for thresoldedimage, not a plot类似于 BestFitLine 但对于阈值图像,而不是情节

Thanks谢谢

source image源图像在此处输入图片说明

processed image (binary threshold) the black dot are supposed to be each individual crop处理后的图像(二进制阈值)黑点应该是每个单独的作物源图像(二进制阈值

what I'd like to have我想要什么

在此处输入图片说明

I'm afraid Hough Lines will fail here.恐怕 Hough Lines 会在这里失败。 You could try ransac to get best estimated line, erase those points and run next ransac .您可以尝试ransac以获得最佳估计线,擦除这些点并运行下一个ransac Tough you still can encounter some troubles: exactly how many clusters do you want to recognize? Tough 你还是会遇到一些麻烦:你到底想识别多少个簇? 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 . scikit-learnscikit-image中都有ransac实现。

如果您还没有尝试过,请使用 OpenCV 函数HoughLines()HoughLinesP()来检测图像中的线条。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM