Ask Your Question

Revision history [back]

There is something wrong when I read 2+ cameras.

I have a project recently that I need to read more than 2 cameras using OpenCV. But I am facing a weird problem that I can't solve. When I execute my code step by step, it just OK, but when I run my project automatically, there is something wrong. Here is my code:

while (1)
{
////////////////////////////////////////////////////////////////////////////////
//When I execute the following part step by step, it is just OK
//But when I run the project automatically, there is someting wrong
    for (i=0; i<3; i++){
        cap = cvCaptureFromCAM(i);
        cvGrabFrame(cap);
        cam = cvRetrieveFrame(cap);
        cvCopy(cam, ImageBuffer[i]);
        cvReleaseCapture(&cap);
    }
///////////////////////////////////////////////////////////////////////////////
    cvGetCols(pairs, &part, 0, 640);                    
    cvCopy(ImageBuffer[0], &part);
    cvGetCols(pairs, &part, 640, 640*2);
    cvCopy(ImageBuffer[1], &part);
    cvGetCols(pairs, &part, 640*2, 640*3);
    cvCopy(ImageBuffer[2], &part);
    cvShowImage("Pairs", pairs);

    if(27==cvWaitKey(10))
        break;
}

When I run the project, the error is like that: image description

So, what is wrong with my code? Can anyone could solve the problem? Thanks In Advance!

There is something wrong when I read 2+ cameras.

I have a project recently that I need to read more than 2 cameras using OpenCV. But I am facing a weird problem that I can't solve. When I execute my code step by step, it just OK, but when I run my project automatically, there is something wrong. Here is my code:

while (1)
{
////////////////////////////////////////////////////////////////////////////////
//When I execute the following part step by step, it is just OK
//But when I run the project automatically, there is someting wrong
    for (i=0; i<3; i++){
        cap = cvCaptureFromCAM(i);
        cvGrabFrame(cap);
        cam = cvRetrieveFrame(cap);
        cvCopy(cam, ImageBuffer[i]);
        cvReleaseCapture(&cap);
    }
///////////////////////////////////////////////////////////////////////////////
    cvGetCols(pairs, &part, 0, 640);                    
    cvCopy(ImageBuffer[0], &part);
    cvGetCols(pairs, &part, 640, 640*2);
    cvCopy(ImageBuffer[1], &part);
    cvGetCols(pairs, &part, 640*2, 640*3);
    cvCopy(ImageBuffer[2], &part);
    cvShowImage("Pairs", pairs);

    if(27==cvWaitKey(10))
        break;
}

When I run the project, the error is like that: image description

So, what is wrong with my code? Can anyone could solve the problem? Thanks In Advance!