Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/objdetect.hpp>
- #include <opencv2/imgcodecs.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include "opencv2/opencv.hpp"
- #include <iostream>
- using namespace std;
- using namespace cv;
- // this is a note for myself
- //https://www.youtube.com/watch?v=M-VHaLHC4XI
- //Utility function to display the box around the detected QR Code
- 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[])
- {
- VideoCapture cap(0);
- cap.set(CAP_PROP_BUFFERSIZE, 3);
- if (!cap.isOpened()) {
- cout << "Error opening video stream" << endl;
- return -1;
- }
- while (1) {
- Mat frame;
- cap >> frame;
- if (frame.empty())
- break;
- QRCodeDetector qrDecoder = QRCodeDetector::QRCodeDetector();
- Mat bbox, rectifiedVideo;
- //this line here seems to cause the video lag
- std::string data = qrDecoder.detectAndDecode(frame, bbox, rectifiedVideo);
- if (data.length() > 0)
- {
- cout << "Decoded Data : " << data << endl;
- }
- else
- cout << "QR Code not detected" << endl;
- display(frame, bbox);
- frame.convertTo(frame, CV_8UC3);
- imshow("realtime", frame);
- char c = (char)waitKey(1);
- if( c == 27 )
- break;
- }
- cap.release();
- destroyAllWindows();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement