Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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()

{

int a = 0;

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.

click to hide/show revision 2
No.2 Revision

updated 2017-01-09 11:24:44 -0600

berak gravatar image

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;

std; using namespace cv;

cv; int k = 0;

0; IplImage* image = 0;

0; CvCapture* capture = cvCaptureFromCAM(0);

cvCaptureFromCAM(0); int Thrr()

{

Thrr() { int a = 0;

0;
while (!k)
 {
 ;
 }

}

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

{

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.

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;
std;    
using namespace cv;
cv;    

int k = 0;

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

int Thrr()

Thrr()    
{           
    while (!k)    
    {

int a = 0;

    while (!k)

    {

        ;

    }
        ;    
    }    
}


int main(int argc, char** argv)
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.

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.