Search code examples
c++opencvhistogram

OpenCV detect if points lie along line/plane


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)

The sort of output wanted (for illistration, if the points are on the line this is all I need to know!)

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.


Solution

  • 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.