/*
     * viewfinder_callback
     *
     * This callback is invoked when an image frame from the camera viewfinder becomes available.
     * The frame is analyzed to determine if a barcode can be matched.
     * Frames come in NV12 format which makes code analysis very fast.
     */
    void viewfinder_callback(camera_handle_t handle,camera_buffer_t* buf,void* arg) {
        camera_frame_nv12_t* data = (camera_frame_nv12_t*)(&(buf->framedesc));
        uint8_t* buff = buf->framebuf;
        int stride = data->stride;
        int width = data->width;
        int height = data->height;

        try {
            Ref<LuminanceSource> source(new GreyscaleLuminanceSource((unsigned char *)buff, stride, height, 0,0,width,height));

            Ref<Binarizer> binarizer(new HybridBinarizer(source));
            Ref<BinaryBitmap> bitmap(new BinaryBitmap(binarizer));
            Ref<Result> result;

            // setup the code reader
            MultiFormatReader *reader = new MultiFormatReader();
            DecodeHints *hints = new DecodeHints();

            hints->addFormat(BarcodeFormat_QR_CODE);
            hints->addFormat(BarcodeFormat_EAN_8);
            hints->addFormat(BarcodeFormat_EAN_13);
            hints->addFormat(BarcodeFormat_UPC_A);
            hints->addFormat(BarcodeFormat_UPC_E);
            hints->addFormat(BarcodeFormat_DATA_MATRIX);
            hints->addFormat(BarcodeFormat_CODE_128);
            hints->addFormat(BarcodeFormat_CODE_39);
            hints->addFormat(BarcodeFormat_ITF);
            hints->addFormat(BarcodeFormat_AZTEC);

			// attempt to decode and retrieve a valid QR code from the image bitmap
			result = reader->decode(bitmap, *hints);

            std::string newBarcodeData = result->getText()->getText().data();

            Json::FastWriter writer;
            Json::Value root;
            root["value"] = newBarcodeData;
            std::string event = "community.barcodescanner.codefound.native";

            // notify caller that a valid QR code has been decoded
            if ( eventDispatcher != NULL){
            	 eventDispatcher->NotifyEvent(event + " " + writer.write(root));
            }


#ifdef DEBUG
            fprintf(stderr, "This is the detected Barcode : %s\n", newBarcodeData.c_str());
#endif
        }
        catch (const std::exception& ex)
        {
#ifdef DEBUG
            fprintf( stderr, "error occured : \%s \n", ex.what());
#endif
        }
    }
//! [0]
BarcodeDecoderControl::BarcodeDecoderControl(Container *parent)
    : CustomControl(parent)
    , m_camera(new Camera(parent))
    , m_cameraSettings(new CameraSettings(this))
    , m_landscapePreviewFrames(false)
    , m_nbuffers(2)
{
    setRoot(m_camera);

    connect(m_camera, SIGNAL(cameraOpened()),
            this, SLOT(onCameraOpened()));

    connect(m_camera, SIGNAL(viewfinderStarted()),
            this, SLOT(viewfinderStarted()));

    connect(m_camera, SIGNAL(viewfinderStopped()),
            this, SLOT(onViewfinderStopped()));

    //Prepare the camera
    m_camera->open(CameraUnit::Rear);

    //Configure camera settings
    m_camera->getSettings(m_cameraSettings);
    m_cameraSettings->setCameraMode(CameraMode::Photo);
    m_cameraSettings->setFocusMode(CameraFocusMode::ContinuousMacro);

    if (m_camera->applySettings(m_cameraSettings))
        qDebug() << "settings applied successfully";

    //Prepare the decoder
    m_reader = Ref<MultiFormatReader>(new MultiFormatReader());
    DecodeHints *hints = new DecodeHints();
    hints->addFormat(BarcodeFormat_QR_CODE);
    hints->addFormat(BarcodeFormat_EAN_8);
    hints->addFormat(BarcodeFormat_EAN_13);
    hints->addFormat(BarcodeFormat_UPC_A);
    hints->addFormat(BarcodeFormat_UPC_E);
    hints->addFormat(BarcodeFormat_DATA_MATRIX);
    hints->addFormat(BarcodeFormat_CODE_128);
    hints->addFormat(BarcodeFormat_CODE_39);
    hints->addFormat(BarcodeFormat_ITF);
    hints->addFormat(BarcodeFormat_AZTEC);
    m_reader.object_->setHints(*hints);
}
Exemple #3
0
void TcZXing::setDecoder(DecoderFormatType hint)
{
    DecodeHints newHints;

    if(hint & DecoderFormat_QR_CODE)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_QR_CODE);

    if(hint & DecoderFormat_DATA_MATRIX)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_DATA_MATRIX);

    if(hint & DecoderFormat_UPC_E)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_UPC_E);

    if(hint & DecoderFormat_UPC_A)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_UPC_A);

    if(hint & DecoderFormat_EAN_8)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_EAN_8);

    if(hint & DecoderFormat_EAN_13)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_EAN_13);

    if(hint & DecoderFormat_CODE_128)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_CODE_128);

    if(hint & DecoderFormat_CODE_39)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_CODE_39);

    if(hint & DecoderFormat_ITF)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_ITF);

    if(hint & DecoderFormat_Aztec)
        newHints.addFormat((BarcodeFormat)BarcodeFormat_AZTEC);

    supportedFormats = newHints.getCurrentHint();
}