建立一个display_video目录,源文件为display_video.cpp,所有CMakeLists.txt为:
project(display_video)
find_package(OpenCV REQUIRED)
add_executable(display_video display_video)
target_link_libraries(display_video ${OpenCV_LIBS})
display_video.cpp的内容为:
#include "highgui.h"
#include "cv.h"
using namespace cv;
int main(int argc, char **argv)
{
cvNamedWindow("Example2", CV_WINDOW_AUTOSIZE);
CvCapture *capture = cvCreateFileCapture(argv[1]);
IplImage *frame;
while(1)
{
frame = cvQueryFrame(capture);
if (!frame)break;
cvShowImage("Example2", frame);
char c = cvWaitKey(33);
if (c==27)break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example2");
}
编译,运行,便可以播放AVI视频,但帧率是固定的,不完整,以后再修改。