c++ - Lagging video display using cvShowImage() -
i'm trying display video file @ 25fps smoothly without lag. code below this, achieves 10fps, taking 0.1ms execute. cvwaitkey(1) around 0.03 0.04ms, perfect, named window stays grey , doesn't show video!
is because cvshowimage() slow? there other way speed code , output video smoothly?
see code below.
thanks lot in advance,
adrian
#include <cv.h> #include <iostream> #include <highgui.h> #include <cxcore.h> #include <cvaux.h> #include <sstream> #include <time.h> using namespace std; using namespace cv; int main(int argc, char** argv) { cvcapture* vid = 0; iplimage* input; //input image int fps; int i=0; clock_t start, end; /*creates gui output processed images*/ cvnamedwindow("video input", 0); /*open input video*/ if (argc!=2) { cout << "please specify input video." << endl; return -1; } else { vid=cvcreatefilecapture(argv[1]); if (!vid) { cout << "could not extract frame." << endl; return -1; } } input = cvqueryframe(vid); fps = (int)cvgetcaptureproperty(vid, cv_cap_prop_fps); cout << fps << endl; cout << "video found." << endl; /*extraction loop */ while (input) { start = clock(); cout << flush; cout << << "\r"; i++; /*show image*/ cvshowimage("video input", input); cvwaitkey(2); //wait needed or else see grey box input = cvqueryframe(vid); //read next frame video end = clock(); cout << (double)(end-start)/clocks_per_sec << " s" << endl; }; /*release allocated memory frames */ cvreleaseimage(&input); cvdestroywindow("video input"); return 1; }
have tried without cout stuff?
the debug build of microsoft stl has cout handling unbelievably slow.
Comments
Post a Comment