#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 source = MatSource::create(greyImg); // Search for QR code zxing::Ref reader; reader.reset(new QRCodeReader); zxing::Ref binarizer(new zxing::GlobalHistogramBinarizer(source)); zxing::Ref bitmap(new zxing::BinaryBitmap(binarizer)); zxing::Ref 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; }