1 前备知识
null
2 所用到的主要OpenCv Class
VideoCapture capture; capture.open("G:\\CVworkstudy\\program_wwx\\研习社140课时\\ZhaiZhigang140\\vtest.avi");
VideoWriter writer("G:\\CVworkstudy\\program_wwx\\研习社140课时\\ZhaiZhigang140\\test.avi", CV_FOURCC('D', 'I', 'V', 'X'), fps, S, true);
3 程序代码
同OpenCv研习社例程代码
#include#include using namespace cv;using namespace std;int main(int argc, char** argv) { // 打开摄像头 // VideoCapture capture(0); // 打开文件 VideoCapture capture; capture.open("G:\\CVworkstudy\\program_wwx\\研习社140课时\\ZhaiZhigang140\\vtest.avi"); if (!capture.isOpened()) { printf("could not read this video file...\n"); return -1; } Size S = Size((int)capture.get(CV_CAP_PROP_FRAME_WIDTH), (int)capture.get(CV_CAP_PROP_FRAME_HEIGHT)); int fps = capture.get(CV_CAP_PROP_FPS); printf("current fps : %d \n", fps); VideoWriter writer("G:\\CVworkstudy\\program_wwx\\研习社140课时\\ZhaiZhigang140\\test.avi", CV_FOURCC('D', 'I', 'V', 'X'), fps, S, true); Mat frame; namedWindow("camera-demo", CV_WINDOW_AUTOSIZE); while (capture.read(frame)) { imshow("camera-demo", frame); writer.write(frame); char c = waitKey(50); if (c == 27) { break; } } capture.release(); writer.release(); waitKey(0); return 0;}
4 运行结果
display:ignore
5 扩展及注意事项
null