您的位置:首页 > 其它

色彩视频文件转换为灰度格式

2013-09-04 15:05 218 查看
// video.cpp : Defines the entry point for the console application.
//convert a video to grayscale
//argv[1]: input video file
//argv[2]: name of new output file

#include <cv.h>
#include <cvaux.h>
#include <highgui.h>

#pragma comment(lib, "ml.lib")
#pragma comment(lib, "cv.lib")
#pragma comment(lib, "cvaux.lib")
#pragma comment(lib, "cvcam.lib")
#pragma comment(lib, "cxcore.lib")
#pragma comment(lib, "cxts.lib")
#pragma comment(lib, "highgui.lib")
#pragma comment(lib, "cvhaartraining.lib")

int main(int argc, char* argv[])
{
	CvCapture* capture = 0;
	capture = cvCreateFileCapture("D:\\clock.avi");
	if(!capture)
	{
		return -1;
	}
	//init the video read
	IplImage* bgr_frame = cvQueryFrame(capture);
	double 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(
		"result.avi",
		CV_FOURCC('M', 'J', 'P', 'G'),
		fps,
		size
		);
	IplImage* logpolar_frame = cvCreateImage(
		size,
		IPL_DEPTH_8U,
		3
		);
	while ((bgr_frame = cvQueryFrame(capture)) != NULL) {
		cvLogPolar(bgr_frame, logpolar_frame,
			cvPoint2D32f(bgr_frame->width/2, bgr_frame->height/2),
			40,
			CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS);
		cvWriteFrame(writer, logpolar_frame);
	}
	cvReleaseVideoWriter(&writer);
	cvReleaseImage(&logpolar_frame);
	cvReleaseCapture(&capture);
	return 0;
}
注:安装了K-Lite codec Pack,可以读文件,"result.avi“文件为0KB.未解决····
http://fileforum.betanews.com/download/KLite-Codec-Pack_Full/1094057842/3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐