linux 下用opencv 驱动多个摄像头

 1 #include "cv.h"
 2 #include "highgui.h"
 3  
 4 #include <stdio.h>
 5 #include <stdlib.h>
 6  
 7 #ifdef _EiC
 8 #define WIN32
 9 #endif
12 
13 int main(  )
14 {
15     CvCapture* capture = 0;
16     IplImage *frame, *frame_copy = 0;
17     CvCapture* capture2 = 0;
18     IplImage *frame2, *frame_copy2 = 0;
19   
20     capture = cvCaptureFromCAM(-1);
21     capture2 = cvCaptureFromCAM(-1);
22 
23  
24    if( capture)
25 
26     {
27         for(;;)
28         {
29             if!cvGrabFrame( capture ))
30                 break;
31             frame = cvRetrieveFrame( capture );
32             if!frame )
33                 break;
34             if!frame_copy )
35                 frame_copy = cvCreateImage( cvSize(frame->width,frame->height),
36                                             IPL_DEPTH_8U, frame->nChannels );
37             if( frame->origin == IPL_ORIGIN_TL )
38                 cvCopy( frame, frame_copy, 0 );
39             else
40                 cvFlip( frame, frame_copy, 0 );
41  
42               cvNamedWindow("cam",1);
43        cvShowImage("cam",frame_copy);
44 
45 
46 
47 ////////////////////////////////////
48             if!cvGrabFrame( capture2 ))
49                 break;
50             frame2 = cvRetrieveFrame( capture2 );
51             if!frame2 )
52                 break;
53             if!frame_copy2 )
54                 frame_copy2 = cvCreateImage( cvSize(frame2->width,frame2->height),
55                                             IPL_DEPTH_8U, frame2->nChannels );
56             if( frame2->origin == IPL_ORIGIN_TL )
57                 cvCopy( frame2, frame_copy2, 0 );
58             else
59                 cvFlip( frame2, frame_copy2, 0 );
60  
61               cvNamedWindow("cam2",1);
62        cvShowImage("cam2",frame_copy2);
63  
64             if( cvWaitKey( 10 ) >= 0 )
65                 break;
66 
67         }
68  
69         cvReleaseImage( &frame_copy );
70         cvReleaseCapture( &capture );
71         cvReleaseImage( &frame_copy2 );
72         cvReleaseCapture( &capture2 );
73     }
74 
75 
76 }

 通过多次的调用cvCaptureFromCAM来实现驱动多个摄像头。

posted on 2009-10-26 18:53  Homography Matrix  阅读(2190)  评论(0编辑  收藏  举报

导航