imshow() "speed upping" cap >> img; [closed]

asked 2014-12-03 18:52:21 -0600

Hello guys, here is the strange stuff i found, calling imshow() and waitKey() functions after a cap >> img; in a loop can speedup the grabbing by halving the time (in my webcam from ~80ms to 40~ms), can someone explain my what's going on? There is a way for having a "fast" grabbing without the imshow()? Here's the code snippet (need C++11 and #include <chrono>):

     VideoCapture capture(0);
 capture.set(CV_CAP_PROP_FRAME_WIDTH, 640);
 capture.set(CV_CAP_PROP_FRAME_HEIGHT, 360);
 capture.set(CV_CAP_PROP_FPS, 30);
 cout << "Failed to connect to the camera." << endl;

 Mat frame;
 int i = 60;


 auto t1 = chrono::high_resolution_clock::now();
 capture >> frame;
 auto t2 = chrono::high_resolution_clock::now();

 cout << "grabbing ms: " << chrono::duration_cast<std::chrono::milliseconds>(t2-t1).count() << endl;

 //COMMENT imshow() and see the capture >> frame; taking twice the time

 i--; cout << i << endl;
     if(waitKey(32) == 27 || i < 0){
     return 0;
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by sturkmen
close date 2020-09-27 11:52:07.064425


I do not get it: you are timing just the capture &gt;&gt; frame and you are saying that if you use imshow and waitKey it is faster than when you do not use them? Then certainly there is something wrong

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-12-05 02:42:34 -0600 )edit