ORLAN

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

实验1

  实验目的:使用opencv操作摄像头拍摄一张图片

  函数:

   

1 CvCapture* cvCreateCameraCapture( int index ); 
2 IplImage* cvQueryFrame( CvCapture* capture ); 

  实验代码:

    

 1 #include"highgui.h"
 2 #include"cv.h"
 3 int main(){
 4     cvNamedWindow("w",0);
 5     IplImage* img;
 6     CvCapture* pCapture =cvCreateCameraCapture(0);
 7 
 8     cvWaitKey();
 9     img=cvQueryFrame( pCapture );
10     cvShowImage("w",img);
11     cvWaitKey();
12     
13     cvReleaseCapture(&pCapture);
14     cvDestroyWindow("w");
15     return 0;
16 }

 实验2

  实验目的:使用opencv操作摄像头拍摄视频

  实验代码:

 1 #include"highgui.h"
 2 #include"cv.h"
 3 int main(){
 4     cvNamedWindow("w",0);
 5     IplImage* img;
 6     CvCapture* pCapture =cvCreateCameraCapture(0);
 7 
 8     cvWaitKey();
 9 
10     while(1){
11         img=cvQueryFrame( pCapture );
12         cvShowImage("w",img);
13         char temp=cvWaitKey(40);
14         if(temp==27)break;
15     }
16     
17     cvReleaseCapture(&pCapture);
18     cvDestroyWindow("w");
19     return 0;
20 }

 

posted on 2014-05-19 21:15  ORLAN  阅读(273)  评论(0编辑  收藏  举报