Hi guys,

In this blogpost I’ll show you how to make the raspberry pi scan bar codes. So without any delay lets begin .



Parts you will need

Raspberry pi (running raspbian OS)

camera module

Internet connection to the pi

Hoping you have all the parts. Let us first start by connecting the camera module

Connecting The Camera module

It is pretty straight forward to connecting the camera module to the pi. Here are the steps.

Lift up the camera connectors lock

Insert the camera module ribbon cable inside

Push down the lock

Enabling the camera on the pi

Boot up the pi

Open up terminal software

In terminal type the following command sudo raspi-config

A settings dialog box will pop up with a set of options to modify various settings for the pi

Go to the Camera setting option and enable the camera

Reboot by typing sudo reboot to make the camera work

Testing the Camera module

If you are using the camera for the first time and want to test it check out the following links

https://www.raspberrypi.org/documentation/usage/camera/raspicam/raspistill.md for testing in the terminal

https://www.raspberrypi.org/documentation/usage/camera/python/README.md for testing in python

SimpleCV

SimpleCV is an image processing library. It is an open source software that runs on all the major platforms and it is quite a powerful piece of image processing software. for more info regarding SimpleCV visit http://simplecv.org/ . I shall cover more of the features of SimpleCV in the upcoming projects. But first we need to install SimpleCV on the Pi

Installing SimpleCV on Raspberry pi

Open up the terminal software

Type the following command

sudo apt-get install ipython python-opencv python-scipy python-numpy python-setuptools python-pip

these were the dependencies or prerequisites for the SimpleCV library

Now to download SimpleCV type

sudo pip install https://github.com/sightmachine/SimpleCV/zipball/master

It will take some time for the software to download

After it is done downloading open up python and type import SimpleCV

If you get no errors then you have successfully installed SimpleCV

Getting the raspberry pi camera recognised by SimpleCV software

The raspberry pi camera is not recognised by the SimpleCv module. This was the most difficult problem that i encountered. Luckily I found help online in the form of this post by Xfirm that will install a uv4l driver for the camera. Many thanks!!. just go through that link and get the camera working in SimpleCV.

Zbar

Zbar is the module that will process the barcodes. There is another library you can use called the ZXing library. It can also process barcodes but currently I’m using the Zbar one.

Installing the Zbar library

Open up the lx terminal software in raspbian OS

First type sudo apt-get update (if not updated recently)

After type the following command sudo apt-get install python-zbar

Open up python and type import zbar, you should get no errors

The final part

You will need this following program

from SimpleCV import Color,Camera,Display cam = Camera() #starts the camera display = Display() while(display.isNotDone()): img = cam.getImage() #gets image from the camera barcode = img.findBarcode() #finds barcode data from image if(barcode is not None): #if there is some data processed barcode = barcode[0] result = str(barcode.data) print result #prints result of barcode in python shell barcode = [] #reset barcode data to empty set img.save(display) #shows the image on the screen

Run the program and wait for a few seconds for the program to run i.e. led on the camera to light up

Now direct the camera towards the Barcode/QR code you want to scan wait for few seconds and youll get the barcode data printed in the python shell

The uv4l driver has a resolution of 640X480. therefore the barcodes need to be of a higher resolution to get them scanned properly. If any of you guys have figured out how to incease resolution of the uv4l driver please let me know in the comments down below.

Also like and share this post so that it reaches out to more people. See you guys next time.