[openCV]视频的读入与一些简单的图像处理

1.序言

作为一个计算机图像处理的工具,因为免费公开呀,版权等等的原因,openCV开始展现出一些无可取代的优势(已经展露好久了好吧)。嘛,之前我研究生阶段,一直再用MATLAB在干活,总感觉调试呀,验证啊,还是MATLAB要好用一些呢!不久前,自己也开始接触了openCV,总感觉虽然都是工具,但是水很深的样子。嘛,总是还是开个关于openCV的坑,记录下自己的学习的轨迹吧。

自带吐槽1:基础的图像处理部分的坑,还有一些没有整理完,等过几天开始整理完后,再开始填坑吧,不算烂尾不算烂尾(= =!!自我催眠)

自带吐槽2:不过话说也没谁真的在等着看吧(= = 好桑心!)

2.视频的读入与图像的显示

2.1从AVI文件中读取图像

对于图像处理来说,最开始的实验代码,基本都是从读取一幅图像,然后将其显示出来开始入手的。这是图像处理的“Hello World!”。openCV里将一枚图像读入,并显示的代码如下所示。

<code class="hljs cs has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;">IplImage* ori= cvLoadImage(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"..\\Data\\Fig0320(4) (bottom_left).tif"</span>,Gray_image);
cvNamedWindow(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Original"</span>, CV_WINDOW_AUTOSIZE );   <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//new window</span>
cvShowImage(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Original"</span>,ori);        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//show</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li></ul>

其实也就相当于MATLAB里面的imread()imshow()figure()这三个函数;这里值得说的是,如果要让窗口内图片跟着窗口一起扩大的话,可以使用式样CV_WINDOW_NORMAL,也就是如下代码所示。

<code class="hljs scss has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-top-left-radius: 0px; border-top-right-radius: 0px; border-bottom-right-radius: 0px; border-bottom-left-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-function" style="box-sizing: border-box;">cvNamedWindow(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Original"</span>, CV_WINDOW_NORMAL )</span>;   <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//new window</span>
<span class="hljs-function" style="box-sizing: border-box;">cvShowImage(<span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"Original"</span>,ori)</span>;        <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//show</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>

对于视频的读入,其实和图像是差不多一样的,使用函数

cvCreateFileCapture(argv[1])去读入一段视频。然后通过函数cvQueryFrame(capture)将其一帧一帧的取出来,然后再用显示图像的方式(cvShowImage()),将其按照一定的时间间隔,逐帧显示出来。

http://www.v1bo.com/110695260

http://www.v1bo.com/110695359

http://www.v1bo.com/110695176

http://www.v1bo.com/110695096

http://www.v1bo.com/110695179

http://www.v1bo.com/110695366

http://www.v1bo.com/110694876

http://www.v1bo.com/110695367

http://www.v1bo.com/110694877

http://www.v1bo.com/110694991

http://www.v1bo.com/110695186

http://www.v1bo.com/110694883

http://www.v1bo.com/110694884

http://www.v1bo.com/110694992

http://www.v1bo.com/110695376

http://www.v1bo.com/110694994

http://www.v1bo.com/110695377

http://www.v1bo.com/110695378

http://www.v1bo.com/110694998

http://www.v1bo.com/110694999

http://www.v1bo.com/110695380

http://www.v1bo.com/110695194

http://www.v1bo.com/110695290

http://www.v1bo.com/110695291

http://www.v1bo.com/110695199

http://www.v1bo.com/110695802

http://www.v1bo.com/110695385

http://www.v1bo.com/110695807

http://www.v1bo.com/110695408

http://www.v1bo.com/110695409

http://www.v1bo.com/110695295

http://www.v1bo.com/110695810

http://www.v1bo.com/110695811

http://www.v1bo.com/110695702

http://www.v1bo.com/110695393

http://www.v1bo.com/110695814

http://www.v1bo.com/110695705

http://www.v1bo.com/110695396

http://www.v1bo.com/110695603

http://www.v1bo.com/110695415

http://www.v1bo.com/110695816

http://www.v1bo.com/110695902

时间: 05-21