OpenCV,捕获的视频运行速度比原来的摄像机视频! [英] OpenCV, captured video runs faster than original camera video!

查看:1649
本文介绍了OpenCV,捕获的视频运行速度比原来的摄像机视频!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用openCV从相机捕获视频,并存储到和avi文件,问题是,当我完成捕获和运行avi文件,视频流看起来尴尬快... ...

I am using openCV to capture video from camera and store to and avi file, the problem is that when i finish capturing and run the avi file, the video stream looks awkwardly fast...

这里是代码

void main( )
{
CvCapture *capture = cvCaptureFromCAM( 0 );

int width = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH );
int height = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT );
CvVideoWriter *writer = cvCreateVideoWriter( "myCamCapture.avi",
-1,30, cvSize(  width, height ) );
cvNamedWindow("d", CV_WINDOW_AUTOSIZE);
IplImage *frame = 0;


while( 1 )
{
    frame = cvQueryFrame( capture );

    cvShowImage("d",frame);
    cvWriteFrame( writer, frame );
    char c = cvWaitKey( 33 );
    if( c == 27 ) break;
}

cvReleaseCapture( &capture );
cvReleaseVideoWriter( &writer );
cvDestroyWindow( "d" );


    }

请帮助

推荐答案

你告诉作家它应该以每秒30帧的速度播放。所以,如果你实际捕获,说,15帧每秒,这些帧将要回放比实时更快。

You're telling the writer that it should play at 30 frames per second. So if you're actually capturing, say, 15 frames per second, those frames are going to be played back faster than than real time.

显示捕获的图像,等待按键,并将其写入文件都需要时间。你需要考虑到这一点。您可以尝试先捕获视频,在发生时测量实际的FPS,然后使用该值写入AVI。

Showing the captured image, waiting for a keypress, and writing it to the file all take time. You need to account for that. You might try capturing the video up-front, measuring the actual FPS while it happens, and then writing your AVI using that value.

这篇关于OpenCV,捕获的视频运行速度比原来的摄像机视频!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆