Understanding camera capture rate using opencv

1.8k Views Asked by At

This is probably an open-ended question. I have written an opencv application that captures feed from two external cameras connected to the computer. The capture from both the cameras runs parallely on 2 different threads. This recorder module writes the frames to a video file which is later processed. The following code sits inside each thread function:

    CvCapture *capture =cvCaptureFromCAM(indexOfCamera);
    if(!capture) return;

    CvSize sz =cvGetSize(cvQueryFrame(capture));
    cvNamedWindow("src");
    CvVideoWriter *writer =cvCreateVideoWriter((char*) p, CV_FOURCC('L','A','G','S'), 20, sz);
     if( !writer ) {
        cvReleaseCapture( &capture );
        return;
    }
     IplImage *frame;
     int frameCounter =0;
     while(true){
        QueryPerformanceCounter(&sideCamCounter);
        frame =cvQueryFrame(capture);
        if(!frame)break;
        //Store timestamp of frame somewhere
        cvShowImage("src", frame);
        cvWriteFrame(writer, frame);

        int c=cvWaitKey(1);
        if((char)c ==27)break;
        ++frameCounter;
     }
    cvReleaseVideoWriter(&writer);
    cvReleaseCapture(&capture);
    cvDestroyAllWindows();

The two cameras I am using are: A - Microsoft hd-6000 lifecam for notebooks and B - Logitech sphere AF webcam. Camera A captures at around 16-20 fps(reaches upto 30 fps during a few recordings) and camera B captures at around 10-12 fps.

I need a faster capture rate to be able to capture real-time motion. I understand I will be limited by the camera's capture speed/rate but apart from that, what other factors will affect the capture rate - e.g. load on the system(Memory and CPU), the API's used ? I am open to explore options. Thanks.

1

There are 1 best solutions below

1
On
  1. Try to set different camera properties - http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#videocapture-set, probably the most interesting for you will be... FPS :) Note that it's not always working fine ( How to set camera FPS in OpenCV? CV_CAP_PROP_FPS is a fake ), but give it a chance, maybe it will help you. Also you may try to set smaller image resolution.

  2. If you don't have to - don't display image.

  3. You may try to grab frames in one thread and process in another.
  4. Connect cameras directly to your computer - don't use USB hub.
  5. the API's used

I don't think it will help, but if you want you may try to use different API - OpenCV on Mac is not opening USB web camera