OpenCV 检测点是否沿着线/平面
我正在研究一种光学设备的自动校准,目前是手动执行的。校准的第一部分是确定光束是否照亮了一组“校准”点。
我正在使用 OpenCV,并对图像进行阈值处理和裁剪,只留下可能的相关点。我知道想要确定这些点是否沿着直线(水平);如果数量足够,光束就处于正确的位置! (这些点位于一条直线上,但光束通常是弯曲的,因此击中大多数点就足够了,有 21 个点在阈值化时显示为白色圆圈)。
我尝试使用直方图,但在阈值图像上,结果不正确,现在正在查看霍夫线,但这会检测来自边缘的直线,因为我想确定检测到的点是否位于一条线上。
这是我使用的阈值代码:
cvThreshold(output, output, 150, 256, CV_THRESH_BINARY);
从 1 到 640 个 bin(图像宽度)的任何位置的直方图结果都是 0 处的两条线,大约是接近最大值的 2/3。不是在没有阈值处理的情况下预期或获得的分布。
一些图片试图说明这一点(注意“嘈杂”的光点,这是系统设置的一个功能,无法克服):
想要的输出类型(为了说明,如果点在线上,这就是我需要知道的全部!)
任何帮助将不胜感激。一种想法是提取点的坐标并进行比较,但我不知道该怎么做。
I am working on a form of autocalibration for an optics device which is currently performed manually. The first part of the calibration is to determine whether a light beam has illuminated the set of 'calibration' points.
I am using OpenCV and have thresholded and cropped the image to leave only the possible relevant points. I know want to determine if these points lie along a stright (horizontal) line; if they a sufficient number do the beam is in the correct position! (The points lie in a straight line but the beam is often bent so hitting most of the points suffices, there are 21 points which show up as white circles when thresholded).
I have tried using a histogram but on the thresholded image the results are not correct and am now looking at Hough lines, but this detects straight lines from edges wwhere as I want to establish if detected points lie on a line.
This is the threshold code I use:
cvThreshold(output, output, 150, 256, CV_THRESH_BINARY);
The histogram results with anywhere from 1 to 640 bins (image width) is two lines at 0 and about 2/3rds through of near max value. Not the distribution expected or obtained without thresholding.
Some pictures to try to illistrate the point (note the 'noisy' light spots which are a feature of the system setup and cannot be overcome):
12 points in a stright line next to one another (beam in correct position)
Any help would be greatly appreciated. One thought was to extract the co-ordinates of the points and compare them but I don't know how to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果它对任何人都有帮助,这里是我使用的一些简单线性回归代码的非常基本(初稿)。
有更有效的方法可以做到这一点(请参阅 CodeCogs 或 AGLIB),但作为快速修复,此代码似乎可以工作。
为了在 OpenCV 中检测圆,我从这篇文章中删除了霍夫变换和改编的代码:
检测图像上的硬币(和适合的椭圆)
然后是细化坐标(删除任何异常值等)的情况,以确定圆是否位于回归的斜率和截距值的水平线上。
Incase it helps anyone here is a very basic (the first draft) of some simple linaear regression code I used.
There are more efficeint ways of doing this (see CodeCogs or AGLIB) but as quick fix this code seems to work.
To detect Circles in OpenCV I dropped the Hough Transform and adapeted codee from this post:
Detection of coins (and fit ellipses) on an image
It is then a case of refining the co-ordinates (removing any outliers etc) to determine if the circles lie on a horizontal line from the slope and intercept values of the regression.
获取阈值点的 x,y 坐标,然后执行线性回归以找到最佳拟合线。通过该线,您可以确定 r^2 值,从而有效地为您提供拟合质量。根据该健康测量,您可以确定校准是否成功。
这里是一个很好的讨论。
Obtain the x,y coordinates of the thresholded points, then perform a linear regression to find a best-fit line. With that line, you can determine the r^2 value which effectively gives you the quality of fit. Based on that fitness measure, you can determine your calibration success.
Here is a good discussion.
你可以做这样的事情,尽管它是一个近似值:
var dw = 决定以像素为单位的中等点宽度
maxdots 将是最好的结果......
you could do something like this, altough it is an aproximation:
var dw = decide a medium dot width in pixels
maxdots would be the best result...