資源簡介
初學(xué)者的實用代碼,對熟悉模式識別技術(shù)有一定的幫助,還可用于其他字符識別的算法參考

代碼片段和文件信息
#include?“stdafx.h“
#include?“cdib.h“
#include?“windowsx.h“
#include?“math.h“
#define?WIDTHBYTES(bits)????(((bits)?+?31)?/?32?*?4)?
CDib::CDib()
{
size=0;
}
CDib::~CDib()
{
????GlobalFreePtr(m_pBitmapInfo);
}
void?CDib::LoadFile(const?char*?dibFileName)
{
???strcpy(m_fileNamedibFileName);
????CFile?dibFile(m_fileName?CFile::modeRead);
????dibFile.Read((void*)&bitmapFileHeadersizeof(BITMAPFILEHEADER));
????if?(bitmapFileHeader.bfType?==?0x4d42)
????{
????????DWORD?fileLength?=?dibFile.GetLength();????
?????????size?=?fileLength?-sizeof(BITMAPFILEHEADER);
?????????pDib?=(BYTE*)GlobalAllocPtr(GMEM_MOVEABLE?size);
????????dibFile.Read((void*)pDib?size);
????????dibFile.Close();
????????m_pBitmapInfo?=?(BITMAPINFO*)?pDib;
????????m_pBitmapInfoHeader?=?(BITMAPINFOHEADER*)?pDib;
????????m_pRGB?=?(RGBQUAD*)(pDib?+
m_pBitmapInfoHeader->biSize);
????????int?m_numberOfColors?=?GetNumberOfColors();
????????if?(m_pBitmapInfoHeader->biClrUsed?==?0)
????????????m_pBitmapInfoHeader->biClrUsed?=
????m_numberOfColors;
????????DWORD?colorTableSize?=?m_numberOfColors?*
????????????sizeof(RGBQUAD);
????????m_pData?=?pDib?+?m_pBitmapInfoHeader->biSize
????????????+?colorTableSize;
if?(m_pRGB?==?(RGBQUAD*)m_pData)?//?No?color?table
m_pRGB?=?NULL;
????????m_pBitmapInfoHeader->biSizeImage?=?GetSize();
m_valid?=?TRUE;
????}????
????else
????{
????????m_valid?=?FALSE;
????????AfxMessageBox(“This?isn‘t?a?bitmap?file!“);
????}
}
BOOL?CDib::IsValid()
{
????return?m_valid;
}
????????
char*?CDib::GetFileName()
{
????return?m_fileName;
}
????????
UINT?CDib::GetWidth()
{
????return?(UINT)?m_pBitmapInfoHeader->biWidth;
}
????????
UINT?CDib::GetHeight()
{
????return?(UINT)?m_pBitmapInfoHeader->biHeight;
}
????????
DWORD?CDib::GetSize()
{
????if?(m_pBitmapInfoHeader->biSizeImage?!=?0)
????????return?m_pBitmapInfoHeader->biSizeImage;
else
????{
????????DWORD?height?=?(DWORD)?GetHeight();
????????DWORD?width?=?(DWORD)?GetWidth();
????????return?height?*?width;
????}
}
void?CDib::SetWidth(UINT?width)
{
m_pBitmapInfoHeader->biWidth=width;
}
void?CDib::SetHeight(UINT?height)
{
m_pBitmapInfoHeader->biHeight=height;
}
UINT?CDib::GetNumberOfColors()
{
int?numberOfColors;
????if?((m_pBitmapInfoHeader->biClrUsed?==?0)?&&
??????????(m_pBitmapInfoHeader->biBitCount?9))
{
switch?(m_pBitmapInfoHeader->biBitCount)
{
????case?1:?numberOfColors?=?2;?break;
????case?4:?numberOfColors?=?16;?break;
????case?8:?numberOfColors?=?256;
}
}
????else
numberOfColors?=?(int)?m_pBitmapInfoHeader->biClrUsed;
????return?numberOfColors;
}
????
BYTE*?CDib::GetData()
{
????return?m_pData;
}
RGBQUAD*?CDib::GetRGB()
{
????return?m_pRGB;
}
BITMAPINFO*?CDib::GetInfo()
{
????return?m_pBitmapInfo;
}
WORD?CDib::PaletteSize(LPBYTE?lpDIB)?
{?
????return?(DIBNumColors(lpDIB)?*?sizeof(RGBTRIPLE));?
}?
WORD?CDib::DIBNumColors(LPBYTE?lpDIB)?
{
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????3606??2008-08-05?10:38??字符識別程序,26個英文字母的識別\CDib.cpp
?????文件????????844??2008-08-05?10:38??字符識別程序,26個英文字母的識別\CDib.h
?????文件??????????0??2008-08-06?09:26??字符識別程序,26個英文字母的識別\chardefine.h
?????文件???????5092??2005-01-01?09:02??字符識別程序,26個英文字母的識別\Classification.cpp
?????文件???????1145??2005-01-01?09:02??字符識別程序,26個英文字母的識別\Classification.h
?????文件??????17246??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\CDib.obj
?????文件??????23413??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\Classification.obj
?????文件??????12978??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\DlgSave.obj
?????文件??????10541??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\GetFeature.obj
?????文件??????22428??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\MainFrm.obj
?????文件?????151664??2013-01-04?22:33??字符識別程序,26個英文字母的識別\Debug\pattern.exe
?????文件?????429588??2013-01-04?22:33??字符識別程序,26個英文字母的識別\Debug\pattern.ilk
?????文件??????24100??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\pattern.obj
?????文件????5497428??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\pattern.pch
?????文件?????533504??2013-01-04?22:33??字符識別程序,26個英文字母的識別\Debug\pattern.pdb
?????文件???????7660??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\pattern.res
?????文件??????25233??2013-01-04?22:32??字符識別程序,26個英文字母的識別\Debug\patternDoc.obj
?????文件??????41727??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\patternView.obj
?????文件??????33878??2013-01-03?16:20??字符識別程序,26個英文字母的識別\Debug\PatternView2.obj
?????文件?????106245??2013-01-03?16:15??字符識別程序,26個英文字母的識別\Debug\StdAfx.obj
?????文件?????230400??2013-01-05?12:30??字符識別程序,26個英文字母的識別\Debug\vc60.idb
?????文件?????372736??2013-01-04?22:32??字符識別程序,26個英文字母的識別\Debug\vc60.pdb
?????文件????????927??2008-08-06?09:30??字符識別程序,26個英文字母的識別\DlgSave.cpp
?????文件???????1196??2008-08-06?09:30??字符識別程序,26個英文字母的識別\DlgSave.h
?????文件???????3904??2008-08-06?09:14??字符識別程序,26個英文字母的識別\GetFeature.cpp
?????文件???????1403??2008-08-06?09:14??字符識別程序,26個英文字母的識別\GetFeature.h
?????文件???????3010??2008-08-05?09:56??字符識別程序,26個英文字母的識別\MainFrm.cpp
?????文件???????1704??2008-08-05?09:44??字符識別程序,26個英文字母的識別\MainFrm.h
?????文件???????8160??2005-01-13?00:00??字符識別程序,26個英文字母的識別\Matrix.h
?????文件??????30324??2013-01-03?16:28??字符識別程序,26個英文字母的識別\pattern.aps
............此處省略51個文件信息
評論
共有 條評論