123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #include "stdafx.h"
- #include "ParseQRInfo.h"
- #include "MatSource.h"
- CParseQRInfo::CParseQRInfo()
- {
- }
- CParseQRInfo::~CParseQRInfo()
- {
- }
- bool CParseQRInfo::parseQRInfo(cv::Mat&greyImg, char*buffer, std::size_t len)
- {
- bool bRet = false;
- try{
- // Create luminance source
- zxing::Ref<LuminanceSource> source = MatSource::create(greyImg);
- // Search for QR code
- zxing::Ref<zxing::Reader> reader;
- reader.reset(new QRCodeReader);
-
- zxing::Ref<zxing::Binarizer> binarizer(new zxing::GlobalHistogramBinarizer(source));
- zxing::Ref<zxing::BinaryBitmap> bitmap(new zxing::BinaryBitmap(binarizer));
- zxing::Ref<zxing::Result> result(reader->decode(bitmap, zxing::DecodeHints(zxing::DecodeHints::TRYHARDER_HINT)));
- auto txt = result->getText()->getText();
- if (len > txt.size()){
- strcpy_s(buffer, len, txt.c_str());
- bRet = true;
- }
- }
- catch (const zxing::ReaderException& e) {
- cerr << e.what() << " (ignoring)" << endl;
- }
- catch (const zxing::IllegalArgumentException& e) {
- cerr << e.what() << " (ignoring)" << endl;
- }
- catch (const zxing::Exception& e) {
- cerr << e.what() << " (ignoring)" << endl;
- }
- catch (const std::exception& e) {
- cerr << e.what() << " (ignoring)" << endl;
- }
- return bRet;
- }
|