Here's my first real test of measuring the flatness of my gantry with a laser and webcam sensor

This whole process of measuring flatness is quite amazing for anyone needing to measure with a high degree of precision.  I’m sure there are specialized tools that do the exact same thing as this but cost many thousands.

The camera sensor is mounted at 90 degree angle so the wide direction is vertical. This gives a high coverage to sense the beam and also rescues power source based noise like PWM noise in switching power supplies.

The laser beam can be a point or a preferred horizontal line (like in a self leveling laser that I am using). We take the mean of each row (ex 1080 pixels wide) reshaping the 2D image into a 1D array. We then take this 1D array and fit a gaussian curve to it to find the center point. Finally converting the pixel position into physical height from calculations based on the physical size of the sensor to its resolution.

With this method you can spend $30 on a laser and $15 on a webcam and be able to measure flatness to a micron or less over a large distance like an axes on a CNC machine.

I didn’t come up with this whole idea but wrote a new tool based on the old Java tool. This one is written in Python, handles full HD streams at higher frame rates, more features like outlier removal, replacing samples, QT based GUI with helper popups. Best of all, It’s written in Python and everyone loves python! For those interested in this I highly recommend reading the original thread located here where they go over other alternatives like the stretch wire with a microscope camera:http://www.mycncuk.com/threads/12966-DIY-Laser-levelling-using-webcam-and-laser-level

My work with going through the whole process including the full development of the new Python tool is located on the PrintNC Discord https://discord.com/channels/648972213734604807/1078447519517921392 You will have to make a Discord account and join the PrintNC Discord in order for that link to work. But it's free and a great community!

It’s really easy to get all this setup and working. I used this webcam and took it apart: https://www.amazon.ca/dp/B07VL7BNLZ made a simple 3d printed holder and epoxied some steel to the bottom of it. 

My software source code including binary releases can be found on GitHub: https://github.com/bhowiebkr/laser-level-webcam