OpenCV例子二:打开摄像头及显示到窗口

た 入场券 2022-08-07 08:39 165阅读 0赞
  1. #include <iostream>
  2. #include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
  3. #include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
  4. #include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
  5. using namespace cv;//必须加入,否则无法检找到OPENCV的各个函数
  6. using namespace std;
  7. int _tmain(int argc, _TCHAR* argv[])
  8. {
  9. VideoCapture cap(0); // open the default camera
  10. if (!cap.isOpened()) // check if we succeeded
  11. return -1;
  12. Mat edges;
  13. for (;;)
  14. {
  15. if (!cap.isOpened())
  16. {//等等摄像头打开
  17. continue;
  18. }
  19. Mat frame;
  20. cap >> frame; // get a new frame from camera
  21. if (frame.data == NULL)
  22. {//等到捕获到数据
  23. continue;
  24. }
  25. cvtColor(frame, edges, CV_BGR2BGRA);
  26. imshow("edges", edges);
  27. if (waitKey(30) >= 0) break;
  28. }
  29. return 0;
  30. }
  31. 来自:http://blog.csdn.net/lan120576664

发表评论

表情:
评论列表 (有 0 条评论,165人围观)

还没有评论,来说两句吧...

相关阅读