Skip to content

rijinmk/code-qr-code-reader-rpi3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

QR code reader on a Raspberry Pi 3

This guide will show you how to create a QR code reader by using the zbarlight python library and fswebcam to take the picture. We will not be using open cv or any other image processing libraries.

What you'll need

  • Raspberry Pi 2 / 3
  • MicroSD Card with Raspbian on it (Tutorial)
  • A USB webcam
  • Micro USB cable
  • Keyboard, Mouse, Monitor
  • HDMI cable for the monitor

If you are using the Raspberry Pi headless (Without a monitor, keyboard or mouse), You will need to connect to the internet using the ethernet port (for Raspberry Pi 2) or through the Wifi (on a Raspberry Pi 3 [Tutorial] ) and then you will have to use SSH to connect to your Raspberry Pi.

Installation process

Here onwards everything will be on the terminals. Press CTRL + ALT + T to open up the terminals.

STEP 1 - Initial installations

The apt-get must always be kept updated.

sudo apt-get update -y && sudo apt-get upgrade -y

This will take some time depending on your internet speed and also the amount of package's that are installed onto your Raspberry Pi's OS.

STEP 2 - Installing and running fswebcam

You will need to install this to access the webcam from the commandline. To install this you will need to use apt-get.

sudo apt-get install fswebcam

This will install fswebcam. Now insert your USB webcam, to check if it's connected, enter in the command

ls /dev/ | grep video

If video0 is the output that means you are good to go, The webcam is connected. Now enter:

sudo fswebcam image.jpg

This will take a picture named image.jpg. To check if you have taken the image, Enter:

ls | grep image

If you see a file named image.jpg, that means your web cam is working. But if your above output for ls /dev/ | grep video was something else, for example video2. We have to pass an additional argument to sudo fswebcam image.jpg. Which is:

sudo fswebcam -d /dev/video2 image.jpg

There is one more argument that we pass through to this command which is -q which means quite, This is to avoid the extra wordings that come when the photo is being taken.

STEP 3 - Installing zbarlight

This is the brain of our QR code reader. This library helps us to decode an image into their basic codes.

First we have to install the following:

sudo apt-get install libzbar0 libzbar-dev

Then we have to install the zbarlight

sudo pip install zbarlight

After this you can run the reader.py python program that I have written to test if it works. But before you proceed, we need to create a folder named qr_codes right outside the reader.py file. This folder will store all the QR codes.

This reader.py program does the following:

  • Runs the command fswebcam -q image_name.ext
  • Checks if it has QR Codes
  • Stores the QR code onto the qr_codes/ folder
  • If there is no QR code present after we run it through zbarlight, the image is deleted.
  • Else the image stays there, and a qr_code_messages.txt file is created with the QR code message onto it.
  • This file seperates the messages with certain delimiters

If you want to run the code enter

sudo python reader.py 0

This is all you need to do / know for the QR code reader to work, If you want the detailed explationation of the code, I will be writing it soon.

About

QR code reader on a Raspberry Pi 2 / 3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages