×
Namespaces

Variants
Actions
(Difference between revisions)

Qr Decoder in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot fixing redirect link.(Moving links from forum.nokia.com TO developer.nokia.com))
favoritas37 (Talk | contribs)
(Favoritas37 - Update project to pure Qt. Uses Camera API from Qt Mobility instead of the Symbian C++ native Camera API.)
Line 1: Line 1:
[[Category:Multimedia]][[Category:Open C/C++]][[Category:Qt]][[Category:Symbian C++]]
+
[[Category:Multimedia]][[Category:Qt]][[Category:Qt Mobility]][[Category:Symbian]]
 
{{Abstract| This article demonstrates how to create a Barcode Decoder program, using the C++ part of [http://code.google.com/p/zxing/  ZXing project] to process the image and decode it.}}
 
{{Abstract| This article demonstrates how to create a Barcode Decoder program, using the C++ part of [http://code.google.com/p/zxing/  ZXing project] to process the image and decode it.}}
 +
 +
QQrDecoder project is developed entirely in Qt SDK + using the CPP part of the ZXing library.It supports the latest version of Qt in Symbian (4.7.x) and the camera is controlled using the Camera APIs from Qt Mobility project.Thus we reasure the compatibility with future releases of Qt and the compatibility with newer device with Symbian^3, Belle and Anna (and S60 5th).
 +
 +
The project's folder contains the code as well as the an installation file in case you want try it out without compiling the project.
 +
 +
NOTE: this project, since it uses Camera APIs from Qt Mobility breaks the backward compatibility with non touch-screen devices. So this project can't be used at device with OS: S60 3rd.
  
 
It currently supports decoding:
 
It currently supports decoding:
Line 12: Line 18:
 
== The three parts of the project ==
 
== The three parts of the project ==
  
* ''CameraImageWrapper'' : <br>The porting layer between the ZXing and Qt. Inherits from ''LuminanceSource'' (zxing/LuminanceSource.h) which is an abstract class representing a grey-scale image. This class holds the image information in a QImage and 3 methods were needed to be implemented: '''getWidth()''', '''getHeight()''' and '''getPixel(int,int)'''. The first 2 are trivial, the 3rd needed to return an unsigned char representing the grey-scale value of the pixel given as argument so since QImage will contain RGB image in this project, the return value was given by qGray(QImage::pixel(x,y)).
+
* ''CameraImageWrapper'' : <br>The porting layer between the ZXing and Qt. Inherits from ''LuminanceSource'' (zxing/LuminanceSource.h) which is an abstract class representing a grey-scale image. This class holds the image information in a QImage and 3 methods were needed to be implemented: '''getWidth()''', '''getHeight()''' and '''getPixel(int,int)'''. The first 2 are trivial, the 3rd needed to return an unsigned char representing the grey-scale value of the pixel given as argument so since QImage will contain RGB image in this project, the return value was given by qGray(QImage::pixel(x,y)). New functions added to comply with the latest version of ZXing libary '''getRow(int, unsigned char*)''' and '''getMatrix()'''.
  
  
* ''QCameraControllerWidget'':<br> This widget is responsible for the camera. All the camera operations are taken from [http://www.developer.nokia.com/info/sw.nokia.com/id/9a3e1226-79db-4c8e-bd70-7d9d22aaa6eb/S60_Platform_Camera_Example.html S60 Platform: Camera Example], so sense that this part is Symbian specific. On construction, the camera is reserved and powered on which are asynchronous operations. When ready, a backbuffer is created to hold the live camera feedback images which are reported through '''MceoViewFinderFrameReady( CFbsBitmap&)'''. When each frame is reported, it is saved to the backbuffer and then update is called to print it. '''CaptureImage()''' method can be called to initiate capturing image operation. When image is captured successfully, '''imageCaptured(QImage)''' signal is emitted.
+
* ''QCameraControllerWidget'':<br> This widget is responsible for the camera. All the camera operations are taken from [http://doc.qt.nokia.com/4.7-snapshot/demos-mobile-qcamera.html QCamera Example]. This is the widget where the image from the camera is shown. When the user presses the button to take a picture, that picture is decoded. If and barcode is found, it is reported with a QMessageBox else nothing happens.
 
+
  
 
* ''QQrDecoder'' : the main window class which contains a ''QCameraControllerWidget'' instance. '''QCameraControllerWidget::imageCaptured(QImage)''' signal is connected to '''QQrDecoder::decodeImage(QImage)''' slot, so each captured image is processed to find the "hidden" message inside the Qr Code.
 
* ''QQrDecoder'' : the main window class which contains a ''QCameraControllerWidget'' instance. '''QCameraControllerWidget::imageCaptured(QImage)''' signal is connected to '''QQrDecoder::decodeImage(QImage)''' slot, so each captured image is processed to find the "hidden" message inside the Qr Code.
  
 +
== Prerequisites to compile ==
 +
 +
* Have Qt SDK installed. This will give you all the tools needed such as the Qt SDK, Qt Mobility APIs and the Qt Creator IDE.
 +
    http://qt.nokia.com/downloads/
 +
   
 +
== Prerequisites to install and run to device ==
 +
 +
* Have Qt 4.7.3 (and newer) binaries installed to the device.
 +
* Have Qt Mobility 1.1.0 (and newer) binaries installed to the device.
 +
 +
NOTE: those binaries, if Qt SDK is installed, can be found under the path \QtSDK\Symbian\sis\Symbian^X\
 +
   
 +
== Importing the project ==
 +
 +
For this step, Qt Creator IDE will be used (contained in Qt SDK). The project can be imported/opened with 2 ways.
 +
 +
NOTE: The project folder must be placed under the same drive letter as the installed Qt SDK. For example "C:\QtSDK" and "C:\QtProject\QQrDecoder"
 +
 +
# Go the the project's folder and double-click the QQrDecoder.pro file. This will result the Qt Creator to open. (This requires that Qt Creator is selected as the predefined program to open such files which is automatically set when installing Qt SDK.)
 +
# Alternatively, open Qt Creator manually, and go under: "File" -> "Open File or Project...", go to the project's folder and select once again the QQrDecoder.pro.
 +
 +
Whichever step from the above you have followed, now you are led to screen named "Project Setup". Here you select the Target Platform.
 +
You can select "Symbian Device" to target directly for a physical device, or "Qt Simulator" to first test it to the build-in simulator.
 +
 +
== Building the project ==
  
== Preconditions to use it for Symbian ==
+
At this point you have imported the project and you are ready to compile it. At the left toolbar in Qt Creator, above the green arrow you can see the
 +
current target platform selected. Press to select which you want.
  
Inside the project folder, there is a folder named '''''camerawrapper'''''. Inside this, the '''''epoc32''''' folder '''must''' be copied to the '''''epoc32''''' folder of the Symbian SDK to be used! <br>(in my case: C:\S60\devices\S60_5th_Edition_SDK_v1.0)
+
Now by pressing Ctrl+B or the "hammer icon" on the left at the bottom. Normally this should be completed without errors (might be lots of wrning though
 +
which we selectively reject them from our mind :P )
  
''NOTE:'' Tested on Nokia 5230 (S60 5th Edition SDK v1.0) and Nokia E52 (S60 3rd FP2 SDK v1.1). On E52 the detection rate was not that great considering the fact that its camera is not as good as 5230's.
+
This step compiles the project BUT doesn't produces the .sis file (the installation file). To create the installation file you have to press the "Run button".
 +
It that "Green arrow" on your left, or by simply pressing Ctrl+R. Regardless if you have a device or not, the .sis file will be created.
  
== How to use it on other platforms than Symbian ==
+
Now you can install it to your device.
  
Since only '''QCameraControllerWidget''' is Symbian specific you can just change the source of the image to be decoded. For example, the image can be read from the local file system, or re-implement ''QCameraControllerWidget'' with target platform specific code on how to use the camera and capture images.
 
  
 
== Download ==
 
== Download ==
Line 37: Line 69:
  
 
== Licence ==
 
== Licence ==
* For the [http://www.developer.nokia.com/info/sw.nokia.com/id/9a3e1226-79db-4c8e-bd70-7d9d22aaa6eb/S60_Platform_Camera_Example.html S60 Platform: Camera Example] see '''Nokia_Licence.txt'''
+
* For the [http://doc.qt.nokia.com/4.7-snapshot/demos-mobile-qcamera.html QCamera Example] see '''Nokia_Licence.txt'''
 
* For the [http://code.google.com/p/zxing/ ZXing] code see '''ZXing_Licence.txt'''
 
* For the [http://code.google.com/p/zxing/ ZXing] code see '''ZXing_Licence.txt'''
  
Line 44: Line 76:
  
 
* [http://code.google.com/p/zxing/ ZXing- Multi-format 1D/2D barcode image processing library]
 
* [http://code.google.com/p/zxing/ ZXing- Multi-format 1D/2D barcode image processing library]
* [[SDK API Plug-in|Symbian S60 SDK API Plug-in]]
+
* [http://doc.qt.nokia.com/4.7-snapshot/demos-mobile-qcamera.html QCamera Example]
* [[Camera Application Engine API]]
+
* [http://www.developer.nokia.com/info/sw.nokia.com/id/9a3e1226-79db-4c8e-bd70-7d9d22aaa6eb/S60_Platform_Camera_Example.html S60 Platform: Camera Example]
+

Revision as of 17:07, 19 September 2011

This article demonstrates how to create a Barcode Decoder program, using the C++ part of ZXing project to process the image and decode it.

QQrDecoder project is developed entirely in Qt SDK + using the CPP part of the ZXing library.It supports the latest version of Qt in Symbian (4.7.x) and the camera is controlled using the Camera APIs from Qt Mobility project.Thus we reasure the compatibility with future releases of Qt and the compatibility with newer device with Symbian^3, Belle and Anna (and S60 5th).

The project's folder contains the code as well as the an installation file in case you want try it out without compiling the project.

NOTE: this project, since it uses Camera APIs from Qt Mobility breaks the backward compatibility with non touch-screen devices. So this project can't be used at device with OS: S60 3rd.

It currently supports decoding:

  • Qr codes
  • EAN
  • Code 128
  • UPC-A
Qr Code containing the text "Qr Decoder in Qt"

Contents

The three parts of the project

  • CameraImageWrapper :
    The porting layer between the ZXing and Qt. Inherits from LuminanceSource (zxing/LuminanceSource.h) which is an abstract class representing a grey-scale image. This class holds the image information in a QImage and 3 methods were needed to be implemented: getWidth(), getHeight() and getPixel(int,int). The first 2 are trivial, the 3rd needed to return an unsigned char representing the grey-scale value of the pixel given as argument so since QImage will contain RGB image in this project, the return value was given by qGray(QImage::pixel(x,y)). New functions added to comply with the latest version of ZXing libary getRow(int, unsigned char*) and getMatrix().


  • QCameraControllerWidget:
    This widget is responsible for the camera. All the camera operations are taken from QCamera Example. This is the widget where the image from the camera is shown. When the user presses the button to take a picture, that picture is decoded. If and barcode is found, it is reported with a QMessageBox else nothing happens.
  • QQrDecoder : the main window class which contains a QCameraControllerWidget instance. QCameraControllerWidget::imageCaptured(QImage) signal is connected to QQrDecoder::decodeImage(QImage) slot, so each captured image is processed to find the "hidden" message inside the Qr Code.

Prerequisites to compile

  • Have Qt SDK installed. This will give you all the tools needed such as the Qt SDK, Qt Mobility APIs and the Qt Creator IDE.
   http://qt.nokia.com/downloads/
   

Prerequisites to install and run to device

  • Have Qt 4.7.3 (and newer) binaries installed to the device.
  • Have Qt Mobility 1.1.0 (and newer) binaries installed to the device.

NOTE: those binaries, if Qt SDK is installed, can be found under the path \QtSDK\Symbian\sis\Symbian^X\

Importing the project

For this step, Qt Creator IDE will be used (contained in Qt SDK). The project can be imported/opened with 2 ways.

NOTE: The project folder must be placed under the same drive letter as the installed Qt SDK. For example "C:\QtSDK" and "C:\QtProject\QQrDecoder"

  1. Go the the project's folder and double-click the QQrDecoder.pro file. This will result the Qt Creator to open. (This requires that Qt Creator is selected as the predefined program to open such files which is automatically set when installing Qt SDK.)
  2. Alternatively, open Qt Creator manually, and go under: "File" -> "Open File or Project...", go to the project's folder and select once again the QQrDecoder.pro.

Whichever step from the above you have followed, now you are led to screen named "Project Setup". Here you select the Target Platform. You can select "Symbian Device" to target directly for a physical device, or "Qt Simulator" to first test it to the build-in simulator.

Building the project

At this point you have imported the project and you are ready to compile it. At the left toolbar in Qt Creator, above the green arrow you can see the current target platform selected. Press to select which you want.

Now by pressing Ctrl+B or the "hammer icon" on the left at the bottom. Normally this should be completed without errors (might be lots of wrning though which we selectively reject them from our mind :P )

This step compiles the project BUT doesn't produces the .sis file (the installation file). To create the installation file you have to press the "Run button". It that "Green arrow" on your left, or by simply pressing Ctrl+R. Regardless if you have a device or not, the .sis file will be created.

Now you can install it to your device.


Download

  • File:ZXingBarcodeReader.zip
    This is the same implementation but without Qt. The GUI is implemented with Symbian C++ and again OpenC++ is required (for the ZXing library to work).

Licence


Useful Links

370 page views in the last 30 days.
×