지연없이 부드럽게 25fps의 비디오 파일을 표시하려고합니다. 아래의 코드는이 작업을 수행하지만 약 10fps 만 수행하며 약 0.1ms의 시간이 소요됩니다. cvWaitKey (1)를 사용하면 0.03에서 0.04ms 정도가 될 것입니다. 완벽 할 수 있지만 명명 된 창이 회색으로 유지되고 비디오가 표시되지 않습니다!cvShowImage()를 사용한 비디오 디스플레이 지연
cvShowImage()가 너무 느리기 때문에이게 맞습니까? 코드 속도를 높이고 비디오를 원활하게 출력하는 다른 방법이 있습니까?
아래 코드를 참조하십시오.
미리 감사, 당신은 모든 cout을 물건없이이를 시도
#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 the GUI to output the processed images*/
cvNamedWindow("Video input", 0);
/*Open input video*/
if (argc!=2)
{
cout << "Please specify an 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 << i << "\r";
i++;
/*Show image*/
cvShowImage("Video input", input);
cvWaitKey(2); //Wait is needed or else we see a grey box
input = cvQueryFrame(vid); //Read next frame from video
end = clock();
cout << (double)(end-start)/CLOCKS_PER_SEC << " s" << endl;
};
/*Release the allocated memory for the frames */
cvReleaseImage(&input);
cvDestroyWindow("Video input");
return 1;
}
예를 많이! Btw, 나는 Microsoft STL을 사용하지 않고 g ++을 사용합니다. cvWaitKey (1)을 사용할 수없는 이유가 누구에게 있습니까? – Adrian
당신은 할 수 ... 나는 방금 작업 한 프로그램에서 그랬다. –
확실히 나를 위해 작동하지 않습니다, 난 그냥 cvWaitKey (1) 사용할 때 회색 화면이 나타납니다. 나는이 특정 빌드와 함께 sth해야한다고 생각한다. – Adrian