资源简介
在做《学习opencv》例2-10时,发现书中源码有些问题,经过我的修改,该代码可以将彩色视频完美输出和保存为灰度格式和极坐标格式的视频,并且解决了很多朋友存在的灰度视频输出是以翻转形式输出的问题,代码有我的详细注解,很容易理解和掌握。

代码片段和文件信息
// Eg2.10.cpp : 定义控制台应用程序的入口点。
//
#include “stdafx.h“
/* License:
Oct. 3 2008
Right to use this code in any way you want without warrenty support or any guarentee of it working.
BOOK: It would be nice if you cited it:
Learning OpenCV: Computer Vision with the OpenCV Library
by Gary Bradski and Adrian Kaehler
Published by O‘Reilly Media October 3 2008
AVAILABLE AT:
http://www.amazon.com/Learning-OpenCV-Computer-Vision-Library/dp/0596516134
Or: http://oreilly.com/catalog/9780596516130/
ISBN-10: 0596516134 or: ISBN-13: 978-0596516130
OTHER OPENCV SITES:
* The source code is on sourceforge at:
http://sourceforge.net/projects/opencvlibrary/
* The OpenCV wiki page (As of Oct 1 2008 this is down for changing over servers but should come back):
http://opencvlibrary.sourceforge.net/
* An active user group is at:
http://tech.groups.yahoo.com/group/OpenCV/
* The minutes of weekly OpenCV development meetings are at:
http://pr.willowgarage.com/wiki/OpenCV
*/
#include “cv.h“
#include “highgui.h“
#include
// Convert a video to grayscale
// argv[1]: input video file
// argv[2]: name of new output file
//
//#define NOWRITE 1; //Turn this on (removed the first comment out “//“ if you can‘t write on linux
int main( int argc char* argv[] ) {
cvNamedWindow( “Example2_10“ CV_WINDOW_AUTOSIZE );
cvNamedWindow( “Log_Polar“ CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( “D:\\sample.avi“ );//地址输入你的视频地址
if (!capture){
return -1;
}
IplImage* bgr_frame;
double fps = cvGetCaptureProperty (
capture
CV_CAP_PROP_FPS
);
printf(“fps=%d\n“(int)fps);
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.widthsize.height);
//#ifndef NOWRITE
CvVideoWriter* writer = cvCreateVideoWriter( // 建立第一个写入视频的容器
“D:\\sample3.avi“ //地址输入一个你想把灰度视频输出到的位置
CV_FOURCC(‘M‘‘J‘‘P‘‘G‘)
fps
size
0 //0表示写入的是灰度图像
);
CvVideoWriter* writer2 = cvCreateVideoWriter( // 建立第二个写入视频的容器
“D:\\sample4.avi“ //地址输入一个你想把极坐标视频输出到的位置
CV_FOURCC(‘M‘‘J‘‘P‘‘G‘)
fps
size
1 //1表示写入的是彩色图像
);
//#endif
IplImage* logpolar_frame = cvCreateImage(
size
IPL_DEPTH_8U
3
);
IplImage* gray_frame = cvCreateImage(
size
IPL_DEPTH_8U
1
);
while( (bgr_frame=cvQueryframe(capture)) != NULL ) {
cvShowImage( “Example2_10“ bgr_frame );
cvCvtColor( bgr_frame gray_frame CV_RGB2GRAY );//每帧都变成灰度图
cvLogPolar( bgr_frame logpolar_frame //This is just a fun conversion the mimic‘s the human visual system
cvPoint2D32f(bgr_
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 65024 2014-12-04 18:49 Eg2.10\Debug\Eg2.10.exe
文件 788676 2014-12-04 18:49 Eg2.10\Debug\Eg2.10.ilk
文件 1813504 2014-12-04 18:49 Eg2.10\Debug\Eg2.10.pdb
文件 1522 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\cl.command.1.tlog
文件 22702 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\CL.read.1.tlog
文件 832 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\CL.write.1.tlog
文件 77 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\Eg2.10.lastbuildstate
文件 1949 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\Eg2.10.log
文件 254354 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\Eg2.10.obj
文件 1245184 2014-12-04 16:09 Eg2.10\Eg2.10\Debug\Eg2.10.pch
文件 2 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\li
文件 2 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\li
文件 2 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\li
文件 2 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\li
文件 2174 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\li
文件 5372 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\li
文件 570 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\li
文件 11717 2014-12-04 16:09 Eg2.10\Eg2.10\Debug\stdafx.obj
文件 674816 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\vc110.idb
文件 1363968 2014-12-04 18:49 Eg2.10\Eg2.10\Debug\vc110.pdb
文件 3949 2014-12-04 18:49 Eg2.10\Eg2.10\Eg2.10.cpp
文件 4543 2014-12-04 16:09 Eg2.10\Eg2.10\Eg2.10.vcxproj
文件 1310 2014-12-04 16:07 Eg2.10\Eg2.10\Eg2.10.vcxproj.filters
文件 1503 2014-12-04 16:07 Eg2.10\Eg2.10\ReadMe.txt
文件 211 2014-12-04 16:07 Eg2.10\Eg2.10\stdafx.cpp
文件 233 2014-12-04 16:07 Eg2.10\Eg2.10\stdafx.h
文件 236 2014-12-04 16:07 Eg2.10\Eg2.10\targetver.h
文件 15728640 2014-12-04 18:50 Eg2.10\Eg2.10.sdf
文件 885 2014-12-04 16:07 Eg2.10\Eg2.10.sln
..A..H. 25600 2014-12-04 18:50 Eg2.10\Eg2.10.v11.suo
............此处省略10个文件信息
- 上一篇:B码对时资料
- 下一篇:相关分析和谱分析的工程应用
相关资源
- 基于OpenCV的数字识别468815
- 使用opencv去掉二值化图像中黑色面积
- opencv环境配置
- win10 64位下编译的opencv4.5.5库,opencv
- NVIDIAOpticalFlowSDK-79c6cee80a2df9a196f20afd6
- opencv_contrib-3.4.0.zip
- opencv2.4.9源码分析——SIFT
- 用两个摄像头实现,双目标定,双目
- opencv_traincascade训练分类器,手势识别
- opencv3.0交叉编译用parallel.cpp
- 基于opencv的图像识别识别图像中的色
- 基于openCV的识别特定颜色区域
- 基于OpenCV的分水岭算法实现
- QT+opencv+OCR 身份证号码,银行卡号识别
- opencv视频特定颜色区域识别
- 把RGB转换为HSV和HSI然后根据黄色和蓝
- opencv视觉测距
- 基于Qt和opencv的身份证号码识别系统
- opencv_ffmpeg249.dll
- SfM稀疏三维点云重建--完整工程文件
- 基于opencv的数人头程序源代码
- 利用OpenCV中的Stitcher类实现全景图像拼
- opencv实现的sift算法源码,包含了图像
- openCV 上的小波变换
- 基于OPENCV的车牌识别系统设计
- 617张国内车牌60-17bmp图片用于OpenCV正样
- hog特征提取,c版本代码
- 基于Qt5.8+OpenCV3.2的Basler多相机触发开
- 基于Opencv实现的图像纠偏
- ImageWatch2019.vsix
评论
共有 条评论