This past Tuesday was the final session in the Pynq-Z2 workshop series. This session completed the embedded vision project by adding an interface for an HDMI camera and using it to read barcodes.
The HDMI interface was was brought in as a hierarchical block called "frontend" which was exported from the base overlay.
Here is the upper level block diagram with the frontend block highlighted:
A closer look at the frontend block showing the camera interface IP dvi2rgb and the video timing and stream converter to support it:
The frontend block essentially replaced the TPG from the previous session.
Once the new bitstream was created, the BIT, TCL, and HWH files were transferred to the PYNQ-Z2 overlay directory. In order to enable the reading of Barcodes a Python library 'zbar' needs to be installed also.
From a Jupyter terminal
- apt-get install libzbar0
- pip3 install pyzbar
I found some sample barcodes on the website https://internationalbarcodes.com/sample-images/ . For purposes of testing I displayed the codes on a second monitor and captured that image with the camera.
Some of the barcodes that I tried didn't work so there may be a problem with the images on the website but here's one that did work:
The code added to the Jupyter notebook to capture the image and display the result:
You can see that my action camera has a fair amount of fish eye distortion that is very apparent with a closeup image.
The captured image is then written to a file img.jpg
The image is shown below - looks like the color conversion needs to be fixed.
The image is processed to convert it to grayscale and apply thresholding.
And finally the detection is run on the image and the barcode is printed if it is found and the image is written with the bounding box and barcode overlaid.
So, another fun and useful workshop. Homework is to try to extend the functionality of the overlay. And the final project is to come up with our own embedded vision project.
I've started to try a few things but as always - the devil is in the details . Looks easy when Adam does it. Hopefully I'll get the homework done this week and then on to figuring out a project to do.......
Note: to those of you paying attention - I just realized that I mixed up some of the images that I saved - I had a few different barcodes that worked. And I may have adjusted the camera position a bit between barcodes.