Click here to Skip to main content
15,886,519 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi everyone,
I'm writing a program that needs to capture from a webcam using opencv. I am using a Logitech C260 Camera and OpenCV2.2, Windows XP, QT Creator. Here is an example piece of my code:

int i = 0;
int arg = 0;
CvCapture *pCapturedImage = cvCaptureFromCAM(arg);
cvNamedWindow( "Example1", CV_WINDOW_AUTOSIZE );
IplImage* img1= cvQueryFrame(pCapturedImage);
IplImage* img2;
IplImage* merged;
int MAX_FRAMES = 10;
    for (int i = 0; i < MAX_FRAMES; i++){
    pCapturedImage = cvCaptureFromCAM(arg);
    if (!pCapturedImage){
        printf("Uh oh");
    }
    img1 = cvQueryFrame(pCapturedImage);
    printf("Query");
    cvShowImage( "Example1", img1 );
    cvWaitKey(0);
}
for (int i = 0; i < MAX_FRAMES; i++){
    printf("Enter");
    img2 = img1;
    pCapturedImage = cvCaptureFromCAM(arg);
    if (!pCapturedImage){
        printf("Uh oh");
    }else
    printf("Capture");
    img1 = cvQueryFrame(pCapturedImage);
    printf("Query");
    cvShowImage( "Example1", img1 );
    cvWaitKey(0);
    img1 = mergePhotos(img2, img1, i*25, i*25);
    printf("Merge");
    cvShowImage( "Example1", img1 );
    cvWaitKey(0);
}

It's not working though. I'm getting only a for around the first 10 captures, then after that, the capture becomes null. I'll try to add a picture.

I'm stumped. I've tried cvCaptureFromCAM and cvCreateCameraCapture. I've tried changing the args to that function. I've tried all my USB ports.
Does anybody know what the problem might be? I greatly appreciate all help.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900