Click here to Skip to main content
11,576,354 members (62,633 online)
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 6:54am

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 251
1 Abhinav S 135
2 Lucifier Rocks 105
3 Dave Kreskowiak 80
4 F-ES Sitecore 80
0 OriginalGriff 705
1 Sergey Alexandrovich Kryukov 626
2 Abhinav S 483
3 F-ES Sitecore 410
4 Suvendu Shekhar Giri 365


Advertise | Privacy | Mobile
Web04 | 2.8.150603.1 | Last Updated 3 Mar 2011
Copyright © CodeProject, 1999-2015
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