forked from 790hanu/Annex-qr-code-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Qrcode.cpp
44 lines (38 loc) · 1.08 KB
/
Qrcode.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#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;
if(argc>1)
inputImage = imread(argv[1]);
else
inputImage = imread("qrcode-learnopencv.jpg");
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;
}