﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-碧海蓝天-文章分类-数字图像处理</title><link>http://www.cppblog.com/meizixiong/category/11095.html</link><description /><language>zh-cn</language><lastBuildDate>Mon, 06 Jul 2009 12:02:18 GMT</lastBuildDate><pubDate>Mon, 06 Jul 2009 12:02:18 GMT</pubDate><ttl>60</ttl><item><title>OPENCV中子图像的获取拷贝以及源代码(转自http://blog.csdn.net/hunnish/)(</title><link>http://www.cppblog.com/meizixiong/articles/89302.html</link><dc:creator>碧云天</dc:creator><author>碧云天</author><pubDate>Sun, 05 Jul 2009 09:30:00 GMT</pubDate><guid>http://www.cppblog.com/meizixiong/articles/89302.html</guid><wfw:comment>http://www.cppblog.com/meizixiong/comments/89302.html</wfw:comment><comments>http://www.cppblog.com/meizixiong/articles/89302.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/meizixiong/comments/commentRss/89302.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/meizixiong/services/trackbacks/89302.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 前段时间在<strong style="COLOR: black; BACKGROUND-COLOR: #ffff66">OPENCV</strong>中做一个小东西，使用到<strong style="COLOR: black; BACKGROUND-COLOR: #a0ffff">子图像</strong>的提取和拷贝，一时间没有找到好的方法，要么直接访问像素进行赋值，要么通过数组来转换，总是感觉别扭，后来终于弄清了一个比较简单的方法，需要利用一下<strong style="COLOR: black; BACKGROUND-COLOR: #ffff66">OPENCV</strong>中的ROI方法，该方法对于任何格式的灰度或者彩色图像均适用<br><br>IplImage* cvGetSubImage(IplImage *image, CvRect roi)<br>{<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> IplImage *result;<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> // 设置 ROI<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> cvSetImageROI(image,roi);<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> // 创建<strong style="COLOR: black; BACKGROUND-COLOR: #a0ffff">子图像</strong><br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> result = cvCreateImage( cvSize(roi.width, roi.height), image-&gt;depth, image-&gt;nChannels );<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> cvCopy(image,result);<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> cvResetImageROI(image);<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> return result;<br>}<!--   -->
<img src ="http://www.cppblog.com/meizixiong/aggbug/89302.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/meizixiong/" target="_blank">碧云天</a> 2009-07-05 17:30 <a href="http://www.cppblog.com/meizixiong/articles/89302.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>opencv图像处理基本操作(转http://imagedsp.blog.sohu.com/96087104.html)(</title><link>http://www.cppblog.com/meizixiong/articles/89301.html</link><dc:creator>碧云天</dc:creator><author>碧云天</author><pubDate>Sun, 05 Jul 2009 09:28:00 GMT</pubDate><guid>http://www.cppblog.com/meizixiong/articles/89301.html</guid><wfw:comment>http://www.cppblog.com/meizixiong/comments/89301.html</wfw:comment><comments>http://www.cppblog.com/meizixiong/articles/89301.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/meizixiong/comments/commentRss/89301.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/meizixiong/services/trackbacks/89301.html</trackback:ping><description><![CDATA[<div class=articleContent id=articleBody>
<div>
<p><strong>1. 矩阵数据类型</strong><br>通用矩阵数据类型：<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> CV_&lt;bit_depth&gt;(S|U|F)C&lt;number_of_channels&gt;<br>其中，S表示带符号整数；<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> U表示无符号整数；<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> F表示浮点数；<br>例如：CV_8UC1　表示8位无符号单通道矩阵；<br>　　　CV_32FC2 表示32位浮点数双通道矩阵；</p>
<p><strong>2. 图像数据类型</strong><br>通用图像数据类型为：<br>　　　IPL_DEPTH_&lt;bit_depth&gt;(S|U|F)<br>如：IPL_DEPTH_8U　表示8位无符号整数图像；<br>　　IPL_DEPTH_32F 表示32位浮点数图像；</p>
<p><strong>3. 分配和释放图像</strong><br><strong>3.1 分配一幅图像</strong><br>　　IpIImage * cvCreateImage(cvSize size, int depth, int channels);<br>其中size可以用cvSize(width, height)得到。<br>depth为像素的单位，包括：<br>IPL_DEPTH_8U<br>IPL_DEPTH_8S<br>IPL_DEPTH_16U<br>IPL_DEPTH_16S<br>IPL_DEPTH_32S<br>IPL_DEPTH_32F<br>IPL_DEPTH_64F<br>channels为每个像素的通道数，可以是1,2,3或4。通道是交叉排列的，一幅彩色<br>图像的通常的排列顺序是：<br>b0&nbsp;<wbr>g0&nbsp;<wbr>r0&nbsp;<wbr>b1&nbsp;<wbr>g1&nbsp;<wbr>r1&nbsp;<wbr>...</p>
<p>例如：分配一个单通道单字节图像的语句是：<br>IpIImage* img1 = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);</p>
<p>分配一个三通道浮点数图像语句是：<br>IpIImage* img2 = cvCreateImage(cvSize(640, 480), IPL_DEPTH_32F, 3);</p>
<p><strong>3.2 释放图像</strong><br>void cvReleaseImage(IpIImage **);</p>
<p><strong>3.3 复制一幅图像<br></strong>IpIImage* cvCloneImage(IpIImage *);<br>如：<br>IpIImage* img1 = cvCreateImage(cvSize(640, 480), IPL_DEPTH_8U, 1);<br>IpIImage* img2;<br>img2 = cvCloneImage(img1);</p>
<p><strong>3.4 设置或得到感兴趣区域ROI</strong><br>void cvSetImageROI(IpIImage* image, cvRect rect);<br>void cvResetImageROI(IpIImage* image);<br>vRect cvGetImageROI(const IpIImage* image);</p>
<p><strong>4. 图像的读写<br>4.1 从文件中获取图像<br></strong>从文件中读取图像可以采用下面的语句：<br>IpIImage* img = 0;<br>img = cvLoadImage(filename);<br>if (!img)<br>&nbsp;<wbr> printf("Could not load image file: %s\n", filename);<br>&nbsp;<wbr><br>默认为读取三通道图像。如果改变设置则采用如下的方式：<br>img = cvLoadImage(filename, flag);<br>当flag &gt; 0时，表示载入图像为3通道彩色图像；<br>当flag = 0时，表示载入图像为单通道灰色图像；<br>当flag &lt; 0时，表示载入图像由文件中的图像通道数决定。</p>
<p><br><strong>5. 图像转换<br>5.1 将灰度图像转换为彩色图像</strong><br>cvConvertImage(src, dst, flags = 0);<br>其中，src表示浮点（单字节）灰度（彩色）图像；<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> dst表示单字节灰度（彩色）图像；<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> flags表示<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> +--- CV_CVTIMG_FLIP,&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> 垂直翻转<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> flags = |<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr> +--- CV_CVTIMG_SWAP_RB, 交换R和B通道<br>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr>&nbsp;<wbr><br><strong>5.2 将彩色图像转换为灰度图像</strong><br>cvCvtColor(cimg, gimg, CV_RGB2GRAY);</p>
<p><strong>5.3 彩色空间的转换</strong><br>cvCvtColor(src, dst, code);<br>其中code为：CV_&lt;X&gt;2&lt;Y&gt;，而&lt;X&gt;,&lt;Y&gt; = RGB, BGR, GRAY, HSV, YCrCb, XYZ, Lab, Luv, HLS。</p>
<p><strong>6. 绘制命令</strong><br>绘图语句为：<br>cvRectangle, cvCircle, cvLine, cvPolyLine, cvFillPoly, cvInitFont, cvPutText。<br></p>
</div>
</div>
<!--   -->
<img src ="http://www.cppblog.com/meizixiong/aggbug/89301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/meizixiong/" target="_blank">碧云天</a> 2009-07-05 17:28 <a href="http://www.cppblog.com/meizixiong/articles/89301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>