44 lines
807 B
C++
44 lines
807 B
C++
#include <iostream>
|
|
#include "opencv2/opencv.hpp"
|
|
|
|
using namespace std;
|
|
using namespace cv;
|
|
|
|
int main() {
|
|
VideoCapture cap(0);
|
|
|
|
if (!cap.isOpened()) {
|
|
cerr << "Camera open failed!" << endl;
|
|
return 0;
|
|
}
|
|
|
|
QRCodeDetector detector;
|
|
|
|
Mat frame;
|
|
while (true) {
|
|
cap >> frame;
|
|
if (frame.empty())
|
|
break;
|
|
|
|
vector<Point> points;
|
|
Mat straightQRCode;
|
|
string info = detector.detectAndDecode(frame, points, straightQRCode);
|
|
resize(straightQRCode, straightQRCode, Size(200, 200));
|
|
|
|
if (!info.empty()) {
|
|
polylines(frame, points, true, Scalar(0, 0, 255), 2);
|
|
putText(frame, info, Point(10, 30), FONT_HERSHEY_DUPLEX, 1, Scalar(0, 0, 255));
|
|
imshow("QR", straightQRCode);
|
|
}
|
|
else {
|
|
destroyWindow("QR");
|
|
}
|
|
|
|
imshow("frame", frame);
|
|
|
|
if (waitKey(10) == 27)
|
|
break;
|
|
}
|
|
|
|
return 0;
|
|
} |