开发者

OpenCV: Camera choosing - strange behavior (2 cameras)

开发者 https://www.devze.com 2023-03-23 03:12 出处:网络
I have few cameras in system. I initialise开发者_JAVA百科 them this way cap1 = cvCreateCameraCapture(0);

I have few cameras in system. I initialise开发者_JAVA百科 them this way

cap1 = cvCreateCameraCapture(0); 
cap2 = cvCreateCameraCapture(1); // or -1

But after each execution their behaviour is different: they work together or both or them don't work or one of them captures well and other shows green screen. And sometimes system shows me dialogue box for choosing device.

Here is this part of source code:

    CvCapture* cap2;
    CvCapture* cap1;
    printf("- Searching first cam : \n");

    for (i; i < LASTCAM; i++)
    {
        cap1 = cvCreateCameraCapture(i);
        if (!cap1)
        {
            printf("-- Camera %d is empty \n", i);
        }
        else
        {
            printf("-- Camera %d is OK \n", i);
            i++;
            break;
        }
    }
    printf("- Searching second cam : \n");
    for (; i < LASTCAM; i++)
    {
        cap2 = cvCreateCameraCapture(i);
        if (!cap2)
        {
            printf("-- Camera %d is empty \n", i);
        }
        else
        {
            printf("-- Camera %d is OK \n", i);
            break;
        }
    }        printf("Frame propeties:\n");
    double width = cvGetCaptureProperty(cap1, CV_CAP_PROP_FRAME_WIDTH);
    double height = cvGetCaptureProperty(cap1, CV_CAP_PROP_FRAME_HEIGHT);
    printf("First cam : %.0f x %.0f\n", width, height );

    double width2 = cvGetCaptureProperty(cap2, CV_CAP_PROP_FRAME_WIDTH);
    double height2 = cvGetCaptureProperty(cap2, CV_CAP_PROP_FRAME_HEIGHT);
    printf("Second cam : %.0f x %.0f\n\n", width2, height2 );

    IplImage* frame1=0;
    IplImage* frame2=0;

    cvNamedWindow("cam1", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("cam2", CV_WINDOW_AUTOSIZE);

    int counter=0;
    char filename[512];

    while(true){
             frame1 = cvQueryFrame( cap1 );
            frame2 = cvQueryFrame( cap2 );
            cvShowImage("cam1", frame1);
            cvShowImage("cam2", frame2);
    ...

what's wrong with it?

1-9 cams are empty; 10 - first cam, 11-infinity - returns cams which are "green screens".

Thanks beforehand.


Have you looked at the stereo mode? It looks like it's required if you want to run multiple cameras.


USB cameras (at least through directshow on windows) can be a little difficult.

Some things to try:

// A small delay between the captures 
cap1 = cvCreateCameraCapture(0); 
Sleep(100);
cap2 = cvCreateCameraCapture(1); 

or

// call all the setup functiosn for camera0 before capturing camera1     
cap1 = cvCreateCameraCapture(0); 
cvGetCaptureProperty(cap1,......)
cap2 = cvCreateCameraCapture(1); 
cvGetCaptureProperty(cap2,......)
0

精彩评论

暂无评论...
验证码 换一张
取 消