BarcodeDetector

Since: BlackBerry 10.0.0

#include <bb/cascades/multimedia/BarcodeDetector>

To link against this class, add the following line to your .pro file: LIBS += -lbbcascadesmultimedia

Allows detection of barcode codes.

When attached to a Camera, this class will search for barcodes. When a barcode is detected, the detected() signal is emitted.

By default, BarcodeDetector will search for QR codes. It can be configured to search for other barcode formats using the formats property.

Barcodes can only be detected when the Camera can provide preview frames. This generally means that the viewfinder must be active.

In order to function correctly, there must be only one instance of BarcodeDetector attached to a Camera instance, and that Camera instance must not have any other consumers of its preview frames.

Example usage in QML
import bb.cascades 1.0
import bb.cascades.multimedia 1.0

Page {
    Container {
        Camera {
            id: camera            
            horizontalAlignment: HorizontalAlignment.Fill
            verticalAlignment: VerticalAlignment.Fill

            attachedObjects: [
                BarcodeDetector {
                    id: barcodeDetector    
                    formats: BarcodeFormat.Any
                    camera: camera
                    
                    onBarcodeDetected: {
                        // Content of the barcode is delivered here as 'data'
                    }               
                }
            ]
            
            onCameraOpened: {                
                camera.startViewfinder();
            }               
        }
    }
    
    onCreationCompleted: {
        camera.open();        
    }
}


Overview

QML properties

camera: bb::cascades::multimedia::Camera
formats: bb::cascades::multimedia::BarcodeFormat::Types

Properties Index

bb::cascades::multimedia::Cameracamera
bb::cascades::multimedia::BarcodeFormat::Typesformats

Public Functions Index

BarcodeDetector (QObject *parent=0)
virtual ~BarcodeDetector ()
bb::cascades::multimedia::Camera *camera () const
bb::cascades::multimedia::BarcodeFormat::Typesformats () const
QStringscanImage (bb::ImageData const &image, bb::cascades::multimedia::BarcodeFormat::Type *foundFormat=0) const
Q_SLOT voidsetCamera (bb::cascades::multimedia::Camera *camera)
Q_SLOT voidsetFormats (bb::cascades::multimedia::BarcodeFormat::Types formats)

Signals Index

voidcameraChanged (bb::cascades::multimedia::Camera *camera)
voiddetected (const QString &data, bb::cascades::multimedia::BarcodeFormat::Type format)
voidformatsChanged (bb::cascades::multimedia::BarcodeFormat::Types newFormats)
voidpotentialRegistrationMarkDetected (const QPoint &position)
voidregistrationMarksDetected (const QList< QPoint > &positions)
voidscanCompleted ()
voidscanStarted ()

Properties

bb::cascades::multimedia::Camera camera

The Camera to which this detector is attached.

Since:

BlackBerry 10.0.0

bb::cascades::multimedia::BarcodeFormat::Types formats

The barcode formats that this detector should look for.

The detector can search for multiple formats at the same time. When a barcode is detected, the BarcodeFormat is included in the detected() signal.

Since:

BlackBerry 10.0.0

Public Functions

BarcodeDetector (

Creates an instance of the BarcodeDetector class.

Parameters
parent

If not 0, the supplied parent will be responsible for deleting this instance.

Since:

BlackBerry 10.0.0

virtual~BarcodeDetector ()

Destructor.

Since:

BlackBerry 10.0.0

bb::cascades::multimedia::Camera * camera ()

Gets the Camera to which this detector is attached.

Return:

The Camera to which this detector is attached.

Since:

BlackBerry 10.0.0

bb::cascades::multimedia::BarcodeFormat::Types formats ()

Gets the barcode formats that this detector is looking for.

Return:

The barcode formats that this detector is looking for.

Since:

BlackBerry 10.0.0

QString scanImage (

Looks for a barcode within a given Image.

Independent of the camera-based detection, you can search for barcodes in any image. This function searches for the same set of barcode formats as are set using setFormats().

Parameters
image

The image containing a barcode.

foundFormat

An optional output parameter. If not null, then on successful detection foundFormat is set to the type of barcode found. Otherwise, it is left unchanged.

Return:

The barcode data, or an empty string if no barcode was detected.

Since:

BlackBerry 10.0.0

Q_SLOT void setCamera (

Attaches this detector to a Camera.

The detector can only be attached to one Camera at once, so calling this function will detach the detector from the Camera to which it was previously attached, if any. Passing NULL will cause the detector to be detached from the current Camera, if any.

BarcodeDetector will use CameraFocusMode::ContinuousAuto on the attached Camera. This is done because the BarcodeDetector is most effective on barcodes that are in focus.

Parameters
camera

The Camera to attach this detector to.

Since:

BlackBerry 10.0.0

Q_SLOT void setFormats (
  • bb::cascades::multimedia::BarcodeFormat::Typesformats)

Sets the barcode formats that this detector should look for.

The detector can search for multiple formats at the same time. When a barcode is detected, the BarcodeFormat is included in the detected() signal.

Parameters
formats

The barcodes formats that this detector should look for.

Since:

BlackBerry 10.0.0

Signals

void cameraChanged (

Emitted when a new Camera is attached or when this detector is detached from the current Camera.

Parameters
camera

The new camera for this object.

Since:

BlackBerry 10.0.0

void detected (

Emitted when a barcode is detected.

Barcodes can only be detected when the Camera can provide preview frames. This generally means that the viewfinder must be active.

Parameters
data

The barcode data.

format

The format of the barcode that was detected.

Since:

BlackBerry 10.0.0

void formatsChanged (
  • bb::cascades::multimedia::BarcodeFormat::TypesnewFormats)

Emitted when the formats property changes.

Parameters
newFormats

The new value of the formats property.

Since:

BlackBerry 10.0.0

void potentialRegistrationMarkDetected (

Emitted when a potential registration mark has been detected in the scanned image.

Parameters
position

The point at which the mark is located, scaled to the dimensions of the Camera viewfinder used by the attached BarcodeDetector.

Since:

BlackBerry 10.0.0

void registrationMarksDetected (

Emitted when registration marks have been detected.

The list of points are the detected registration marks of the detected barcode.

Parameters
positions

The list of points defining the registration marks of the detected barcode.

Since:

BlackBerry 10.0.0

void scanCompleted ()

Emitted when the scan of an image, or a camera frame, is completed when looking for a barcode.

This signal will always be emitted before the detected() signal can be emitted.

Note:
The order of events, per frame, is:
Since:

BlackBerry 10.0.0

void scanStarted ()

Emitted at the start of scanning an image, or a camera frame, when looking for a barcode.

This signal will always be emitted before the detected() signal can be emitted.

Note:
The order of events, per frame, is:
Since:

BlackBerry 10.0.0

Last modified: 2014-09-30



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus