Code Monkey home page Code Monkey logo

qr_scanner_raspberry_pi's Introduction

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

qr_scanner_raspberry_pi's People

Contributors

qengineering avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

greigs

qr_scanner_raspberry_pi's Issues

Error when launching QRpi

I got this error when I launch QRpi
Using pipeline:
libcamerasrc ! video/x-raw, width=(int)1024, height=(int)768, framerate=(fraction)15/1 ! videoconvert ! videoscale ! video/x-raw, width=(int)1024, height=(int)768 ! appsink

(QRpi:774): GLib-GObject-WARNING **: 10:25:52.137: invalid cast from 'GstLibcameraSrc' to 'GstBin'

(QRpi:774): GStreamer-CRITICAL **: 10:25:52.137: gst_bin_iterate_elements: assertion 'GST_IS_BIN (bin)' failed

(QRpi:774): GStreamer-CRITICAL **: 10:25:52.137: gst_iterator_next: assertion 'it != NULL' failed

(QRpi:774): GStreamer-CRITICAL **: 10:25:52.137: gst_iterator_free: assertion 'it != NULL' failed

[ WARN:[email protected]] global cap_gstreamer.cpp:1535 open OpenCV | GStreamer warning: cannot find appsink in manual pipeline
[ WARN:[email protected]] global cap_gstreamer.cpp:1173 isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
[ WARN:[email protected]] global cap.cpp:204 open VIDEOIO(GSTREAMER): backend is generally available but can't be used to capture by name
Failed to open camera.
I'm worjing on a Pi4 with no desktop environment.
Could you help me, please?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.