Как декодировать QRCODE с помощью библиотеки C ++ opencv в Linux? - PullRequest
1 голос
/ 29 мая 2019

Я работаю с библиотекой opencv c ++ для декодирования Qrcode. Вот мой пример тестового кода с этого сайта: https://www.learnopencv.com/opencv-qr-code-scanner-c-and-python/

Когда я компилирую эту тестовую программу, я получаю следующую ошибку:

test.cc: In function ‘int main(int, char**)’:
test.cc:29:3: error: ‘QRCodeDetector’ was not declared in this scope
   QRCodeDetector qrDecoder = QRCodeDetector::QRCodeDetector();
   ^~~~~~~~~~~~~~
test.cc:33:22: error: ‘qrDecoder’ was not declared in this scope
   std::string data = qrDecoder.detectAndDecode(inputImage, bbox, rectifiedImage)

Как устранить эту ошибку?

test.cc:
//https://www.learnopencv.com/opencv-qr-code-scanner-c-and-python/
#include <opencv2/objdetect.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>

using namespace cv;
using namespace std;

void display(Mat &im, Mat &bbox)
{
  int n = bbox.rows;
  for(int i = 0 ; i < n ; i++)
  {
    line(im, Point2i(bbox.at<float>(i,0),bbox.at<float>(i,1)), Point2i(bbox.at<float>((i+1) % n,0), bbox.at<float>((i+1) % n,1)), Scalar(255,0,0), 3);
  }
  imshow("Result", im);
}

int main(int argc, char* argv[])
{
  // Read image
  Mat inputImage;

  inputImage = imread(argv[1]);

  QRCodeDetector qrDecoder = QRCodeDetector::QRCodeDetector();

  Mat bbox, rectifiedImage;

  std::string data = qrDecoder.detectAndDecode(inputImage, bbox, rectifiedImage);
  if(data.length()>0)
  {
    cout << "Decoded Data : " << data << endl;

    display(inputImage, bbox);
    rectifiedImage.convertTo(rectifiedImage, CV_8UC3);
    imshow("Rectified QRCode", rectifiedImage);

    waitKey(0);
  }
  else
    cout << "QR Code not detected" << endl;
}

//compile
g++ test.cc -o test `pkg-config opencv --cflags --libs`
...