Ask Your Question
0

cvWaitKey() slows down capture/display process

asked 2013-09-09 10:50:38 -0600

refuzee gravatar image

Hi,

I am using openCV to capture, display and save frames from ps3 eye camera. with 640x480 i could get 60fps but turns out that i only get about 16 when trying to display and save images at the same time. so i measured a bit and the main contributor to this slow process is cvWaitKey(). Is there any workaround ? here is the code for my loop:

// image capturing loop
    while(_running)
    {
        //activate cvWaitKey - this drops framerate significantly!
        cvWaitKey(1);

        //get frame from capture and put into buffer
        CLEyeCameraGetFrame(_cam, pCapBuffer);

        //get system timestamps 
        GetSystemTime(&st);
        GetLocalTime(&lt);

        // Resize image to fit screen size
        cvResize(pCapImage,resizedpCapImage,CV_INTER_NN);

        //display image
        cvShowImage(_windowName, resizedpCapImage);

        //clear string
        sstm.str(std::string());

        //complete filname      
        sstm << _folder << prefix << _participant << std::setfill('0') << std::setw(10) << i  << "-" << st.wHour << st.wMinute << st.wSecond <<  st.wMilliseconds << suffix;
        image_name = sstm.str();
        c = image_name.c_str();


        //log if enabled
        if (_logging){
            //try to save image
            try {
                cvSaveImage(c, pCapImage); //bmp = speed!
            }
            catch (runtime_error& ex) {
                fprintf(stderr, "Exception converting image to bmp format: %s\n", ex.what());
            }
        }
    }
edit retag flag offensive close merge delete

Comments

Why do you use waitkey anyways?

Moster gravatar imageMoster ( 2013-09-09 10:56:32 -0600 )edit

to update my display ?

refuzee gravatar imagerefuzee ( 2013-09-09 11:08:56 -0600 )edit

Ah right :P Im used to do stuff with android. You dont need the waitkey there. Anyways, try to switch over to the new c++ style. C is deprecated.

Moster gravatar imageMoster ( 2013-09-09 12:06:46 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-09-09 13:11:06 -0600

xaffeine gravatar image

Perhaps the easiest workaround would be to call waitKey less often. If you do it only every 4th or 5th frame, you should get back to your good frame rate.

Less easy would be to avoid calling waitKey and replace your ShowImage calls with something that draws without relying on the HighGui event loop.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-09-09 10:50:38 -0600

Seen: 1,249 times

Last updated: Sep 09 '13