OpenCV Learning: 第2章视频写入遇到的问题
2013-10-31 10:27
411 查看
原文写于2013年3月22日
写入原始视频可以正常保存,现在frame经过灰度化处理之后想保存视频,但是不知怎地就是无法保存,难道cvWriteFrame只支持3通道的image保存吗?等待解决...
写入原始视频可以正常保存,现在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; }
相关文章推荐
- OpenCV Trackbar 实现播放视频代码遇到的问题 cvQueryFrame cvCreateFileCapture cvCreateTrackbar cvSetTrackbarPos
- 使用opencv_python进行视频分析遇到的bgsegm问题
- 关于OpenCV不能读取视频和写入视频的问题
- Learning_Opencv(一)使用摄像头录制视频并逐帧写入文件
- Itunes connect上传应用视频 app preview时遇到“无法载入文件”的问题
- NET视频学习笔记 新手入门 可能遇到的问题
- OpenCV-Python learning-2.视频、相机简单处理
- sudo apt-get install libopencv-dev 遇到ppa获取错误的问题
- 编译OpenCV遇到Qmake问题
- [置顶] Windows下利用Cmake编译OpenCV3.2.0 遇到ipipcv问题解决
- jsp+mysql中遇到中文写入数据库乱码问题
- opencv 写视频时找不到编码器问题解决方法
- OpenCV读视频文件和运动问题检测
- cuda8.0配置opencv2.4.9可能遇到的两个问题
- 【Opencv笔记】利用VideoCapture和VideoWriter函数读取和写入视频文件
- 1.1-学习Opencv与MFC混合编程之---利用画图函数,生成视频,并写入视频文件
- 使用opencv_traincascade训练遇到的问题总汇
- python+Opencv视频读取问题+官网光流法示例程序报错问题解决
- 【opencv + Directshow + VC2005】视频采集中遇到的问题
- 针对MATLAB(imfilter)翻译C语言(opencv)遇到的问题