Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows QT
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 3-Mar-11 7:54am

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

  Print Answers RSS
0 OriginalGriff 8,149
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 3 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100