This Python script utilizes OpenCV and various libraries to measure the dimensions of a pill from an image.
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
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
python measure_pill_dimensions.py
This script performs the following steps:
- Reads an input image and resizes it for processing.
- Converts the image to grayscale and applies thresholding to create a binary image.
- Detects contours in the binary image and identifies the contour of the pill.
- Estimates the dimensions of the pill by finding its minimum bounding rectangle.
- Calculates the dimensions in millimeters using a predefined pixels-per-millimeter (PPMR) value.
- Displays the dimensions on the image.
Feel free to modify the code and PPMR value to suit your specific requirements.