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...
here is the code
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" );
}
please help
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.
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.
You can also use cvGetCaptureProperty(CV_CAP_PROP_FPS ) to ask the camera what frame rate it is generating frames at then use 1000/fps instead of 33 in the delay loop.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With