OpenCV 调用摄像头

谁践踏了优雅 2022-07-11 08:21 437阅读 0赞

OpenCV调用摄像头还是很简单的,同样是由VideoCapture 来控制,一种是VideoCapture(const string& filename)用来打开视频文件,一种是VideoCapture(int device)用来打开设备。

  1. #include <opencv2/highgui/highgui.hpp>
  2. #include <opencv2/imgproc/imgproc.hpp>
  3. #include <opencv2/core/core.hpp>
  4. using namespace cv;
  5. int main()
  6. {
  7. VideoCapture cap(0);
  8. if(!cap.isOpened())
  9. {
  10. return -1;
  11. }
  12. Mat frame;
  13. Mat edges;
  14. bool stop = false;
  15. while(!stop)
  16. {
  17. cap>>frame;
  18. imshow("video",frame);
  19. if(waitKey(30) >=0)
  20. stop = true;
  21. }
  22. return 0;
  23. }

摄像头的调用还是用imshow来显示,一般都会将按帧获取的图像放进循环中,此时一直在循环的显示图像,就出来了实时的效果。

发表评论

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

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

相关阅读