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
- 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.
![]() |
![]() |
---|
- Image Upload: Users upload an image containing barcodes via the web interface.
- Barcode Detection: The YOLO model detects the barcodes in the uploaded image.
- Barcode Segmentation: The SAM2 model segments the detected barcodes.
- Preprocessing: Apply grayscale and binarization to the cut-out barcode.
- Barcode Decoding: The segmented barcodes are decoded to extract the encoded information.
- Result Display: The original image, processed images, and decoded barcode information are displayed on the web interface.
Follow these steps to set up the project:
-
Clone the repository:
git clone https://github.com/yourusername/barcode-detector.git cd barcode-detector
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Download the pre-trained models:
./checkpoints/download_ckpts.sh
-
Run the Flask app:
python main.py
-
Open your browser and navigate to
http://127.0.0.1:5000
. -
Upload an image containing barcodes and view the results.
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
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.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.