實驗2014051901:opencv操做攝像頭

實驗1函數

  實驗目的:使用opencv操做攝像頭拍攝一張圖片ui

  函數:spa

   

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

  實驗代碼:code

    

 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操做攝像頭拍攝視頻blog

  實驗代碼:圖片

 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 }
相關文章
相關標籤/搜索