ParseQRInfo.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "stdafx.h"
  2. #include "ParseQRInfo.h"
  3. #include "MatSource.h"
  4. CParseQRInfo::CParseQRInfo()
  5. {
  6. }
  7. CParseQRInfo::~CParseQRInfo()
  8. {
  9. }
  10. bool CParseQRInfo::parseQRInfo(cv::Mat&greyImg, char*buffer, std::size_t len)
  11. {
  12. bool bRet = false;
  13. try{
  14. // Create luminance source
  15. zxing::Ref<LuminanceSource> source = MatSource::create(greyImg);
  16. // Search for QR code
  17. zxing::Ref<zxing::Reader> reader;
  18. reader.reset(new QRCodeReader);
  19. zxing::Ref<zxing::Binarizer> binarizer(new zxing::GlobalHistogramBinarizer(source));
  20. zxing::Ref<zxing::BinaryBitmap> bitmap(new zxing::BinaryBitmap(binarizer));
  21. zxing::Ref<zxing::Result> result(reader->decode(bitmap, zxing::DecodeHints(zxing::DecodeHints::TRYHARDER_HINT)));
  22. auto txt = result->getText()->getText();
  23. if (len > txt.size()){
  24. strcpy_s(buffer, len, txt.c_str());
  25. bRet = true;
  26. }
  27. }
  28. catch (const zxing::ReaderException& e) {
  29. cerr << e.what() << " (ignoring)" << endl;
  30. }
  31. catch (const zxing::IllegalArgumentException& e) {
  32. cerr << e.what() << " (ignoring)" << endl;
  33. }
  34. catch (const zxing::Exception& e) {
  35. cerr << e.what() << " (ignoring)" << endl;
  36. }
  37. catch (const std::exception& e) {
  38. cerr << e.what() << " (ignoring)" << endl;
  39. }
  40. return bRet;
  41. }