码迷,mamicode.com
首页 > 其他好文 > 详细

2、由摄像机读入数据

时间:2016-02-28 16:51:33      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

OpenCV的HighGUI模块提供了cvCreateCameraCapture(),可以从摄像设备中读入视频流,函数参数为设备ID而不是文件名。默认值为-1,即随机选择一个设备。

示例程序:

 1 /************************************************************************/
 2 /* 由摄像机读入数据                                                     */
 3 /************************************************************************/
 4 
 5 #include "cv.h"
 6 #include "highgui.h"
 7 
 8 int main(int argc, char** argv)
 9 {
10     cvNamedWindow("cameraCapture", CV_WINDOW_AUTOSIZE);
11     CvCapture* capture;
12     if (argc == 1)
13     {
14         capture = cvCreateCameraCapture(-1);
15     } 
16     else
17     {
18         capture = cvCreateFileCapture(argv[1]);
19     }
20     assert(capture != NULL);
21 
22     IplImage* frame;
23     while (1)
24     {
25         frame = cvQueryFrame(capture);
26         if(!frame) break;
27         cvShowImage("cameraCapture", frame);
28         char c = cvWaitKey(33);    //设置帧率
29         if(c == 27) break;    //按ESC退出
30     }
31 
32     cvReleaseCapture(&capture);
33     cvDestroyWindow("cameraCapture");
34 
35     return 0;
36 }

 

2、由摄像机读入数据

标签:

原文地址:http://www.cnblogs.com/chan20160228/p/5224945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!