示例#1
0
static Ref<String> decode_text(Ref<LuminanceSource> source)
{
	Ref<Binarizer> binarizer(new GlobalHistogramBinarizer(source));
	Ref<BinaryBitmap> bitmap(new BinaryBitmap(BinaryBitmap(binarizer)));
	DecodeHints hints(DecodeHints::BARCODEFORMAT_QR_CODE_HINT);
	QRCodeReader reader;

	return reader.decode(bitmap, hints)->getText();
}
示例#2
0
void decode_image(Image& image, bool localized) {
  try {
    Ref<MagickBitmapSource> source(new MagickBitmapSource(image));
    
    Ref<Binarizer> binarizer(NULL);
    if (localized) {
      binarizer = new LocalBlockBinarizer(source);
    } else {
      binarizer = new GlobalHistogramBinarizer(source);
    }
    

    Ref<BinaryBitmap> image(new BinaryBitmap(binarizer));
    QRCodeReader reader;
    Ref<Result> result(reader.decode(image));
    
    cout << result->getText()->getText() << endl;
  } catch (zxing::Exception& e) {
    cerr << "Error: " << e.what() << endl;
  }
}