没有合适的资源?快使用搜索试试~ 我知道了~
模式识别 模式识别实验报告 1. 初始化样品特征库及获得待测手写数字的特征矩阵 //函数的声明部分 GetFeature.h #include "Cdib.h" struct pattern//pattern结构体,保存某个数字类别(0~9)的所有样品特征 { int number;//该手写数字样品个数 double feature[200][25];//各样品特征,每类手写数字最多有200个样品,每个样品有25个特征 };
资源推荐
资源详情
资源评论
模式识别实验报告
1. 初始化样品特征库及获得待测手写数字的特征矩阵
//函数的声明部分
GetFeature.h
#include "Cdib.h"
struct pattern//pattern 结构体,保存某个数字类别(0~9)的所有样品特征
{
int number;//该手写数字样品个数
double feature[200][25];//各样品特征,每类手写数字最多有 200 个样品,每个样品有 25
个特征
};
class GetFeature : public CDib
{
public:
pattern pattern[10];//手写数字样品特征库
double testsample[25];//待测的手写数字
int width;//手写数字的宽
int height;//手写数字的高
int LineBytes;
void Save(int cls);//将手写的数字保存到 cls(0~9)类别中
BOOL Saveable(int cls);//判断手写的数字能否保存到 cls(0~9)类别中,因为各类别中样
品特征不能重复
double Cal(int row, int col);//计算分割好的 5×5 小区域中,黑像素所占的比例
void SetFeature();//计算手写数字的特征,赋值给 testsample
void GetPosition();//获得手写数字的位置
GetFeature();
virtual ~GetFeature();
protected:
int bottom;//手写数字的底部
int top;//手写数字的顶部
int left;//手写数字的左边
int right;//手写数字的右边
};
//函数的实现部分
GetFeature.cpp
/***************************************************************
* 函数名称:GetPosition()
* 函数类型:void
* 函数功能:搜索手写数字的位置,赋值给 bottom,down,right,left
****************************************************************/
void GetFeature::GetPosition()
{
width=GetWidth();
height=GetHeight();
LineBytes=(width*8+31)/32*4;
int i,j;
BOOL flag;
for(j=0;j<height;j++)
{
flag=FALSE;
for(i=0;i<width;i++)
if(m_pData[j*LineBytes+i]==0)
{
flag=TRUE;
break;
}
if(flag)
break;
}
bottom=j;
for(j=height-1;j>0;j--)
{
flag=FALSE;
for(i=0;i<width;i++)
if(m_pData[j*LineBytes+i]==0)
{
flag=TRUE;
break;
}
if(flag)
break;
}
top=j;
for(i=0;i<width;i++)
{
flag=FALSE;
for(j=0;j<height;j++)
if(m_pData[j*LineBytes+i]==0)
{
flag=TRUE;
break;
}
if(flag)
break;
}
left=i;
for(i=width-1;i>0;i--)
{
flag=FALSE;
for(j=0;j<height;j++)
if(m_pData[j*LineBytes+i]==0)
{
flag=TRUE;
break;
}
if(flag)
break;
}
right=i;
}
/***************************************************************
* 函数名称:SetFeature()
* 函数类型:void
* 函数功能:将手写数字特征保存在变量 testsample 中
****************************************************************/
void GetFeature::SetFeature()
{
int i,j;
for(j=0;j<5;j++)
{
for(i=0;i<5;i++)
{
testsample[5*(4-j)+i]=Cal(j,i);//(Cal(j,i)>0.10)?1:0;//
}
}
}
/****************************************************************
* 函数名称:Cal(int row, int col)
* 函数类型:double
* 参数说明:int row, int col:第 row 行,第 col 个区域
* 函数功能:计算某一小区域内黑像素所占比例,返回某一小区域内黑像素所占比例
****************************************************************/
double GetFeature::Cal(int row, int col)
{
double w,h,count;
剩余14页未读,继续阅读
资源评论
zhengdandan0528
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功