CS373 Barcode detection assignment
Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit
CS373 Barcode detection assignment
1 Overview
Deadline: 11:59pm 4th of June 2023
The image processing assignment will combine what we have done in the coderunner
programming quizzes for image processing. You will generate a Python code pipeline to
detect barcodes on common household items. This is an individual assignment, so every
student has to submit this assignment!
You will receive 10 marks for solving the barcode detection problem (“CS373_barcode
_detection.py”), and there will be an additional component for 5 marks, where you will
extend upon the barcode detection (“CS373_extension.py”) and write a short reflective
report about your extension.
Please clone this GitHub repository to receive a Python code skeleton for program-
ming by using the following line in a command prompt that has git installed (or use any
other way that you prefer for getting access to this repository):
Command Line $ git clone https://github.com/mrog173/CS373_2023_Assignment_Barcode_Detection.git
|
2 Submission
Please upload your submission as a zipped file of the assignment folder to the UoA As- signment Dropbox by following this link: Assignment Dropbox
• Don’t put any virtual environment (venv) folders into this zip file, it just adds to the size, and we will have our own testing environment.
• Your code for executing the main barcode detection algorithm has to be located in the provided“CS373_barcode_detection.py”file!
• You can either put all of your code into these two files, or use a modular structure
with additional files (that, of course, have to be submitted in the zip file). However,
we will only execute the “CS373_barcode_detection.py” file to see if your code
works for the main component!
• The main component of the assignment (“CS373_barcode_detection.py”) must not
use any non-built-in Python packages (e.g., PIL or OpenCV) except for Matplotlib.
Ensure your IDE hasn’t added any of these packages to your imports.
• Important: Use a lab computer to test if your code works on Windows on a dif- ferent machine (There are over 300 students, we cannot debug code if it doesn’t work!)
3 Assignment steps
1. Convert to greyscale and normalise
Read the input image, convert the RGB data to greyscale and stretch the values be- tween 0 and 255. As per week 9 lecture slides and the Coderunner Programming quiz in Week 10.
For the next steps there are two methods you could use: The image gradient or the
standard deviation method.
2a. Option 1: Image gradient method
Apply a 3x3 Sobel filter in the x- and y-directions independently and take the absolute
value of the difference between the results. See lecture slides on edges and Coderunner
Programming quiz in Week 11.
2b. Option 2: Standard deviation method
Apply a 5x5 standard deviation filter. See Coderunner Programming quiz in Week 11.
3. Gaussian filter
Apply a series of 3x3 Gaussian filters to the output image. (Try repeating the Gaussian
filter four times or a larger sigma and filter size). See lecture slides on filtering and the
Coderunner Programming quiz in Week 11.
Option 1: Image gradient
Option 2: Standard deviation
4. Threshold the image
Perform a thresholding operation to get the high-contrast regions as a binary image.
Hint: A good threshold value for the standard deviation method may be around 25,
while for the gradient method, a threshold around 100 should work. (It is up to you
to explore different values or to determine the threshold automatically.)
Option 1: Image gradient
Option 2: Standard deviation
5. Erosion and dilation
Perform several erosion steps followed by several dilation steps.
Hint: For the standard deviation method, two or three consecutive erosion steps
followed by two consecutive dilation steps with a 5x5 filter should be enough. For
the image gradient method, the barcode lines are much thinner, so two consecutive
dilations followed by two erosions may work better (It is up to you to determine how
many works well).
Option 1: Image gradient
Option 2: Standard deviation
6. Connected component analysis
Perform a connected component analysis to find the largest connected component. See the Segmentation lecture slides and the Coderunner Programming quiz in Week 12.
For some images, the largest connected component may not be the barcode, so you
may need to analyse the aspect ratio of the generated bounding box or look for more
densely filled regions.
• The aspect ratio can be found based on the minimum and maximum x and y values
of the component. One side of the bounding box should be no more than 1.8 times
the other for a typical barcode.
• Pixel density can be calculated by the number of foreground pixels as a percentage of the total number of pixels in the bounding box around the connected component.
Option 1: Image gradient
Option 2: Standard deviation
7. Draw a bounding box
Extract the final bounding box around this region by looping over the image and look-
ing for the minimum and maximum x and y coordinates of the pixels in the previously
determined connected component.
Option 1: Image gradient
Option 2: Standard deviation
4 Extension
For this extension (worth 5 marks), you are expected to extend this barcode detection
system. This can be done by improving parts of the pipeline or by adding new parts to
the pipeline. Examples for extensions based on previous years submissions:
• Find challenging images (e.g., multiple barcodes or other barcode like structures),
show where the algorithm fails (with images) and discuss why, attempt to over-
come failures.
• Attempt to read the barcode (e.g., using the Pyzbar library).
• Create a real-time system to scan barcodes using OpenCV.
Submissions that make the most impressive contributions will get full marks. Please include a short PDF report about your extension. Try to be creative.
5 Examples
Option 1: Image gradient
Option 2: Standard deviation
Figure 1: Examples of the two approaches detecting barcodes on the provided images.
2023-05-30