windows 下 opencv highgui 多个摄像头采集

 1 #include  < cvcam.h >
 2 #include  < cv.h >
 3 #include  < highgui.h >
 4 #include  < stdio.h >
 5
 6 void  StereoCallback(IplImage  * frame1,IplImage  * frame2);
 7
 8 IplImage  * image1, * image2;
 9 int  n = 0 ;
10
11 void  main()
12 {
13//achrive cameras numbers
14    int *CameraNumber;
15    int nSelected = cvcamSelectCamera(&CameraNumber);
16
17//IplImage* frame1;
18//IplImage *frame2;
19//彩色图像
20    image1=cvCreateImage(cvSize(320,240),IPL_DEPTH_8U,3);
21    image2=cvCreateImage(cvSize(320,240),IPL_DEPTH_8U,3);
22
23//初始化两个摄像头
24
25        cvcamSetProperty(CameraNumber[0], CVCAM_PROP_ENABLE, CVCAMTRUE);
26        cvcamSetProperty(CameraNumber[0], CVCAM_PROP_RENDER, CVCAMTRUE);
27
28        cvcamSetProperty(CameraNumber[1], CVCAM_PROP_ENABLE, CVCAMTRUE);
29        cvcamSetProperty(CameraNumber[1], CVCAM_PROP_RENDER, CVCAMTRUE);
30
31
32//让两个摄像头同步
33        cvcamSetProperty(CameraNumber[0], CVCAM_STEREO_CALLBACK,(void *)&StereoCallback);
34        cvNamedWindow("WIN1",1);
35        cvNamedWindow("WIN2",2);
36
37//启动程序
38        printf("s2 \n");
39        cvcamInit();
40        cvcamStart();
41        printf("s3 \n");
42
43    while(1)
44    {
45        if(cvWaitKey(10)>=0)
46            break;
47        else
48        {
49            cvShowImage("WIN1",image1);
50            cvShowImage("WIN2",image2);
51        }

52    }

53
54    cvcamStop();
55    cvcamExit();
56    cvWaitKey(0);
57
58//    cvDestroyWindow("cvcam1 Window");
59//    cvDestroyWindow("cvcam2 Window");
60      cvDestroyWindow("WIN1");
61      cvDestroyWindow("WIN2");
62      cvReleaseImage(&image1);
63      cvReleaseImage(&image1);
64}

65
66 void  StereoCallback(IplImage *  frame1,IplImage  * frame2)
67 {
68    image1=cvCloneImage(frame1);    
69    image2=cvCloneImage(frame2);
70
71//    cvFlip(image1,image1,0);
72//    cvFlip(image2,image2,0);
73
74    n=n+1;
75    printf("frame %d \n",n);
76
77    cvSaveImage("C:\\image1.jpg",image1);
78    cvSaveImage("C:\\image2.jpg",image2);
79
80  }

81

你可能感兴趣的:(windows)