opencv手写数字识别C++


opencv手写数字识别
资源截图
代码片段和文件信息
#include “stdafx.h“
#include “cvapp.h“
#include “math.h“

ImageProcessor *proc = 0;
int H;//图像高度
int W;//图像宽度

//计算直线距离
int dst(int xint yfloat afloat bfloat c)
{
return abs((a*x+b*y+c)/sqrt(a*a+b*b));
}

//用于表示图像上点的一个结构体
struct Point
{
int h;       //该点高度坐标
int w;       //该点宽度坐标
Point(int aint b)
{
h=a;
w=b;
}
};

//计算两点之间距离
int dst(Point p1Point p2)
{
int dist=sqrt(float((p1.h-p2.h)*(p1.h-p2.h)+(p1.w-p2.w)*(p1.w-p2.w)));
return dist;
}

//根据索引获取一维数组值
unsigned char Getdata(int hint wunsigned char* data)
{
return data[h*W+w];
}

//查找p点左上方的点是否为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点正上方的点是否为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点右上方的点是否为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点正左方的点是否为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点正右方的点是否为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点左下方的点是否为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点正下方的点是否为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点右下方的点是否为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;
}

//寻找从点p开始,最左最上的点
Point Find_LU(Point punsigned char* data)
{
Point p1=pp2=p;
int i=1j=0;
while (i*=-1) //让i在1和-1之间来回切换,用于记录最近两个时刻所要求的目标点
{
if (checkLU(pdata))//左上方
{
if (i==1) 
{
if (p.h-1!=p1.h||p.w-1!=p1.w) //查找的点为新点
p1=Point(p.h-1p.w-1);
else break;//改点已经找过,则改点为要找的点
}
else
{
if (p.h-1!=p2.h||p.w-1!=p2.w) //查找的点为新点
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-

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-10-10 14:54  数字识别源程序_重要的OpenCV程序
     文件           0  2015-06-17 11:20  数字识别源程序_重要的OpenCV程序1.txt
     文件           0  2015-06-17 11:20  数字识别源程序_重要的OpenCV程序2.txt
     文件           0  2015-06-17 11:20  数字识别源程序_重要的OpenCV程序3.txt
     文件           0  2015-06-17 11:20  数字识别源程序_重要的OpenCV程序4.txt
     文件       31006  2015-06-17 11:18  数字识别源程序_重要的OpenCV程序cvapp.cpp
     文件         952  2011-07-12 16:24  数字识别源程序_重要的OpenCV程序cvapp.h
     目录           0  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序Debug
     文件         574  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugBscMake.command.1.tlog
     文件         872  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序Debugscmake.read.1.tlog
     文件         442  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序Debugscmake.write.1.tlog
     文件        3058  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序Debugcl.command.1.tlog
     文件       70996  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugCL.read.1.tlog
     文件        1692  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugCL.write.1.tlog
     文件      365581  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序Debugcvapp.obj
     文件           0  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序Debugcvapp.sbr
     文件    12233728  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.bsc
     文件        1907  2015-06-17 11:19  数字识别源程序_重要的OpenCV程序DebugImgrcv.Build.CppClean.log
     文件      137728  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.exe
     文件         667  2015-06-17 11:19  数字识别源程序_重要的OpenCV程序DebugImgrcv.exe.embed.manifest
     文件         732  2015-06-17 11:19  数字识别源程序_重要的OpenCV程序DebugImgrcv.exe.embed.manifest.res
     文件         381  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.exe.intermediate.manifest
     文件     1387100  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.ilk
     文件          87  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.lastbuildstate
     文件       10101  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.log
     文件       25827  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.obj
     文件    27590656  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.pch
     文件     5803008  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.pdb
     文件        2560  2015-06-17 11:19  数字识别源程序_重要的OpenCV程序DebugImgrcv.res
     文件           0  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.sbr
     文件         713  2015-10-10 13:59  数字识别源程序_重要的OpenCV程序DebugImgrcv.vcxprojResolveAssemblyReference.cache
............此处省略71个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)