Scans one-dimensional barcodes and QR codes in real-time from your phone's camera or computer's webcam. Can be run directly from your command-line or terminal. This application is built using Python 3.7 and uses the following libraries:
- OpenCV
- Pyzbar
Install OpenCV
$-> pip install opencv-python
Install Pyzbar
$-> pip install pyzbar
After all the required libraries have been installed, the program can be run as
$-> python realtime_barcode_reader.py --video <source>
In place of source, enter the URL of your IP Camera application. Format for this is http://<IP_address>:<PORT>/video
.
For example, I'm using an Android application called DroidCam which shows these two instances.
- First instance : I connected my computer to my phone's personal hotspot
- Second instance : I connected my computer & phone to a WiFi
So in the first instance, my source URL would be http://192.168.43.1:4747/video
. And the complete command would be
$-> python realtime_barcode_reader.py --video http://192.168.43.1:4747/video
And in the second instance, my source URL would be http://192.168.43.39:4747/video
. And the complete command would be
$-> python realtime_barcode_reader.py --video http://192.168.43.39:4747/video
NOTE : In both these instances, note that your computer needs to be connected to the same network as your phone. Also, keep the IP Camera application running in your phone.
If you want to use your computer’s primary or secondary webcam as the video source, use source as 0 or 1 respectively, in the command above. For example, the below command starts your computer’s primary webcam as the video source.
$-> python realtime_barcode_reader.py --video 0
On punching either of these commands as per your choice, the realtime_barcode_reader.py program will start executing displaying a startup message on the command line, and your phone/computer will start streaming video feed. At the same time, a new window will open up on your computer screen displaying the barcode reader’s output stream (as shown below).
Now we are ready to scan different barcodes!
To exit the program, press the ESC key on your computer.
Attached below are some sample shots of the barcode reader.
On every run, this program generates a log file (log.txt) which contains the exact last session timestamp and details of the unique barcodes scanned.
For IP Camera application, you can download either of these apps:
Google Drive download link (ipynb file included) ⤓
Thanks!