This script processes an image to detect and estimate the number of kakis (persimmons) by identifying the common orange areas using a Gaussian fit method with least squares estimation.
The script performs the following steps:
- Reads an image of kakis.
- Converts the image to the HSV color space.
- Applies a median blur to reduce noise.
- Masks the image to isolate the orange color of the kakis.
- Dilates the mask to ensure kakis are properly highlighted.
- Extracts the kakis from the original image using the mask.
- Finds contours of the masked kakis.
- Estimates the number of kakis based on the most common area obtained from a Gaussian fit of the area histogram.
- Draws contours around the detected kakis and saves the output images.
To run this script, you'll need Python installed on your system along with the following libraries:
- numpy
- opencv-python
- scipy
You can install these libraries using pip
with the following command:
pip install numpy opencv-python scipy
To use the script, follow these steps:
- Place your image of kakis in the
./img/
directory and name itkaki.JPG
. - Run the script with the command
python kaki_detection.py
. - The script will output two images:
masked_kaki.jpg
: Shows the kakis with the mask applied.contoured_kaki.jpg
: Displays the original kakis with contours drawn around them.
- The estimated count of kakis will be printed to the console.
kaki_detection.py
: The main script file../img/kaki.JPG
: Input image file (you need to provide this)../img/masked_kaki.jpg
: Output image with kakis masked../img/contoured_kaki.jpg
: Output image with contours drawn around kakis.
This document was generated by an AI model from OpenAI.