-
Notifications
You must be signed in to change notification settings - Fork 345
Home
Welcome to the QZXing wiki!
This is a wrapper library of the C++ part of ZXing library.
This library is mented to be very simple and will provide as simple as possible the decoding operations. Thus my main purpose is not to support extreme operations and complex techniques that ZXing library does support. Of course, the original ZXing code is still here for everyone interested in using something beyond the already implemented (those of you willing to make more operations available, their code is always welcomed to be merged).
Supported barcode types:
- UPC-A and UPC-E
- EAN-8 and EAN-13
- Code 39
- Code 93
- Code 128
- ITF
- Codabar
- RSS-14 (all variants)
- RSS Expanded (most variants)
- QR Code
- Data Matrix
- Aztec ('beta' quality)
- PDF 417 ('alpha' quality)
So, if you have a Qt project and your target is to decode a barcode contained in an image, then this is how is done...
There are 2 options on how to include/embed the library in your code.
- Use the source code of the project. Embed the source code of the project in your project, build it all as one and you are done. For more instructions see here.
Where the library needs to be used you have to include the header file: #include <qzxing.h>. Now a QZXing object can be created. It is recommended (but not obligatory) to use one instance of it and decode any number of barcodes you decide. The class supports 3 methods:
-
setDecoder(DecoderFormat): DecoderFormat is an enumeration regarding the types of barcodes the decoder will try to identify to each decoding. By default all the types are enabled but hence that it is extra processing. If you want to identify specific barcode types you can disable the other. This will result to faster processing. Conjunctions of more than one types of barcodes are supported using logical OR over the enumeration. For example if we need to support both Qt Codes and EAN 13 we need to call the following:
QZXing decoder; decoder.setDecoder( DecoderFormat_QR_CODE | DecoderFormat_EAN_13 );
This enable/disable operation of the decoders can be done any time needed.
-
registerQMLTypes(): If you are planning to use the library in the QML then in the main function you need to call this static function. It will register the QZXing library and make it visible to QML. After that, in the qml file you are planning to use the library you need to write at the top:
import QZXing 2.x //enter the version of the release
-
decodeImage(QImage image, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false): the method that initiates the decoding. It is made as a slot for convenience. It is blocking function thus if you need your application to continue without freezing, you can call it to an other thread. Finally return the result of the decoding. It also allows to scale the image before decoding to reduce the image resolution and make the decoding faster. If an error occurred it will return an empty string "".
-
decodeImage(QString imageFilePath, int maxWidth=-1, int maxHeight=-1, bool smoothTransformation = false): an overloaded version of the deodeImage function. The image is provided as a path to the image file in the local file system.
-
decodeImageQML(QObject*): the method that has to be called from QML to decode an Image Element. By calling this function the decoder will search the whole picture to find something to decode. As argument is used the Image QML element that holds the image that we want to decode. If is needed to decode only a specific part of the image use decodeSubImageQML. Introduced in version V1.2
-
decodeSubImageQML(QObject*, double, double, double, double): the method that has to be called from QML to decode only a portion of an Image Element. First argument is the Image QML element. The rest are as follows: offsetX, offsetY, width, height.
- offsetX, offsetY: define the starting point in the image where the portion that needs to be decoded starts.
- width, height: the size of the portion that will be decoded. Introduced in version V1.2
-
getProcessTimeOfLastDecoding(): Get the time in millisecond that lasted the last decoding operation. (Simply for statistical reasons)
-
decodingStarted(): signal emitted when decoding starts
-
decodingFinished(bool succeeded): signal emitted when decoding finishes reporting the success with the boolean.
-
tagFound(QString tag): emitted upon successful decoding of a barcode.
The repository contains 3 examples.
- QQrDecoder: (25/08/16: the example project is outdated, needs to be updated) uses Qt Mobility 1.1.3 with QCamera , VideoFinder and QWidgets. This is the same project previously hosted in this project page and this wiki article (the project page from now gets deprecated since the project will be hosted here from now on). It has known issues that i hope will get fixed at some point:
No automatic focus thus the user needs to press a button to initiate focusing, capturing and eventually decoding. A few were unable to use it because it constantly throughs various erros such as "General Camera error".
-
QZXingDragNDropTest: A desktop application mostly for debugging purposes. Contains a Drag'n'Drop area where the user drags an image file and it gets decoded. The result, if successful, is show at the console log below the Drag'n'Drop area. Also it contains a component for enabling or disabling the active decoders. If no decoder is selected, the image will be tested against all the supported formats.
-
QMLBarcodeDecoder: Needs Qt Mobility 1.2 and Qt 4.7.4 because Camera qml component got supported from that version and on. Hope it will solve the problems we had in the QQrDecoder.
And for the closing here is a small pretty QML code contained in the above project showing how it is used:
Camera{
id:camera
onImageCaptured:{
imageToDecode.source = preview
decoder.decodeImageQML(imageToDecode);
}
}
Image{
id:imageToDecode
}
QZXing{
id: decoder
enabledDecoders: QZXing.DecoderFormat_QR_CODE
onDecodingStarted: console.log("Decoding of image started...")
onTagFound: console.log("Barcode data: " + tag)
onDecodingFinished: console.log("Decoding finished " + (succeeded==true ? "successfully" : "unsuccessfully") )
}
If anyone needs anything feel free to ask in the project's forum.
Also your feedback is very important :)