This project uses OpenCV (cv2
) to analyze images and detect:
- The amount of liquid in a bottle (as a percentage of the total capacity).
- Whether the bottle has a cap or not.
This solution is particularly useful for quality control in production lines or automation systems where liquid levels and cap presence need to be verified.
- Liquid Level Detection: Detects the height of the liquid in the bottle and calculates the percentage of liquid relative to the total bottle height.
- Cap Detection: Identifies whether a cap is present on the bottle.
- Bounding Boxes: Visualizes the detected liquid level, bottle boundaries, and cap presence on the image.
- Reference Image: A reference image of a fully filled bottle is used to calculate the height of the cap and the total height of the bottle.
- Liquid Level Detection:
- Converts the image to grayscale.
- Applies Gaussian blur to reduce noise.
- Uses the Canny edge detection algorithm to find edges.
- Identifies the contour with the largest area to determine the liquid level.
- Cap Detection:
- Crops the top portion of the image based on the liquid height.
- Processes the cropped region to detect the largest contour.
- If the contour area is smaller than a predefined threshold, it determines the cap is missing.
- Output: Displays the processed image with visual indicators (bounding boxes) and prints the results in the console.
The project requires the following:
- Python 3.8 or newer
- OpenCV
git clone https://github.com/pzimnota/liquid_detection.git
-
Place the images in the Foto directory:
- Full.jpg: A reference image of a fully filled bottle.
- Test.jpg: An image of the bottle to be examined.
-
Run the script:
- python Detection.py
-
Results:
- The processed image will be saved as Foto/Solution.jpg.
- The liquid level percentage and cap detection status will be displayed in the console.
Reference Image: A fully filled bottle | Test Image: A bottle with varying liquid levels |
---|---|
![]() |
![]() |
- The program overlays bounding boxes:
Green: Liquid level.
Blue: Bottle boundaries.
Red: Cap (if present).
Bottle without cap | Bottle with cap detected |
---|---|
![]() |
![]() |
Console Output:
Bottle without cap | Bottle with cap detected |
---|---|
![]() |
![]() |