Webcam Ruler
This instructable explains how to measure object dimensions remotely using a camera, a ruler, and simple ratios.
The supplied software is easy to use which makes it an ideal learning tool.
All you require is a webcam, Processing 3 software, and a ruler.
Excluding the webcam, the cost of this project is less than $5.00
Images
- The length of the red line in the cover photo, as measured by the webcam, is 8.5 inches
- Photo 2 confirms that the distance is indeed 8.5 inches
- Photo 3 is a screen shot of a dimension being measured in mm
Video
- The video shows the webcam ruler in operation
Parts Required
The following parts are required:
- 1 only 12 inch / 300mm ruler
- 1 only webcam ... I am using a Logitech Quickcam Pro 9000 but any webcam should work
- Processing 3 software from https://processing.org/download/
Theory
The image sensor within a camera may be regarded as a sheet of paper that is divided into a number of small squares called pixels (picture elements).
Assume that your webcam can see a standard ruler.
To measure an object dimensions in inches:
- record the pixel location for zero inches on the ruler
- record the pixel location for 12 inches on the ruler
- subtract these pixel locations to get the ruler-length in pixels
- repeat steps 1-3 to get the object-length in pixels
- the object length in inches is equal to:
object-length (inches) = object-length (pixels) / ruler-length (pixels) * 12 ......... (1)
To measure an object dimensions in millimetres:
- record the pixel location for zero on the ruler
- record the pixel location for 300mm on the ruler
- subtract these pixel locations to get the ruler-length in pixels
- repeat steps 1-3 to get the object-length in pixels
- the object length in mm is equal to:
object-length (mm) = object-length (pixels) / ruler-length (pixels) * 300 .............. (2)
Measurement accuracy depends on your camera resolution ... the more pixels the better.
The camera should be positioned directly overhead without any trapezoid distortion.
Software
Installation
- Download and install Processing 3 from https://processing.org/download/
- Download the attached file “webcam_ruler.pde”
- Launch Processing 3 ... an empty sketch similar to Arduino will appear.
- Copy the contents of “webcam_ruler.pde” to the sketch ... use a text editor NOT a word processor
- Save the sketch as “webcam_ruler” (without the quotes)
- Left-click the top-left button to run [1]
Note:
[1]
This sketch requires that the following video library is installed:
- Left-click "Sketch | Import Library ... | Add library" (photo1)
- Type video in the search bar (photo 2)
- Select "Video | GSteamer-based video library for Processing"
- Now left-click "Install"
A green tick will appear when the process is complete.
Downloads
Configuring Your Camera
The software will automatically recognise your camera and list various configurations. Each configuration comes with a number inside brackets.
If your camera doesn’t start, choose a configuration and substitute the [73] shown in photo 1 with the chosen camera configuration number .
For best enjoyment replace size(960, 720) in setup() with the image dimensions listed for your chosen camera configuration.
Measuring
Calibration
- RIGHT-click each end of the ruler to calibrate
- Green circles will appear with each mouse click.
- Keep clicking until you are satisfied that the circles are in the correct place.
Measuring
- LEFT-click one end of the object.
- A red line will follow your mouse as it moves to the other end
- LEFT-click this distant end
- The distance between the two left-clicks will appear on the screen
- Press “1” for inches or “2” for millimetres
- Repeat this process to take another measurement ... there is no need to recalibrate
Summary
The attached software allows you to measure objects remotely using a webcam.
The software uses simple proportion (ratios) to measure distance. As such it is a fun teaching tool.
Calibration is achieved by right-clicking both ends of a 12 inch / 300mm ruler.
Calibration is only required once prior to measuring.
Left-click both ends of an object to measure its length ... the length will appear on-screen.
You can switch between inches and millimetres using the ‘1’ and ‘2’ keys.
Click here to view my other instructables.