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

本文提供了一个使用OpenCV将彩色视频转换为灰度视频的示例代码。该程序通过加载视频文件,逐帧进行颜色空间转换,并保存为新的灰度视频。文中详细介绍了如何初始化视频读取、设置输出参数及视频写入过程。
// 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值