Skip to content

CamRuler is a Python-based interactive measurement tool that uses your webcam and OpenCV to measure objects in real-time. It features manual and automatic measurement modes, calibration for real-world units (mm, cm, inches), and live image processing adjustments. Users can click to measure or let the app detect objects automatically. It's ideal for

Notifications You must be signed in to change notification settings

Dev-Sachintha/mesurment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

CamRuler - Interactive Camera Measurement Tool

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.

Features

  • 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.csv and 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).
  • 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 press T again 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.

Prerequisites

  • Python 3.x
  • OpenCV (opencv-python)
  • NumPy

Installation

  1. Clone the repository or download the script (camruler_app.py).
  2. Install the required Python libraries:
    pip install opencv-python numpy
  3. Ensure you have a webcam connected to your computer.

How to Run

Navigate to the directory containing camruler_app.py in your terminal or command prompt and run:

python camruler_app.py

About

CamRuler is a Python-based interactive measurement tool that uses your webcam and OpenCV to measure objects in real-time. It features manual and automatic measurement modes, calibration for real-world units (mm, cm, inches), and live image processing adjustments. Users can click to measure or let the app detect objects automatically. It's ideal for

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages