Skip to content

A system for barcode detection and decoding using YOLO, SAM2, and pyzbar designed to extract barcode data from images.

Notifications You must be signed in to change notification settings

AntonAshraf/Barcode-segmentation

Repository files navigation

Barcode Detector

This repository contains a barcode detection and recognition system using deep learning models. The system is designed to detect barcodes in images and extract the encoded information. It leverages the power of YOLO for object detection and SAM2 for image segmentation.

Here is a detailed explanation of the project in this link

Features

  • Barcode Detection: Detects barcodes in images using YOLO.
  • Barcode Segmentation: Segments the detected barcodes using SAM2.
  • Barcode Decoding: Decodes the segmented barcodes to extract the encoded information using pyzbar.
  • Web Interface: Provides a user-friendly web interface for uploading images and viewing results.

Screenshots

Screenshot 2025-01-06 230957 Screenshot 2025-01-06 231150

Pipeline

pipeline

  1. Image Upload: Users upload an image containing barcodes via the web interface.
  2. Barcode Detection: The YOLO model detects the barcodes in the uploaded image.
  3. Barcode Segmentation: The SAM2 model segments the detected barcodes.
  4. Preprocessing: Apply grayscale and binarization to the cut-out barcode.
  5. Barcode Decoding: The segmented barcodes are decoded to extract the encoded information.
  6. Result Display: The original image, processed images, and decoded barcode information are displayed on the web interface.

Installation

Follow these steps to set up the project:

  1. Clone the repository:

    git clone https://github.com/yourusername/barcode-detector.git
    cd barcode-detector
  2. Create a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install dependencies:

    pip install -r requirements.txt
  4. Download the pre-trained models:

    ./checkpoints/download_ckpts.sh

Usage

  1. Run the Flask app:

    python main.py
  2. Open your browser and navigate to http://127.0.0.1:5000.

  3. Upload an image containing barcodes and view the results.

Directory Structure

barcode-detector/
├── checkpoints/          # Directory for storing model checkpoints
├── sam2/                 # SAM2 model implementation
├── static/               # Static files for the web interface
├── templates/            # HTML templates for the web interface
├── test images/          # Sample images for testing the system
├── utils/                # Utility scripts
├── YOLO/                 # YOLO model implementation & weights
├── main.py               # Main script to run the Flask app
├── README.md             # This README file
└── requirements.txt      # Python dependencies

Dataset

The dataset used to fine-tune the YOLO model was obtained from Roboflow.

It contains images of barcodes with corresponding annotations in YOLO format. The dataset was split into training and validation sets for training the model with heavy data augmentation.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.