This repository contains a solution for recognizing barcodes on the items in an image containing multiple grocery items with a single-colored background. The solution uses OpenCV and Zbar libraries for barcode recognition and object detection.
- OpenCV
- pyzbar
- Numpy
- dbr
- ultralytics
- Import the required libraries
- Define the function to detect objects in the image using OpenCV's feature-based object detection method
- Define the function to recognize barcodes in the detected objects using Zbar library
- Loop through all the detected objects and use the barcode recognition function to recognize barcodes in each object
- Draw bounding boxes of different colors around the objects based on the results of the barcode recognition:
- Blue for successfully recognized barcodes
- Yellow for partially recognized barcodes
- Red for objects without barcodes
- Black for each item in the image
- Print the value of every barcode and the number of times each barcode appears in the image
- Clone or download the repository
- Install the required dependencies
- Run the solution by executing the main file in the terminal or command prompt
The rest of the results can be found in the Output Folder.
The following steps are performed in the solution:
- The image is loaded.
- Yolo Object detection is applied on the image and all the objects present in the image are identified.
- The identified objects are cropped and passed to the Fine object getter method which uses clustering of corners present in the image to identify individual items.
- The cropped images of individual items are processed to detect barcode present in them. For barcode detection Pyzbar and Dynamsoft barcode reader libraries are used.
- The images are coloured accordingly to indicate successful barcode detection or not.
- Finally, Barcode detection is applied directly on the whole image to see if there is any left out barcode.
The main code for barcode identification is present in the file main.py. To run the code from python, follow the instructions below:
- Make a new python script to get the results
import main
file = main.main_func("Image_name/path")
img_output = file[0] barcode_coordinates = file[1]
To run the code from the Command Line Interface, follow the instructions below:
- Open your terminal or command prompt
- Change the directory to the project directory using the
cd
command - Run the following command:
python main.py [image_file/loc] [optional_arguments]
The basic script.ipynb file is the raw Jupyter Notebook that was used for training and experimentation and also for finding the hyperparameter's optimal values, etc. You can use this notebook for understanding the implementation of the code and other approches.