Skip to content

pzimnota/liquid_detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Bottle Liquid and Cap Detection using OpenCV

This project uses OpenCV (cv2) to analyze images and detect:

  1. The amount of liquid in a bottle (as a percentage of the total capacity).
  2. 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.


Table of Contents


Features

  • 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.

How It Works

  1. 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.
  2. 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.
  3. 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.
  4. Output: Displays the processed image with visual indicators (bounding boxes) and prints the results in the console.

Requirements

The project requires the following:

  • Python 3.8 or newer
  • OpenCV

Installation

git clone https://github.com/pzimnota/liquid_detection.git


Usage

  1. 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.
  2. Run the script:

    • python Detection.py
  3. 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.

Example Results

Input:

Reference Image: A fully filled bottle Test Image: A bottle with varying liquid levels
Full Test

Output:

  • The program overlays bounding boxes:
    Green: Liquid level.
    Blue: Bottle boundaries.
    Red: Cap (if present).

Example:

Bottle without cap Bottle with cap detected
Solution Solution_with_cap

Console Output:

Bottle without cap Bottle with cap detected
image image

About

A program for detecting the amount of liquid in a bottle and whether the bottle has a cap or not.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages