Skip to content

Qengineering/QR_scanner_Raspberry_Pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

QR scanner Raspberry Pi

output image

QR and barcode scanner for the Raspberry Pi 3 and 4 (32 and 64 bit OS).

License

Special made for a bare Raspberry Pi see : Q-engineering computer vision.


Benchmark.

Operating system FPS CPU load
Bullseye 64-bit LCCV 13.5 34%
Bullseye 64-bit 12.0 46%
Bullseye 32-bit 10.0 40%
Buster 64-bit 8.7 34%
Buster 32-bit 8.0 32%

All versions work with GStreamer due to its very low latency.
There is also a Bullseye 64-bit version that works with our LCCV.
It outperforms GStreamer in terms of FPS and CPU load.


Dependencies.

To run the application, you have to:

  • A raspberry Pi 4 with a 32 or 64-bit operating system. It may have a Buster (Debian 10) or Bullseye (Debian 11) operating system.
  • ZBar installed.
  • OpenCV installed. Install OpenCV 4.5
  • A working Raspicam.

Installing ZBar.

You have to install ZBar first. It is a perfect library for scanning QR and barcodes. Much better and faster than the comparable OpenCV module.

$ sudo apt install autopoint build-essential libv4l-dev libtool
$ git clone -b 0.23.92 https://github.com/mchehab/zbar.git
$ cd zbar
$ autoreconf -vfi
$ ./configure

output image

$ make -j4
$ sudo make install
$ sudo ldconfig

Note that ZBar tries to work with /dev/video0, which the Bullseye operating system doesn't support (yet).
Since we're only using the decoding part of ZBar and not the ability to capture images, it won't affect our project.

Scanning QR and/or barcodes

In the code you can configure the codes ZBar is trying to decode. You can enable all possible codes by the single line

scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);

Or, if you want to scan a specific code, uncheck everything and then enable the one you want

scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 0);
scanner.set_config(zbar::ZBAR_QRCODE, zbar::ZBAR_CFG_ENABLE, 1);

More info at ZBar.


Installing the app.

  • Make sure you have OpenCV up and running on your system.
  • Choose the folder with your operating system (Buster or BUllseye, 32 or 64 bit).
  • Download the files.
  • You can either build the app with Code::Blocks ($ sudo apt-get install codeblocks) or use CMake.

Code::Blocks

Load the project file QR.cbp and run the app with F9.
For more info on how to work with the Code::Blocks IDE see our tutorial.

CMake

mkdir build
cd build
cmake ..
make

output image
After the build you find the QRpi app in the buiild folder.
.
├── build
│   ├── CMakeCache.txt
│   ├── CMakeFiles
│   ├── cmake_install.cmake
│   ├── Makefile
│   └── QRpi
├── CMakeLists.txt
├── main.cpp
└── QRpi.cbp


Final remarks.

  • Keep the camera resolution at 1024x768 as we will crop the images to the required ZBar size of 720x720.
  • The standard Raspicam is not the best choice when it comes to scanning small QR codes. With its fixed focus, the camera cannot zoom in very close. If you need to scan tiny QR codes, consider a variable focus camera like ArduCam's 8Mp. output image

output image