5.从摄像机读入数据

    xiaoxiao2025-08-13  11

    from:http://blog.sina.com.cn/s/blog_6dbe9bdb0100nii7.html

    此程序可调用普通摄像头,未能调用kinect

    代码:

    /************************************************************************/ /* 由摄像机读入数据 */ /************************************************************************/ #include"highgui.h" #include"cv.h" //从摄像头中读入数据 int main(int argc,char** argv) { cvNamedWindow("Example1",CV_WINDOW_AUTOSIZE); CvCapture* capture; //初始化一个CvCapture结构的指针 if(argc==1) { capture=cvCaptureFromCAM(0);//如果参数为1,则从摄像头中读入数据,并返回一个CvCapture的指针 } //注:《学习OpenCV》中此处用cvCreateCameraCapture为错 else { capture=cvCreateFileCapture(argv[1]); } assert(capture!=NULL); //断言(assert)使用,检查capture是否为空指针,为假时程序退出,并打印错误消息 IplImage* frame; while(1) { frame=cvQueryFrame(capture);//用于将下一帧视频文件载入内存(实际是填充和更新CvCapture结构中),返回一个对应当前帧的指针 if(!frame) break; cvShowImage("Example1",frame); char c=cvWaitKey(33); if(c==27) break; //出发ESC键退出循环,读入数据停止 } cvReleaseCapture(&capture);//释放内存 cvDestroyWindow("Example1"); }

    运行结果:

    转载请注明原文地址: https://ju.6miu.com/read-1301702.html
    最新回复(0)