5月份为应付老师的作业写的简单的图片识别的程序

 做的是一个简单的图片识别程序  用来识别摄像头在纸上拍到的图像。注释很详细  整个项目将上传到本人的资源里面去。

 

 关键类

//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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值