原文写于2013年3月22日
写入原始视频可以正常保存,现在frame经过灰度化处理之后想保存视频,但是不知怎地就是无法保存,难道cvWriteFrame只支持3通道的image保存吗?等待解决...
#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
int main( ) {
CvCapture* capture = cvCaptureFromFile( "E:\\test.avi" );
if (!capture)
{printf("unable to load a video");
cvWaitKey(0);
exit(0);
}
cvNamedWindow("haha", 1);
IplImage* frame;
double fps = cvGetCaptureProperty (
capture,
CV_CAP_PROP_FPS);
printf("fps=%d n",(int)fps);
/*
Here with the help cvGetCaptureproperty we are trying to acquire the widht and height of the video… and store it in CvSize structure….Please do not get overwhelmed…
treat CvSize structure as a normal easy to understand structure and read on…
*/
CvSize size = cvSize((int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_WIDTH),
(int)cvGetCaptureProperty( capture, CV_CAP_PROP_FRAME_HEIGHT)
);
printf("frame (w, h) = (%d, %d)n",size.width,size.height);
/*Creating the Video writer If you do not know about the Video writer study this post and come back to tis line*/
CvVideoWriter *writer = cvCreateVideoWriter(
"partofvideo.avi",/*filename*/
CV_FOURCC('X','V','I','D'), /*codec type*/
fps,
size,
1
);
IplImage* gray_frame = cvCreateImage(size, IPL_DEPTH_8U, 1);
int counter=0;
while( (frame=cvQueryFrame(capture)) != NULL ) {
counter++;
/*discard all the frames before a certain time and accept the frames in a certain time period and write the frames in the new video*/
cvConvertImage(frame, gray_frame, 0);
printf("entered\n");
cvWriteFrame( writer, gray_frame );
cvShowImage("haha", gray_frame);
if((cvWaitKey(100)) == 27)
break;
}
cvReleaseImage(&frame);
cvReleaseImage(&gray_frame);
cvReleaseVideoWriter( &writer );
cvReleaseCapture( &capture );
cvDestroyWindow("haha");
return 0;
}
在2013年的3月22日,博主遇到了使用OpenCV进行视频处理的一个问题。当将原始视频帧转换为灰度图像后尝试保存视频时,发现无法成功保存。疑问是否OpenCV的cvWriteFrame函数仅支持3通道图像的保存。这个问题有待进一步解决。
1618

被折叠的 条评论
为什么被折叠?



