Exemplo n.º 1
0
int processFilepath(
    const char * filename, // name of the file to be read
    std::ostream * os, // output stream to use (NULL for no output). Not that cerr is used to report errors.
    MultiFormatReader::DataFormatType fmt, // enum indicating the file format to expect.
    INIReader & iniReader) {
    assert(filename);
    int rc;
    try {
        MultiFormatReader * nexusReader;
        nexusReader = instantiateReader();
        if (!gQuietMode) {
            cerr << "Executing" << endl;
        }
        try {
            nexusReader->DemoteBlocks();
            nexusReader->ReadFilepath(filename, fmt);
            rc = processContent(*nexusReader, filename, os, iniReader);
        } catch(...) {
            nexusReader->DeleteBlocksFromFactories();
            delete nexusReader;
            throw;
        }
        nexusReader->DeleteBlocksFromFactories();
        delete nexusReader;
        return rc;
    } catch (const NxsException &x) {
        cerr << "Error:\n " << x.msg << endl;
        if (x.line > 0 || x.pos > 0) {
            cerr << "at line " << x.line << ", column (approximately) " << x.col << " (and file position "<< x.pos << ")" << endl;
        }
        return 2;
    }
}
Exemplo n.º 2
0
void QQrDecoder::decodeImage(QImage originalImage)
{
    MultiFormatReader decoder;

    image.setImage(originalImage);

    Ref<Result> res;

    try{
        Ref<LuminanceSource> imageRef(new CameraImageWrapper(image));
        GlobalHistogramBinarizer* binz = new GlobalHistogramBinarizer(imageRef);

        Ref<Binarizer> bz (binz);
        BinaryBitmap* bb = new BinaryBitmap(bz);

        Ref<BinaryBitmap> ref(bb);

        res = decoder.decode(ref);

        QString string = QString(res->getText()->getText().c_str());
        QMessageBox::information((QWidget*)ui.centralwidget, QString("Decoding result") ,string);
    }
    catch(zxing::Exception& e)
    {
       // QMessageBox::information((QWidget*)ui.centralwidget, QString("Decoding result"), QString("Error"));
    }
}
    /*
     * 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
        }
    }
Exemplo n.º 4
0
  int processFilepath(
		      const char * filename, // name of the file to be read
		      ostream * , // output stream to use (NULL for no output). Not that cerr is used to report errors.
		      MultiFormatReader::DataFormatType fmt, // enum indicating the file format to expect.
		      ProcessActionsEnum ) // enum that is passed on to processContent to indicate what should be done with the content of the file.
#endif 
{
  assert(filename);
  try
    {
      MultiFormatReader * nexusReader;
#		if defined(MULTIFILE_NEXUS_READER) && MULTIFILE_NEXUS_READER
      nexusReader = gNexusReader;
#		else
      nexusReader = instantiateReader();
#		endif
	    
      if (!gQuietMode)
	cerr << "Executing" << endl;
      try {
	nexusReader->DemoteBlocks();
	nexusReader->ReadFilepath(filename, fmt);
#			if !defined(MULTIFILE_NEXUS_READER) ||  !MULTIFILE_NEXUS_READER
	                processContent(*nexusReader, os, currentAction);
#			endif
      }
      catch(...) {
	nexusReader->DeleteBlocksFromFactories();
#	if ! defined(MULTIFILE_NEXUS_READER) || !MULTIFILE_NEXUS_READER
	delete nexusReader;
#	endif
	throw;
      }
#     if !defined(MULTIFILE_NEXUS_READER) ||  !MULTIFILE_NEXUS_READER
      nexusReader->DeleteBlocksFromFactories();
      delete nexusReader;
#     endif
      return 0;
    }
  catch (const NxsException &x)
    {
      cerr << "Error:\n " << x.msg << endl;
      if (x.line > 0 || x.pos > 0)
	cerr << "at line " << x.line << ", column (approximately) " << x.col << " (and file position "<< x.pos << ")" << endl;
      return 2;
    }
}
Exemplo n.º 5
0
MultiFormatReader * instantiateReader() {
    MultiFormatReader * nexusReader = new MultiFormatReader(-1, NxsReader::WARNINGS_TO_STDERR);
    if (gQuietMode) {
        nexusReader->SetWarningOutputLevel(NxsReader::SKIPPING_CONTENT_WARNING);
    }
    if (gStrictLevel != 2) {
        nexusReader->SetWarningToErrorThreshold((int)NxsReader::FATAL_WARNING + 1 - (int) gStrictLevel);
    }
    NxsCharactersBlock * charsB = nexusReader->GetCharactersBlockTemplate();
    NxsDataBlock * dataB = nexusReader->GetDataBlockTemplate();
    charsB->SetAllowAugmentingOfSequenceSymbols(true);
    dataB->SetAllowAugmentingOfSequenceSymbols(true);
    NxsTreesBlock * treesB = nexusReader->GetTreesBlockTemplate();
    assert(treesB);
    if (gStrictLevel < 2) {
        treesB->SetAllowImplicitNames(true);
    }
    treesB->setValidateInternalNodeLabels(gValidateInternals);
    treesB->setAllowNumericInterpretationOfTaxLabels(true);
    if (gStrictLevel < 2) {
        NxsStoreTokensBlockReader *storerB =  nexusReader->GetUnknownBlockTemplate();
        assert(storerB);
        storerB->SetTolerateEOFInBlock(true);
    }
    nexusReader->conversionOutputRecord.addNumbersToDisambiguateNames = true;
    return nexusReader;
}
Exemplo n.º 6
0
MultiFormatReader * instantiateReader() {
  MultiFormatReader * nexusReader = new MultiFormatReader(-1, NxsReader::WARNINGS_TO_STDERR);
  if (gQuietMode)
    nexusReader->SetWarningOutputLevel(NxsReader::SKIPPING_CONTENT_WARNING);
  if (gStrictLevel != 2)
    nexusReader->SetWarningToErrorThreshold((int)NxsReader::FATAL_WARNING + 1 - (int) gStrictLevel);
  if (gUnderscoresToSpaces) 
    nexusReader->SetCoerceUnderscoresToSpaces(true);
  NxsCharactersBlock * charsB = nexusReader->GetCharactersBlockTemplate();
  NxsDataBlock * dataB = nexusReader->GetDataBlockTemplate();
  charsB->SetAllowAugmentingOfSequenceSymbols(true);
  dataB->SetAllowAugmentingOfSequenceSymbols(true);
  if (gInterleaveLen > 0) {
    assert(charsB);
    charsB->SetWriteInterleaveLen(gInterleaveLen);
    dataB->SetWriteInterleaveLen(gInterleaveLen);
  }
  
  NxsTreesBlock * treesB = nexusReader->GetTreesBlockTemplate();
  assert(treesB);
  if (gStrictLevel < 2)
    treesB->SetAllowImplicitNames(true);
  treesB->SetWriteFromNodeEdgeDataStructure(gTreesViaInMemoryStruct);
  treesB->setValidateInternalNodeLabels(gValidateInternals);
  if (gAltNexus)
    treesB->setWriteTranslateTable(false);
  if (gStrictLevel < 2) {
    NxsStoreTokensBlockReader *storerB =  nexusReader->GetUnknownBlockTemplate();
    assert(storerB);
    storerB->SetTolerateEOFInBlock(true);
  }
  nexusReader->conversionOutputRecord.addNumbersToDisambiguateNames = true;
  
  if (gSuppressingNameTranslationFile)
    nexusReader->conversionOutputRecord.writeNameTranslationFile = false;
  return nexusReader;
}