5月份为应付老师的作业写的简单的图片识别的程序
2009-06-12 20:25
302 查看
做的是一个简单的图片识别程序 用来识别摄像头在纸上拍到的图像。注释很详细 整个项目将上传到本人的资源里面去。
关键类
//bmp.h
#ifndef _BMP_H_
#define _BMP_H_
#include <iostream>
#include <list>
using namespace std;
struct BMPPoint
{
int x,y;
};
struct Bound
{
unsigned char data;
int up,low,left,right;
list<BMPPoint> *points;
};
class MapDO
{
public:
/*--------位图转化为灰度图--------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int ChangeGray(unsigned char *pSrcDib, int width, int height);
//--------二阶微分算子提取轮廓---------------
int Laplacian1(unsigned char *pSrcDib, int width, int height);
int Laplacian2(unsigned char *pSrcDib, int width, int height);
int Laplacian3(unsigned char *pSrcDib, int width, int height);
int Laplacian4(unsigned char *pSrcDib, int width, int height);
int Laplacian5(unsigned char *pSrcDib, int width, int height);
int Laplacian6(unsigned char *pSrcDib, int width, int height);
int Laplacian7(unsigned char *pSrcDib, int width, int height);
int Laplacian8(unsigned char *pSrcDib, int width, int height);
//--------二阶微分算子提取轮廓---------------
//--------用Prewitt提取轮廓------------------
int Prewitt(unsigned char *pSrcDib, int width, int height);
/*--------把二值图像细化---------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int Thinning(unsigned char *pSrcDib, int width, int height);
/*--------把二值图像-------------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
thresh 阀值
---------------------------------------------*/
int Threshold(unsigned char *pSrcDib, int width, int height, int thresh);
/*--------中值滤波法去除噪声-----------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
-------------------------------------------*/
int Median(unsigned char *pSrcDib, int width, int height);
/*---------二值图像收缩处理-------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int Erosion(unsigned char *pSrcDib, int width, int height);
/*---------二值图像膨胀处理-------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int Diation(unsigned char *pSrcDib, int width, int height);
/*-------标记图像-----------------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
count 被标记个数
labels 标记数组
bounds 保存每个对象的边框
--------------------------------------------*/
int Label(unsigned char *pSrcDib, int width, int height, unsigned char *lb, int &count, list<Bound> &bounds);
/*-------框住所要的对象-----------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
bounds 标记数组
--------------------------------------------*/
int bounding(unsigned char *pSrcDib, int width, int height, list<Bound> &bounds);
int Rotation(unsigned char *pSrcDib, int width, int height, float deg);
private:
/*--------用二阶微分提取轮廓------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
c[] 算子
amp 图像增益
---------------------------------------------*/
int Second_order_differential(unsigned char *pSrcDib, int width, int height, int c[], float amp);
/*--------用Prewitt提取轮廓-------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
amp 图像增益
---------------------------------------------*/
int Prewitt(unsigned char *pSrcDib, int width, int height, float amp );
/*--------检查连接性---------------------------
inb 输入像素
---------------------------------------------*/
int Cconc(int inb[]);
/*-------求出中值滤波法中9个元素的中间值------
c 橡树
--------------------------------------------*/
int Median_value(int c[]);
/*-------标记图像-----------------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
x 识别位置
y 识别位置
label 标记值
bound 该对象的边框和橡树
--------------------------------------------*/
int Labeling(unsigned char *pSrcDib, int width, int height,int x, int y, int label, Bound &bound);
};
#endif
//ComputerKnow.h
#ifndef _COMPRTERKNOW_H_
#define _COMPRTERKNOW_H_
#include "bmp.h"
#include <deque>
class ComputerKnow
{
public:
/*----------------构造函数---------------------------
pSrcDib 数据源
width 图片宽度
height 图片高度
---------------------------------------------------*/
ComputerKnow(unsigned char* pSrcDib, int width, int height)
{
if (pSrcDib == NULL || width < 0 || height < 0)
{
throw string("error! please send in right!");
}
this->pSrcDib = pSrcDib;
this->width = width;
this->height = height;
}
/*---------------识别---------------------------
rect 矩形个数
triangle 三角形个数
round 圆形个数
----------------------------------------------*/
int Knowing(int &rect, int &triangle, int &round);
private:
/*----------------识别到底是什么----------------
识别是矩形 还是三角形 还是圆形
返回值 1 矩形 , 2 三角形 , 3 圆形 , 0 无法识别
res 保存单个图形个指针
up 最上边界值
low 最下边界值
left 最左边界值
right 最右边界值
----------------------------------------------*/
int KnowWhat(unsigned char* res, int up, int low, int left, int right, int label);
/*------------测试所在范围的像素点个数----------
res 保存单个图形个指针
d 起始队列
up 最上边界值
low 最下边界值
left 最左边界值
right 最右边界值
----------------------------------------------*/
int TestPoint(unsigned char* res, deque<BMPPoint> d, int label, int up, int lwow, int left, int right);
public:
unsigned char* pSrcDib;
int width;
int height;
private:
MapDO mapDo; //基础图像算法
};
#endif
关键类
//bmp.h
#ifndef _BMP_H_
#define _BMP_H_
#include <iostream>
#include <list>
using namespace std;
struct BMPPoint
{
int x,y;
};
struct Bound
{
unsigned char data;
int up,low,left,right;
list<BMPPoint> *points;
};
class MapDO
{
public:
/*--------位图转化为灰度图--------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int ChangeGray(unsigned char *pSrcDib, int width, int height);
//--------二阶微分算子提取轮廓---------------
int Laplacian1(unsigned char *pSrcDib, int width, int height);
int Laplacian2(unsigned char *pSrcDib, int width, int height);
int Laplacian3(unsigned char *pSrcDib, int width, int height);
int Laplacian4(unsigned char *pSrcDib, int width, int height);
int Laplacian5(unsigned char *pSrcDib, int width, int height);
int Laplacian6(unsigned char *pSrcDib, int width, int height);
int Laplacian7(unsigned char *pSrcDib, int width, int height);
int Laplacian8(unsigned char *pSrcDib, int width, int height);
//--------二阶微分算子提取轮廓---------------
//--------用Prewitt提取轮廓------------------
int Prewitt(unsigned char *pSrcDib, int width, int height);
/*--------把二值图像细化---------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int Thinning(unsigned char *pSrcDib, int width, int height);
/*--------把二值图像-------------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
thresh 阀值
---------------------------------------------*/
int Threshold(unsigned char *pSrcDib, int width, int height, int thresh);
/*--------中值滤波法去除噪声-----------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
-------------------------------------------*/
int Median(unsigned char *pSrcDib, int width, int height);
/*---------二值图像收缩处理-------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int Erosion(unsigned char *pSrcDib, int width, int height);
/*---------二值图像膨胀处理-------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
---------------------------------------------*/
int Diation(unsigned char *pSrcDib, int width, int height);
/*-------标记图像-----------------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
count 被标记个数
labels 标记数组
bounds 保存每个对象的边框
--------------------------------------------*/
int Label(unsigned char *pSrcDib, int width, int height, unsigned char *lb, int &count, list<Bound> &bounds);
/*-------框住所要的对象-----------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
bounds 标记数组
--------------------------------------------*/
int bounding(unsigned char *pSrcDib, int width, int height, list<Bound> &bounds);
int Rotation(unsigned char *pSrcDib, int width, int height, float deg);
private:
/*--------用二阶微分提取轮廓------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
c[] 算子
amp 图像增益
---------------------------------------------*/
int Second_order_differential(unsigned char *pSrcDib, int width, int height, int c[], float amp);
/*--------用Prewitt提取轮廓-------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
amp 图像增益
---------------------------------------------*/
int Prewitt(unsigned char *pSrcDib, int width, int height, float amp );
/*--------检查连接性---------------------------
inb 输入像素
---------------------------------------------*/
int Cconc(int inb[]);
/*-------求出中值滤波法中9个元素的中间值------
c 橡树
--------------------------------------------*/
int Median_value(int c[]);
/*-------标记图像-----------------------------
pSrcDib 图片数据指针
width 图片橡树宽度
height 图片橡树高度
x 识别位置
y 识别位置
label 标记值
bound 该对象的边框和橡树
--------------------------------------------*/
int Labeling(unsigned char *pSrcDib, int width, int height,int x, int y, int label, Bound &bound);
};
#endif
//ComputerKnow.h
#ifndef _COMPRTERKNOW_H_
#define _COMPRTERKNOW_H_
#include "bmp.h"
#include <deque>
class ComputerKnow
{
public:
/*----------------构造函数---------------------------
pSrcDib 数据源
width 图片宽度
height 图片高度
---------------------------------------------------*/
ComputerKnow(unsigned char* pSrcDib, int width, int height)
{
if (pSrcDib == NULL || width < 0 || height < 0)
{
throw string("error! please send in right!");
}
this->pSrcDib = pSrcDib;
this->width = width;
this->height = height;
}
/*---------------识别---------------------------
rect 矩形个数
triangle 三角形个数
round 圆形个数
----------------------------------------------*/
int Knowing(int &rect, int &triangle, int &round);
private:
/*----------------识别到底是什么----------------
识别是矩形 还是三角形 还是圆形
返回值 1 矩形 , 2 三角形 , 3 圆形 , 0 无法识别
res 保存单个图形个指针
up 最上边界值
low 最下边界值
left 最左边界值
right 最右边界值
----------------------------------------------*/
int KnowWhat(unsigned char* res, int up, int low, int left, int right, int label);
/*------------测试所在范围的像素点个数----------
res 保存单个图形个指针
d 起始队列
up 最上边界值
low 最下边界值
left 最左边界值
right 最右边界值
----------------------------------------------*/
int TestPoint(unsigned char* res, deque<BMPPoint> d, int label, int up, int lwow, int left, int right);
public:
unsigned char* pSrcDib;
int width;
int height;
private:
MapDO mapDo; //基础图像算法
};
#endif
相关文章推荐
- 斯坦福作业2:简单Java程序 控制台作业合集
- Java 实现的简单图片缩放小程序
- 作业一:创建个人技术博客、自我介绍、简单的C程序
- 根据牛腩老师的mono for android 视频,用xamarin for android 写的一个简单程序范例
- 【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能!
- 简单的python (orc)图片识别(识别京东价格图片)
- [置顶] 微信小程序识别二维码跳转 图片预览,放大图片 + 识别图中二维码 出现的坑2个
- Python_python图片识别小程序
- Java写的一个简单的图片移动小程序
- 吴恩达老师的公开课,简单神经网络的作业总结
- PHP 简单计票程序(作业)
- MATLAB实现一个简单的车牌识别小程序
- 一个C语言写的简单的单词识别程序附带VS性能分析结果
- 一个简单的将yuv图片转化为jpeg格式图片的Python脚本程序
- Matlab实现简单的人脸识别程序
- Linux 内核分析 第二次作业 完成一个简单的时间片轮转多道程序内核代码
- 作业2 编写简单输出程序 LHZ
- Java实现的网络爬虫程序,简单易懂无框架(我的网络大作业)
- JavaSE图像验证码简单识别程序
- 16—【Android游戏开发十六】Android Gesture之【触摸屏手势识别】操作!利用触摸屏手势实现一个简单切换图片的功能