Ask Your Question

Harber's profile - activity

2017-01-09 12:05:13 -0500 commented question Capture problem in thread

Yeah. My system has Octa-core(exynos 5422 / octa-core) cpu. So I can't understand this problem. Also I got it understand your mind. never mind. Thanks.

2017-01-09 11:56:28 -0500 commented question Capture problem in thread

Thanks for reply. But it is same problem even if I use a VideoCapture class. Do you know why is it?

2017-01-09 11:48:59 -0500 received badge  Editor (source)
2017-01-09 11:24:02 -0500 asked a question Capture problem in thread

Hi.

I'm try to capture a frame from webcam with parallel work in another thread.

When I capture a frame without another thread, capture function works at 50~60fps.

But, work with another thread even just while loop, capture function work at 20~30fps.

Below is a code.


using namespace std;    
using namespace cv;    

int k = 0;

IplImage* image = 0;    
CvCapture* capture = cvCaptureFromCAM(0);

int Thrr()    
{           
    while (!k)    
    {
        ;    
    }    
}


int main(int argc, char** argv)    
{

    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 1280);
    cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 720);

    thread th1(Thrr);

    while (1)
    {

        for (int i = 0; i < 300; i++)
        {
            clock_t aaa = clock();
            cvGrabFrame(capture);
            clock_t ss = clock();
            image = cvRetrieveFrame(capture);
            printf("%d ", i);
            printf("a12 frame : %f\n", double(CLOCKS_PER_SEC) / double(clock() - aaa));

        }
        k = 1;
    }


    return 0;

}

image description

Like above image you can see, when it capture a frame with another thread in first for loop, it works at 25fps.

But after first for loop, Thrr() thread end(k = 1, it means Thrr() while(!k) loop end), capture function works at 55fps.

Didn't any of you know why it is and how can I do for this problem.

Thanks.