CamRuler is a Python application that uses OpenCV to provide live camera-based measurement capabilities. It allows users to measure objects in real-time, both manually by clicking points and automatically by detecting object contours. The tool supports calibration for converting pixel measurements to real-world units (mm, cm, inches) and offers live adjustments for various image processing parameters.
Inspired by the functionality demonstrated in ClaytonDarwin's YouTube channel video on a similar tool.
- Live Camera Feed: Displays video from your webcam.
- Manual Measurement Mode:
- Click two points on the live feed to draw a line and a bounding box.
- Displays X (horizontal), Y (vertical), and L (diagonal) lengths.
- Shows the area of the drawn bounding box.
- Measurements are displayed in both pixels and selected real-world units.
- Auto Measurement Mode:
- Automatically detects objects (e.g., coins) using contour detection.
- Draws bounding boxes around detected objects.
- Displays Width, Height, Average Dimension, and Area for each detected object in the selected real-world units.
- Calibration Mode:
- Step-by-step process to calibrate pixel-to-unit conversion.
- Place a ruler in view and click on known distances from the frame's center.
- Calibration data is saved to
camruler_cal.csvand loaded on startup. - Supports non-linear calibration (different scales at different distances from the lens center).
- Live Parameter Adjustments (for Auto Mode & Display):
- Threshold: Adjust the binary threshold for object detection (Key:
T+ Mouse L/R). - Gaussian Blur: Modify the Gaussian blur kernel size to smooth the image before thresholding (Key:
G+ Mouse L/R). - Min Object Area Percent: Filter out small noise by setting a minimum object size relative to the frame (Key:
P+ Mouse L/R). - Normalize (Brightness/Contrast): Adjust image brightness and contrast (Key:
N+ Mouse L/R).
- Threshold: Adjust the binary threshold for object detection (Key:
- Keyboard Controls:
Q: Quit the application.R: Rotate the camera feed by 180 degrees (useful if your camera is mounted upside down).A: Toggle between Manual Measurement Mode and Auto Measurement Mode.C: Enter/Exit Calibration Mode.T: Enter/Exit Threshold adjustment mode (use mouse left/right to adjust, click or pressTagain to set).G: Enter/Exit Gaussian Blur adjustment mode.P: Enter/Exit Minimum Object Area Percentage adjustment mode.N: Enter/Exit Normalize (brightness/contrast) adjustment mode.U: Cycle through measurement units (mm, cm, inches).
- On-Screen Display (OSD):
- Camera information (index, resolution, FPS).
- Coordinates of the last clicked point and current mouse position (in pixels).
- Current operating mode and values of adjustable parameters.
- Help text listing available keyboard commands.
- Python 3.x
- OpenCV (
opencv-python) - NumPy
- Clone the repository or download the script (
camruler_app.py). - Install the required Python libraries:
pip install opencv-python numpy
- Ensure you have a webcam connected to your computer.
Navigate to the directory containing camruler_app.py in your terminal or command prompt and run:
python camruler_app.py