Skip to content

This Python script utilizes OpenCV and various libraries to measure the dimensions of a pill from an image

Notifications You must be signed in to change notification settings

harrylal/pillsize-estimator-with-Opencv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

Pill Dimension Measurement using OpenCV and Python

This Python script utilizes OpenCV and various libraries to measure the dimensions of a pill from an image.

Table of Contents

Requirements

Before running the code, ensure you have the following libraries installed:

You can install these libraries using pip:

pip install scipy imutils numpy opencv-python

Installation

git clone https://github.com/yourusername/pill-dimension-measurement.git
cd pill-dimension-measurement

Edit the IMAGE_PATH and the PPM variable in the script to specify the path to your input image and your PPM value of the camera:

IMAGE_PATH = 'your_image.jpg'
PPMR = 0.1015625 # chage according to your camera

Usage

python measure_pill_dimensions.py

Explanation

This script performs the following steps:

  1. Reads an input image and resizes it for processing.
  2. Converts the image to grayscale and applies thresholding to create a binary image.
  3. Detects contours in the binary image and identifies the contour of the pill.
  4. Estimates the dimensions of the pill by finding its minimum bounding rectangle.
  5. Calculates the dimensions in millimeters using a predefined pixels-per-millimeter (PPMR) value.
  6. Displays the dimensions on the image.

Feel free to modify the code and PPMR value to suit your specific requirements.

About

This Python script utilizes OpenCV and various libraries to measure the dimensions of a pill from an image

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages