資源簡介
包括詳細(xì)講解與源代碼,目的是將一幅圖像中的數(shù)字識別出來,圖像中數(shù)字有一定的傾斜角度,且各個(gè)部分光照不均,數(shù)字大體分布位置相同。作者根據(jù)圖像的這些性質(zhì),對圖像進(jìn)行分析,寫出了識別數(shù)字的一個(gè)算法,該算法先對圖像進(jìn)行尺度變換,將傾斜的圖像正立,同時(shí)提取圖像中的數(shù)字部分,再對數(shù)字進(jìn)行特征的提取,最后確定所識別的是哪一個(gè)具體數(shù)字。在識別過程中,由于數(shù)字的特征不同,識別難度也不同,因此識別時(shí)有順序區(qū)別,遵循先識別較難識別的數(shù)字,再識別簡單的,并不是嚴(yán)格按照從0到9的順序。對于題目材料中所給的6幅圖像能進(jìn)行準(zhǔn)確的識別,作者再將材料中的某些圖像稍加改動后,仍能識別,識別效果較好。

代碼片段和文件信息
#include?“stdafx.h“
#include?“cvapp.h“
#include?“math.h“
ImageProcessor?*proc?=?0;
int?H;//圖像高度
int?W;//圖像寬度
//計(jì)算直線距離
int?dst(int?xint?yfloat?afloat?bfloat?c)
{
return?abs((a*x+b*y+c)/sqrt(a*a+b*b));
}
//用于表示圖像上點(diǎn)的一個(gè)結(jié)構(gòu)體
struct?Point
{
int?h;???????//該點(diǎn)高度坐標(biāo)
int?w;???????//該點(diǎn)寬度坐標(biāo)
Point(int?aint?b)
{
h=a;
w=b;
}
};
//計(jì)算兩點(diǎn)之間距離
int?dst(Point?p1Point?p2)
{
int?dist=sqrt((p1.h-p2.h)*(p1.h-p2.h)+(p1.w-p2.w)*(p1.w-p2.w));
return?dist;
}
//根據(jù)索引獲取一維數(shù)組值
unsigned?char?Getdata(int?hint?wunsigned?char*?data)
{
return?data[h*W+w];
}
//查找p點(diǎn)左上方的點(diǎn)是否為0
bool?checkLU(Point?punsigned?char*?data)
{
if?(p.w==0)//沒有左
return?false;
else?if?(p.h==0)?//沒有上
return?false;
else?if?(Getdata(p.h-1p.w-1data)!=0)//左上方不為0
return?false;
return?true;
}
//查找p點(diǎn)正上方的點(diǎn)是否為0
bool?checkU(Point?punsigned?char*?data)
{
if?(p.h==0)//沒有上
return?false;
else?if?(Getdata(p.h-1p.wdata)!=0)//正上方不為0
return?false;
return?true;
}
//查找p點(diǎn)右上方的點(diǎn)是否為0
bool?checkRU(Point?punsigned?char*?data)
{
if?(p.w==W-1)?//沒有右
return?false;
else?if?(p.h==0)//沒有上
return?false;
else?if?(Getdata(p.h-1p.w+1data)!=0)//右上方不為0
return?false;
return?true;
}
//查找p點(diǎn)正左方的點(diǎn)是否為0
bool?checkL(Point?punsigned?char*?data)
{
if?(p.w==0)?//沒有左
return?false;
else?if?(Getdata(p.hp.w-1data)!=0)//正左方不為0
return?false;
return?true;
}
//查找p點(diǎn)正右方的點(diǎn)是否為0
bool?checkR(Point?punsigned?char*?data)
{
if?(p.w==W-1)?//沒有右
return?false;
else?if?(Getdata(p.hp.w+1data)!=0)//正右方不為0
return?false;
return?true;
}
//查找p點(diǎn)左下方的點(diǎn)是否為0
bool?checkLD(Point?punsigned?char*?data)
{
if?(p.w==0)?//沒有左
return?false;
else?if?(p.h==H-1)//沒有下
return?false;
else?if?(Getdata(p.h+1p.w-1data)!=0)//左下方不為0
return?false;
return?true;
}
//查找p點(diǎn)正下方的點(diǎn)是否為0
bool?checkD(Point?punsigned?char*?data)
{
if?(p.h==H-1)//沒有下
return?false;
else?if?(Getdata(p.h+1p.wdata)!=0)//正下方不為0
return?false;
return?true;
}
//查找p點(diǎn)右下方的點(diǎn)是否為0
bool?checkRD(Point?punsigned?char*?data)
{
if?(p.w==W-1)?//沒有右
return?false;
else?if?(p.h==H-1)//沒有下
return?false;
else?if?(Getdata(p.h+1p.w+1data)!=0)//右下方不為0
return?false;
return?true;
}
//尋找從點(diǎn)p開始,最左最上的點(diǎn)
Point?Find_LU(Point?punsigned?char*?data)
{
Point?p1=pp2=p;
int?i=1j=0;
while?(i*=-1)?//讓i在1和-1之間來回切換,用于記錄最近兩個(gè)時(shí)刻所要求的目標(biāo)點(diǎn)
{
if?(checkLU(pdata))//左上方
{
if?(i==1)?
{
if?(p.h-1!=p1.h||p.w-1!=p1.w)?//查找的點(diǎn)為新點(diǎn)
p1=Point(p.h-1p.w-1);
else?break;//改點(diǎn)已經(jīng)找過,則改點(diǎn)為要找的點(diǎn)
}
else
{
if?(p.h-1!=p2.h||p.w-1!=p2.w)?//查找的點(diǎn)為新點(diǎn)
p2=Point(p.h-1p.w-1);
else?break;
}
}
else?if?(checkU(pdata))//上方
{
if(i==1)
{
if?(p.h-1!=p1.h||p.w!=p1.w)?
p1=Point(p.h-1p.w);
else?break;
}
else
{
if?(p.h-1!=p2.h||p.w!=p2.w)?
p2=Point(p.h-1p.w);
else?break;
}
}
else?if?(checkRU(pdata))//右上方
{
if?(i==1)?
{
if?(p.h-1!=p1.h
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????31534??2009-01-15?20:33??數(shù)字識別源程序\cvapp.cpp
?????文件????????972??2009-01-12?16:23??數(shù)字識別源程序\cvapp.h
?????文件??????20740??2009-01-14?11:50??數(shù)字識別源程序\Imgrcv.aps
?????文件???????1155??2009-01-15?19:31??數(shù)字識別源程序\Imgrcv.clw
?????文件???????2063??2008-12-28?15:23??數(shù)字識別源程序\Imgrcv.cpp
?????文件???????4340??2008-12-28?17:14??數(shù)字識別源程序\Imgrcv.dsp
?????文件????????537??2008-12-28?15:23??數(shù)字識別源程序\Imgrcv.dsw
?????文件???????1324??2008-12-28?15:23??數(shù)字識別源程序\Imgrcv.h
?????文件?????181248??2009-01-15?21:11??數(shù)字識別源程序\Imgrcv.ncb
?????文件??????48640??2009-01-15?21:11??數(shù)字識別源程序\Imgrcv.opt
?????文件????????453??2009-01-15?21:11??數(shù)字識別源程序\Imgrcv.plg
?????文件???????5312??2009-01-02?15:15??數(shù)字識別源程序\Imgrcv.rc
?????文件???????4724??2009-01-14?13:48??數(shù)字識別源程序\ImgrcvDlg.cpp
?????文件???????1363??2009-01-02?15:15??數(shù)字識別源程序\ImgrcvDlg.h
?????文件???????3579??2008-12-28?15:23??數(shù)字識別源程序\ReadMe.txt
?????文件???????1078??2008-12-28?15:23??數(shù)字識別源程序\res\Imgrcv.ico
?????文件????????398??2008-12-28?15:23??數(shù)字識別源程序\res\Imgrcv.rc2
????..A.SH.??????3072??2009-01-15?22:47??數(shù)字識別源程序\res\Thumbs.db
?????文件????????776??2009-01-02?15:15??數(shù)字識別源程序\resource.h
?????文件????????208??2008-12-28?15:23??數(shù)字識別源程序\StdAfx.cpp
?????文件???????1054??2008-12-28?15:23??數(shù)字識別源程序\StdAfx.h
?????文件???????1144??2009-01-15?21:11??數(shù)字識別源程序\圖片\1.txt
?????文件???????1144??2009-01-15?21:11??數(shù)字識別源程序\圖片\2.txt
?????文件???????1144??2009-01-15?21:11??數(shù)字識別源程序\圖片\3.txt
?????文件???????1144??2009-01-15?21:11??數(shù)字識別源程序\圖片\4.txt
?????文件??????14690??2009-01-15?18:52??數(shù)字識別源程序\圖片\Image0.BMP
?????文件??????14690??2009-01-15?18:59??數(shù)字識別源程序\圖片\Image1.bmp
?????文件??????14690??2009-01-15?19:59??數(shù)字識別源程序\圖片\Image2.BMP
?????文件??????14690??2009-01-15?20:02??數(shù)字識別源程序\圖片\Image3.BMP
?????文件??????14690??2009-01-15?14:25??數(shù)字識別源程序\圖片\Image4.bmp
............此處省略18個(gè)文件信息
評論
共有 條評論