Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include <opencv2/objdetect.hpp>
  2. #include <opencv2/imgcodecs.hpp>
  3. #include <opencv2/highgui/highgui.hpp>
  4. #include <opencv2/imgproc/imgproc.hpp>
  5. #include "opencv2/opencv.hpp"
  6. #include <iostream>
  7. using namespace std;
  8. using namespace cv;
  9.  
  10. // this is a note for myself
  11. //https://www.youtube.com/watch?v=M-VHaLHC4XI
  12.  
  13. //Utility function to display the box around the detected QR Code
  14. void display(Mat& im, Mat& bbox)
  15. {
  16. int n = bbox.rows;
  17. for (int i = 0; i < n; i++)
  18. {
  19. 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);
  20. }
  21. //imshow("Result", im);
  22. }
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26. VideoCapture cap(0);
  27.  
  28. cap.set(CAP_PROP_BUFFERSIZE, 3);
  29.  
  30. if (!cap.isOpened()) {
  31. cout << "Error opening video stream" << endl;
  32. return -1;
  33. }
  34.  
  35. while (1) {
  36.  
  37. Mat frame;
  38. cap >> frame;
  39.  
  40. if (frame.empty())
  41. break;
  42.  
  43. QRCodeDetector qrDecoder = QRCodeDetector::QRCodeDetector();
  44.  
  45. Mat bbox, rectifiedVideo;
  46.  
  47. //this line here seems to cause the video lag
  48. std::string data = qrDecoder.detectAndDecode(frame, bbox, rectifiedVideo);
  49.  
  50. if (data.length() > 0)
  51. {
  52. cout << "Decoded Data : " << data << endl;
  53. }
  54. else
  55. cout << "QR Code not detected" << endl;
  56.  
  57.  
  58. display(frame, bbox);
  59. frame.convertTo(frame, CV_8UC3);
  60. imshow("realtime", frame);
  61.  
  62. char c = (char)waitKey(1);
  63. if( c == 27 )
  64. break;
  65. }
  66. cap.release();
  67. destroyAllWindows();
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement