⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap08.htm

📁 数字图像处理入门. 一位图像处理高手写的书. 从图像处理的最基础开始,然后慢慢以一些例子做说明,进入图像处理的更高阶段.学习图像处理不可多得的比较朴实的书
💻 HTM
📖 第 1 页 / 共 4 页
字号:

<html>

<!-- Mirrored from www.lgui.net/column/book1/chap08.htm by HTTrack Website Copier/3.x [XR&CO'2005], Mon, 21 Mar 2005 13:20:21 GMT -->
<head>
<meta http-equiv=Content-Type content="text/html; charset=GB2312">
<link rel=Edit-Time-Data href="chap08.files/editdata.html" >
<link rel=OLE-Object-Data href="chap08.files/oledata.mso" >
<title>第8章 图象的检测及模板匹配</title>
<style><!--
.Normal
	{text-align:justify;
	text-justify:inter-ideograph;
	text-indent:0pt;
	line-height:normal;
	font-size:10.5pt;
	font-family:"Times New Roman";}
.a
	{text-align:center;
	text-indent:0pt;
	line-height:20.0pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
-->
</style>
</head>
<body lang=ZH-CN link=blue vlink=purple class="Normal" bgcolor="#FFFFFF">
<div style='layout-grid:15.6pt'> 
  <h1><a name="_Toc486331903"></a><a name="_Toc486332903"></a><a
name="_Toc486339012"></a><a name="_Toc454810877"></a><a name="_Toc454856651"><span><span>第<span
lang=EN-US>8</span></span></span></a><span><span><span style='font-family:黑体;"Times New Roman"'>章</span> 
    </span></span><span><span><span  
style='font-family:黑体;"Times New Roman"'>图象的检测及模板匹配</span></span></span></h1>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>图象的分割与检测</span><span
lang=EN-US>(</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>识别</span><span lang=EN-US>)</span><span
style='font-family:宋体;"Times New Roman"'>实际上是一项非常困难的工作。很难说清楚为什么图象应该分割成这样而不是那样。人类的视觉系统是非常优越的,它不仅包含了双眼,还包括了大脑,可以从很复杂的景物中分开并识别每个物体,甚至可以毫不费力地跟上每秒好几十帧变化的图象。举两个例子来说明一下人类视觉系统的优越性。</span></p>
  <table border=0 cellspacing=0 cellpadding=0>
    <tr> 
      <td width=276 valign=top class="Normal"> 
        <p class=a style='line-height:18.0pt'><span lang=EN-US> <img width=264 height=139
  src="chap08.files/image001.gif"  v:shapes="_x0000_i1025"> </span></p>
        <p class=a style='line-height:18.0pt'><b><span style='font-family:宋体;
  &quot;Times New Roman&quot;'>图</span>8.1&nbsp;&nbsp;&nbsp; </b><b><span  
  style='font-family:宋体;"Times New Roman"'>单词</span><span lang=EN-US>THE</span></b></p>
      </td>
      <td width=276 valign=top class="Normal"> 
        <p class=a style='line-height:18.0pt'><span lang=EN-US> <img width=153 height=137
  src="chap08.files/image003.gif"  v:shapes="_x0000_i1026"> </span></p>
        <p class=a style='line-height:18.0pt'><b><span style='font-family:宋体;
  &quot;Times New Roman&quot;'>图</span>8.2&nbsp;&nbsp;&nbsp; </b><b><span  
  style='font-family:宋体;"Times New Roman"'>看不见的三角</span><span lang=EN-US></span></b></p>
      </td>
    </tr>
  </table>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>图</span><span
lang=EN-US>8.1</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>是单词</span><span lang=EN-US>THE</span><span
style='font-family:宋体;"Times New Roman"'>,这一点很容易看出来,但仔细观察一下,就会发现,图中少了很多线条。在我们人类看来很简单的一件事,让计算机来做就很困难了。</span></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>图</span><span
lang=EN-US>8.2</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>中尽管没有任何线条,但我们还是可以很容易的看出中间存在着一个白色三角形。计算机却很难发现。</span></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>由于人类在观察图象时适用了大量的知识,所以没有任何一台计算机在分割和检测真实图象时,能达到人类视觉系统的水平。正因为如此,对于大部分图象应用来说,自动分割与检测还是一个将来时。目前只有少数的几个领域</span><span
lang=EN-US>(</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>如印刷体识别</span><span lang=EN-US>OCR)</span><span
style='font-family:宋体;"Times New Roman"'>自动识别达到了实用的水平。</span></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>也许算是题外话,我们可以憧憬这样一种应用:基于内容的搜索。在一场足球比赛的录象中,用户可以输入命令,由计算机自动搜索出所有射门的镜头并显示在屏幕上。目前,我们能从一幅图象中获得的信息只是每个象素的颜色或灰度值,除此以外别无其它,完成上述功能实在是太困难了。所以说解决图象分割和检测最根本的方法是在编码</span><span
lang=EN-US>(</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>成象</span><span lang=EN-US>)</span><span
style='font-family:宋体;"Times New Roman"'>时就给予考虑。这也正是</span><span lang=EN-US>MPEG4</span><span
style='font-family:宋体;"Times New Roman"'>及未来的视频压缩编码标准的主要工作。</span></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>正因为有上述的困难,所以我们今天要介绍的只是一些最基本,最简单的算法和思想,针对也只能是一些具体</span><span
lang=EN-US>(</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>而不是通用</span><span lang=EN-US>)</span><span
style='font-family:宋体;"Times New Roman"'>的应用。算法共有三个:投影法、差影法和模板匹配。</span></p>
  <h2> <span
lang=EN-US>8.1</span> <span lang=EN-US> </span><a name="_Toc486331904"></a><a  
name="_Toc486332904"></a><a name="_Toc486339013"></a><a name="_Toc454810878"></a><a
name="_Toc454856652"><span><span>投影法</span></span></a></h2>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>在介绍投影法之前,我先出一道题目,下面的这幅照片是著名的华盛顿纪念碑</span><span
lang=EN-US>(</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>我记得在“阿甘正传”中曾经看到过它</span><span
lang=EN-US>)</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>,怎样从图中自动检测到水平方向上纪念碑的位置。</span></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>仔细观察,不难发现,纪念碑上象素的灰度都差不多而且与众不同,如果我们选取合适的阈值,做削波处理</span><span
lang=EN-US>(</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>这里选</span><span lang=EN-US>175</span><span
style='font-family:宋体;"Times New Roman"'>到</span><span lang=EN-US>220)</span><span style='font-family:
宋体;&quot;Times New Roman&quot;'>,将该图二值化,如图</span><span
lang=EN-US>8.3</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>所示:</span></p>
  <div align=center> 
    <table border=0 cellspacing=0 cellpadding=0>
      <tr> 
        <td width=276 valign=top class="Normal"> 
          <p class=a style='line-height:18.0pt'><span lang=EN-US> <img width=216 height=216
  src="chap08.files/image005.jpg"  v:shapes="_x0000_i1027"> </span></p>
          <p class=a style='line-height:18.0pt'><b><span style='font-family:宋体;
  &quot;Times New Roman&quot;'>图</span>8.3&nbsp;&nbsp;&nbsp; </b><b><span  
  style='font-family:宋体;"Times New Roman"'>华盛顿纪念碑</span><span lang=EN-US></span></b></p>
        </td>
        <td width=276 valign=top class="Normal"> 
          <p class=a style='line-height:18.0pt'><span lang=EN-US> <img width=215 height=217
  src="chap08.files/image007.gif"  v:shapes="_x0000_i1028"> </span></p>
          <p class=a style='line-height:18.0pt'><b><span style='font-family:宋体;
  &quot;Times New Roman&quot;'>图</span>8.4&nbsp;&nbsp;&nbsp; </b><b><span  
  style='font-family:宋体;"Times New Roman"'>削波处理,将图</span><span lang=EN-US>8.3</span></b><b><span
  style='font-family:宋体;"Times New Roman"'>二值化</span><span lang=EN-US></span></b></p>
        </td>
      </tr>
    </table>
  </div>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>由于纪念碑所在的那几列的白色点比起其他列多很多,如果把该图在垂直方向做投影,如图</span><span
lang=EN-US>8.5</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>所示。</span></p>
  <p class=a style='line-height:18.0pt'><span lang=EN-US> <img width=210 height=168
src="chap08.files/image009.jpg"  v:shapes="_x0000_i1029"> </span></p>
  <p align=center style='text-align:center;line-height:18.0pt'><b><span
style='font-family:宋体;"Times New Roman"'>图</span>8.5&nbsp;&nbsp;&nbsp;&nbsp; </b><b><span  
style='font-family:宋体;"Times New Roman"'>图</span><span lang=EN-US>8.4</span></b><b><span
style='font-family:宋体;"Times New Roman"'>做垂直方向投影</span><span lang=EN-US></span></b></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>其中,黑色线条的高度代表了该列上白色点的个数。图中间的高峰部分就是我们要找的水平方向上纪念碑所在的位置,这就是投影法。</span></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>可以看出投影法是一种很自然的想法,有点象灰度直方图。为了得到更好的效果,投影法经常和阈值化一起使用。由于噪声点对投影有一定的影响,所以处理前最好先做一次平滑,去除噪声。</span></p>
  <p style='line-height:18.0pt'><span style='font-family:宋体;
&quot;Times New Roman&quot;'>以下是投影法的源程序,第二个参数是个</span><span
lang=EN-US>BOOL</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>变量,为真时表示在水平方向上做投影,否则在垂直方向上做投影。要注意的是,我们针对的虽然是二值图,但为了处理的方便,用的是</span><span
lang=EN-US>256</span><span style='font-family:宋体;
&quot;Times New Roman&quot;'>级灰度图,不过只用到了</span><span lang=EN-US>0</span><span
style='font-family:宋体;"Times New Roman"'>和</span><span lang=EN-US>255</span><span style='font-family:
宋体;&quot;Times New Roman&quot;'>两种灰度级。</span></p>
  <p style='line-height:18.0pt'><span lang=EN-US>BOOL Projection(HWND hWnd,BOOL   
    Hori)</span></p>
  <p style='line-height:18.0pt'><span lang=EN-US>{</span></p>
  <p style='line-height:18.0pt'><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>DWORD   
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
    OffBits,BufSize;</p>
  <p style='line-height:18.0pt'>LPBITMAPINFOHEADER&nbsp;&nbsp;&nbsp; lpImgData;</p>  
  <p style='line-height:18.0pt'><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>LPSTR&nbsp;   
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
    lpPtr;</p>
  <p style='line-height:18.0pt'><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>HLOCAL&nbsp;&nbsp;&nbsp;   
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
    hTempImgData;</p>
  <p style='line-height:18.0pt'><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>LPBITMAPINFOHEADER&nbsp;&nbsp;&nbsp;   
    lpTempImgData;</p>
  <p style='line-height:18.0pt'><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>LPSTR   
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -