使用 OpenCV 从 .avi 视频获取帧
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv)
{
CvCapture* capture=0;
IplImage* frame=0;
capture = cvCaptureFromAVI("C:\\boy walking back.avi"); // read AVI video
if( !capture )
throw "Error when reading steam_avi";
cvNamedWindow( "w", 1);
for( ; ; )
{
/* int cvGrabFrame (CvCapture* capture);
IplImage* cvRetrieveFrame (CvCapture* capture)*/
frame = cvQueryFrame( capture );
if(!frame)
break;
cvShowImage("w", frame);
}
cvWaitKey(0); // key press to close window
cvDestroyWindow("w");
cvReleaseImage(&frame);
}
我正在使用 openCV 和 VS2008。我读入了一个视频文件并使用 CV_CAP_PROP_FRAME_COUNT 来获取 4 秒长的视频剪辑的帧数,该帧数约为 130。我正在进行步行的运动识别,因此我需要每隔 5 帧获取一次,因为在 5 帧之间,身体的运动几乎没有变化。到目前为止,我有一个程序可以让我获取视频剪辑的一帧。但是,我无法获取不同的帧,而且我不知道如何每隔 5 帧获取一次。上面是用于获取视频一帧的代码。
#include "cv.h"
#include "highgui.h"
int main(int argc, char** argv)
{
CvCapture* capture=0;
IplImage* frame=0;
capture = cvCaptureFromAVI("C:\\boy walking back.avi"); // read AVI video
if( !capture )
throw "Error when reading steam_avi";
cvNamedWindow( "w", 1);
for( ; ; )
{
/* int cvGrabFrame (CvCapture* capture);
IplImage* cvRetrieveFrame (CvCapture* capture)*/
frame = cvQueryFrame( capture );
if(!frame)
break;
cvShowImage("w", frame);
}
cvWaitKey(0); // key press to close window
cvDestroyWindow("w");
cvReleaseImage(&frame);
}
I am using openCV with VS2008. I have read in a video file and used CV_CAP_PROP_FRAME_COUNT to obtain the number of frames which was approximately 130 for a 4 second long video clip. I am doing a motion recognition of walking so I need to get every other 5 frames since between 5 frames, there is little change in the motion of the body. I have a program so far which allows me to obtain one frame of the video clip. However, I am unable to obtain different frames and also, I am not sure how to go about getting every other 5 frames. The above is the code used to get one frame of the video.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够跳过 4 帧,然后保留第 5 帧。下面是我写的一个小例子来演示这一点:
希望有帮助:)
You should be able to skip 4 frames, and then keep the 5th frame. Below is a small example I wrote to demonstrate this:
Hope that helps :)