#include<opencv2\opencv.hpp>
#include<highgui.h>
#include <string.h>
#include <iostream>
#include "cv.h"
using namespace cv;
using namespace std;
/*
@brief:读入一个完整的程序来实现读入一个彩色视频文件,并且以灰度格式 输出这个文件
< Convert a video to grayscale/>
@author:ZJL
@date:2019-5-11
@reference:<<opencv chinese>>
*/
int main(int argc, char** argv)
{
CvCapture *capture = 0;
capture = cvCreateFileCapture("car.avi");
if (!capture)
{
return -1;
}
IplImage *bgr_frame = cvQueryFrame(capture);
double fps;//定义帧率变量
fps = cvGetCaptureProperty(
capture,
CV_CAP_PROP_FPS
);
CvSize size = cvSize(
(int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT)
);
//视频编码
CvVideoWriter *writer = cvCreateVideoWriter("car1.avi",
CV_FOURCC('M', 'J', 'P', 'G'),
fps,
size
);
IplImage *logpolar_frame = cvCreateImage(
size,
IPL_DEPTH_8U,
3
);//灰度图像
while ((bgr_frame = cvQueryFrame(capture)) != NULL)
{
cvConvertImage(bgr_frame, logpolar_frame, CV_RGB2GRAY);//彩色转换为灰度图像
cvFlip(logpolar_frame, NULL, 0);//翻转图像
cvWriteFrame(writer, logpolar_frame);
}
cvReleaseVideoWriter(&writer);
cvReleaseImage(&logpolar_frame);
cvReleaseCapture(&capture);
}