/object-size

Measure size of an object (height and width) using a reference object

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

Measure size of objects in an image using OpenCV

The project provides a script to read an image and based on the dimensions of a reference object find the dimensions of other objects in a scene. The reference object must be the leftmost object in the scene. In sample images given, a box of dimension 2cm x 2cm is taken as a reference object.

For any other reference object provide actual width of the object. (change line 59 in file 'init.py')

Constraints

  1. Shadow effect: use dark braground
  2. Object boundry: use contrasting background

Getting Started

Prerequisites

Python 3 Pip OpenCV Numpy

Installing all the requirements

  • cd object-size
  • python3 -m venv .env
  • source .env/bin/activate
  • pip install -r requirements.txt

Executing

  • cd object-size
  • cp images/example_01.jpg images/foo01.jpg
  • python init.py
  • you should see new files appearing inside the image folder:
    • foo01_blurred.jpg foo01_edged.jpg foo01rslt.jpg

Algorithm

  1. Image pre-processing
  • Read an image and convert it it no grayscale
  • Blur the image using Gaussian Kernel to remove un-necessary edges
  • Edge detection using Canny edge detector
  • Perform morphological closing operation to remove noisy contours
  1. Object Segmentation
  • Find contours
  • Remove small contours by calculating its area (threshold used here is 100)
  • Sort contours from left to right to find the reference objects
  1. Reference object
  • Calculate how many pixels are there per metric (centi meter is used here)
  1. Compute results
  • Draw bounding boxes around each object and calculate its height and width

Results

Result

Authors

  • Shashank Sharma

Acknowledgments