本文基于VS2013和opencv所写
这里写代码片#include<iostream>
#include"opencv2/imgproc/imgproc.hpp"
#include"opencv2/highgui/highgui.hpp"
using namespace cv;
using namespace std;
/*int main()
{
VideoCapture capture("fighting.avi");
VideoWriter Writer;
Writer.open("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), 25.0, Size(640, 480), 1);
if (!capture.isOpened())
cout << "failed!" << endl;
//long totalframe = capture.get(CV_CAP_PROP_FRAME_COUNT);
//cout << "总共的帧数:"<<totalframe<< endl;
//bool stop = false;
Mat frame;
while (capture.read(frame))
{
//capture >> frame;
//cout << "failed!!" << endl;
imshow("showing", frame);
Writer << frame;
waitKey(1);
}
return 0;
}*/
void main()
{
VideoCapture capture("fighting.avi");
VideoWriter writer;
double rate = capture.get(CV_CAP_PROP_FPS);//帧率
Size videoSize(capture.get(CV_CAP_PROP_FRAME_WIDTH), capture.get(CV_CAP_PROP_FRAME_HEIGHT));//视频的宽和高
writer.open("test.avi", CV_FOURCC('M', 'J', 'P', 'G'), rate, videoSize,0);//1默认保存彩色图,0则不默认
Mat frame,gray;
//while (capture.isOpened())
// {
// capture >> frame;
while (capture.read(frame))
{
Mat gray;
cvtColor(frame, gray, CV_RGB2GRAY);
writer<<gray;
imshow("video", frame);
imshow("gray", gray);
waitKey(20);
}
}
同样的颜色转换可以依照灰度变化来做。