Webcam Laser Rangefinder
Project Leaders:
Howard Chen, Eric Schelin
A slightly more detailed version is attached as a Microsoft Word Document.
Objective:
Calculate the distance of an object in a simple, reliable, and accurate manner.
Theory:
Distance-
A laser that is mounted a fixed distance below and parallel to the camera would result in a vertical distance between the center of the image and the laser dot that is inversely proportional to the object’s distance.
Finding Brightest Pixel-
The laser dot would appear as the brightest red spot in the picture, thus the largest red value of the pixel array should be located at the laser dot. Since the laser is mounted parallel to the camera, the height of the laser dot would always be in the lower half of image. Since the laser is mounted in the center of the camera, the laser dot would be located within the middle columns of the image. This reduces the area to find the brightest pixel, making the algorithm faster and more reilable.
Implementation:
The algorithm was written in Java and establishes a socket connection with Roborealm. Utilizing Roborealm simplifies development because it eliminates the need to write an interface with the webcam. Since Roborealm provides the code that establishes a socket connection with the program, all that was needed was to code the algorithm. The algorithm converts the 1D array into a 3D array and searches in the specified area for the brightest red pixel. Once the laser dot’s distance from center is calculated, a box is drawn around the specified area that was searched and the image is converted back to a 1D array and transferred back to Roborealm to be displayed. Though faint, the crosshair is the location of the laser dot. Information on setting up Roborealm is available at http://www.roborealm.com/help/Socket_Program.php . Please refer to the source code if more information is needed.
Calibration:
A reading of the pixel from center was taken every five inches from the webcam and a power regression line was fitted to the data points. The first measurement was taken at the point in which the laser dot was picked up by the camera. The last measurement was taken at the point that any further change in distance would result in an unnoticeable change in pixels from center.
The regression equation was entered into the code and the distance measurement was transferred back into Roborealm.
Results:
Running the regression line on the test data resulted in a maximum error of 6%. The error was at most 10% when measurements were taken on actual objects. The image processing algorithm would find the laser dot in most situations. Reflections and very bright lights seem to be the only problems associated with the image processing algorithm.
Conclusions:
It is amazing to get the results that were achieved, especially given the simplicity in the image processing and the distance calculating algorithms. More accurate results could be achieved, but the complexity would increase exponentially.
Improvements:
Running the algorithm without converting from a 1D to a 3D array and back would greatly increase the processing speed. Using a laser line instead of a Dot would enable a range of distance measurements to be taken rather than at one point.
References:
http://www.pages.drexel.edu/~twd25/webcam_laser_ranger.html
http://www.roborealm.com