OpenCV(C++)第一章课后作业
检测二维码提取其中数据并画框
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc,char** argv)
{
Mat QR = imread("./test.jpg");
Size size = Size(QR.cols/4, QR.rows/4);
resize(QR, QR,size, INTER_LINEAR);
QRCodeDetector qr;
vector<Point> list,test;
/*if (!qr.detect(QR, list))
return -1;
for (auto w : list)
cout << w << endl;
line(QR, list[0], list[1], Scalar(255,0,0), 3);
line(QR, list[0], list[3], Scalar(255, 0, 0), 3);
line(QR, list[1], list[2], Scalar(255, 0, 0), 3);
line(QR, list[2], list[3], Scalar(255, 0, 0), 3);
Mat b = cv::Mat::zeros(cv::Size(640, 480), CV_8UC3);*/
Point origin;
origin.x = QR.cols/16;
origin.y = QR.rows/4;
double fontScale = 0.35;
string text=qr.detectAndDecode(QR, test);
cout << text << endl;
cout << text.length()<<endl;
for (auto w : test)
cout << w << endl;
line(QR, test[0], test[1], Scalar(255, 0, 0), 3);
line(QR, test[0], test[3], Scalar(255, 0, 0), 3);
line(QR, test[1], test[2], Scalar(255, 0, 0), 3);
line(QR, test[2], test[3], Scalar(255, 0, 0), 3);
putText(QR, text, origin, FONT_HERSHEY_COMPLEX, fontScale, Scalar(255, 0, 255), true);
imshow("hh1", QR);
waitKey(0);
imwrite("./result.jpg", QR);
return 0;
}