利用神经网络算法的C#手写数字识别(二)




#region 潘正平新增加的
public List<Rectangle> _rowRctList;
public List<Rectangle> _currentWordRctsList;
public List<Rectangle> _currentCharRctsList;
public List<Bitmap> m_bitmaps;
int _irowIndex = 0;
int _iwordIndex = 0;
int _icharIndex;
Bitmap _originalBitmap;
Bitmap _currentRow;
Bitmap _currentWord; /// <summary>
/// 潘正平新加
/// </summary>
/// <param name="bitmap"></param>
public void PatternRecognitionThread(Bitmap bitmap)
{
m_bitmaps = new List<Bitmap>();
_originalBitmap = bitmap;
if (_rowRctList == null)
{
_rowRctList = AForge.Imaging.Image.PatternRectangeBoundaryList
(_originalBitmap, 255, 30, 1, true, 5, 5);
_irowIndex = 0; }
foreach (Rectangle rowRect in _rowRctList)
{
_currentRow = AForge.Imaging.ImageResize.ImageCrop
(_originalBitmap, rowRect);
if (_iwordIndex == 0)
{
_currentWordRctsList = AForge.Imaging.Image.PatternRectangeBoundaryList
(_currentRow, 255, 20, 10, false, 5, 5);
} foreach (Rectangle wordRect in _currentWordRctsList)
{
_currentWord = AForge.Imaging.ImageResize.ImageCrop
(_currentRow, wordRect);
_iwordIndex++;
if (_icharIndex == 0)
{
_currentCharRctsList =
AForge.Imaging.Image.PatternRectangeBoundaryList
(_currentWord, 255, 1, 1, false, 5, 5);
} foreach (Rectangle charRect in _currentCharRctsList)
{
Bitmap _currentChar = AForge.Imaging.ImageResize.ImageCrop
(_currentWord, charRect);
_icharIndex++;
Bitmap bmptemp = AForge.Imaging.ImageResize.FixedSize
(_currentChar, 21, 21);
bmptemp = AForge.Imaging.Image.CreateColorPad
(bmptemp, Color.White, 4, 4);
bmptemp = AForge.Imaging.Image.CreateIndexedGrayScaleBitmap
(bmptemp);
byte[] graybytes = AForge.Imaging.Image.GrayscaletoBytes(bmptemp);
PatternRecognizingThread(graybytes);
m_bitmaps.Add(bmptemp);
}
string s = " \n";
_form.Invoke(_form._DelegateAddObject, new Object[] { 1, s });
if (_icharIndex == _currentCharRctsList.Count)
{
_icharIndex = 0;
}
}
if (_iwordIndex == _currentWordRctsList.Count)
{
_iwordIndex = 0;
}
}
}
#endregion
#region 潘正平新增加的
private void OpenTestImagesToolStripMenuItem_Click(object sender, EventArgs e)
{
if (!_bTestingDataReady || !_MinstTestingDatabase.m_bDatabaseReady)
{
MessageBox.Show("请先加载测试数据库!");
return;
}
OpenFileDialog fDlg = new OpenFileDialog();
fDlg.Filter = "*.bmp|*.bmp|*.jpg|*.jpg";
if (fDlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
Bitmap bmp = new Bitmap(fDlg.FileName);
//this.pictureBoxMain.Image = bmp;
Bitmap bmp2 = new Bitmap(bmp);
this.ImagePatternRecognization(bmp2);
}
} private void ImagePatternRecognization(Bitmap bmp)
{
List<Mutex> mutexs = new List<Mutex>(2);
for (int i = 0; i < 2; i++)
{
var mutex = new Mutex();
mutexs.Add(mutex);
} NNTessing = new NNTestPatterns(_NN, _Mnistdatabase, _Preference, _bDatabaseReady, null, null, this, mutexs);
var thread = new Thread(() => NNTessing.PatternRecognitionThread(bmp));
thread.Start();
while(thread.IsAlive)
{
Application.DoEvents();
Thread.Sleep(10);
}
this.pictureBoxMain.Image = bmp;
this.pictureBoxMain.Refresh();
} NNTestPatterns NNTessing;
Pen pen = new Pen(Color.Red); private void pictureBoxMain_Paint(object sender, PaintEventArgs e)
{
if (NNTessing != null)
{
if (NNTessing._currentCharRctsList != null)
{
e.Graphics.DrawRectangles(pen, NNTessing._currentCharRctsList.ToArray());
}
if (NNTessing._currentWordRctsList != null)
{
e.Graphics.DrawRectangles(pen, NNTessing._currentWordRctsList.ToArray());
}
if (NNTessing._rowRctList != null)
{
e.Graphics.DrawRectangles(pen, NNTessing._rowRctList.ToArray());
}
}
}
#endregion


#region 潘正平新增加的
public List<Rectangle> _rowRctList;
public List<Rectangle> _currentWordRctsList;
public List<Rectangle> _currentWordCharRctsList;
public List<Bitmap> m_bitmaps;
int _irowIndex = 0;
int _iwordIndex = 0;
int _icharIndex;
Bitmap _originalBitmap;
Bitmap _currentRow;
Bitmap _currentWord; /// <summary>
/// 潘正平新加
/// </summary>
/// <param name="bitmap"></param>
public void PatternRecognitionThread(Bitmap bitmap)
{
_currentWordCharRctsList = new List<Rectangle>();
m_bitmaps = new List<Bitmap>();
_originalBitmap = bitmap;
if (_rowRctList == null)
{
_rowRctList = AForge.Imaging.Image.PatternRectangeBoundaryList
(_originalBitmap, 255, 30, 1, true, 5, 5);
_irowIndex = 0; }
foreach (Rectangle rowRect in _rowRctList)
{
_currentRow = AForge.Imaging.ImageResize.ImageCrop
(_originalBitmap, rowRect);
if (_iwordIndex == 0)
{
_currentWordRctsList = AForge.Imaging.Image.PatternRectangeBoundaryList
(_currentRow, 255, 20, 10, false, 5, 5);
} foreach (Rectangle wordRect in _currentWordRctsList)
{
_currentWord = AForge.Imaging.ImageResize.ImageCrop
(_currentRow, wordRect);
_iwordIndex++;
List<Rectangle> _currentCharRctsList = new List<Rectangle>();
if (_icharIndex == 0)
{
_currentCharRctsList = AForge.Imaging.Image.PatternRectangeBoundaryList(_currentWord, 255, 1, 1, false, 5, 5);
}
string strWord = string.Empty;
foreach (Rectangle charRect in _currentCharRctsList)
{
Bitmap _currentChar = AForge.Imaging.ImageResize.ImageCrop(_currentWord, charRect);
_icharIndex++;
Bitmap bmptemp = AForge.Imaging.ImageResize.FixedSize(_currentChar, 21, 21);
bmptemp = AForge.Imaging.Image.CreateColorPad(bmptemp, Color.White, 4, 4);
bmptemp = AForge.Imaging.Image.CreateIndexedGrayScaleBitmap(bmptemp);
byte[] graybytes = AForge.Imaging.Image.GrayscaletoBytes(bmptemp);
strWord += PatternRecognizingThread(graybytes);
m_bitmaps.Add(bmptemp);
//
Rectangle rctCharAbsolute = new Rectangle(wordRect.Left + charRect.Left + rowRect.Left, wordRect.Top + charRect.Top + rowRect.Top, charRect.Width, charRect.Height);
this._currentWordCharRctsList.Add(rctCharAbsolute);
}
string s = " \n";
_form.Invoke(_form._DelegateAddObject, new Object[] { 1, s });
_form.Invoke(_form._DelegateAddObject, new Object[] { 8, strWord });
if (_icharIndex == _currentCharRctsList.Count)
{
_icharIndex = 0;
}
}
if (_iwordIndex == _currentWordRctsList.Count)
{
_iwordIndex = 0;
}
}
}
#endregion
利用神经网络算法的C#手写数字识别(二)的更多相关文章
- 【机器学习】k-近邻算法应用之手写数字识别
上篇文章简要介绍了k-近邻算法的算法原理以及一个简单的例子,今天再向大家介绍一个简单的应用,因为使用的原理大体差不多,就没有没有过多的解释. 为了具有说明性,把手写数字的图像转换为txt文件,如下图所 ...
- 卷积神经网络应用于tensorflow手写数字识别(第三版)
import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data mnist = input_dat ...
- 基于sk_learn的k近邻算法实现-mnist手写数字识别且要求97%以上精确率
1. 导入需要的库 from sklearn.datasets import fetch_openml import numpy as np from sklearn.neighbors import ...
- MLP 之手写数字识别
0. 前言 前面我们利用 LR 模型实现了手写数字识别,但是效果并不好(不到 93% 的正确率). LR 模型从本质上来说还只是一个线性的分类器,只不过在线性变化之后加入了非线性单调递增 sigmoi ...
- 利用神经网络算法的C#手写数字识别
欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 下载Demo - 2.77 MB (原始地址):handwritten_character_recognition.zip 下载源码 - 70. ...
- 利用神经网络算法的C#手写数字识别(一)
利用神经网络算法的C#手写数字识别 转发来自云加社区,用于学习机器学习与神经网络 欢迎大家前往云+社区,获取更多腾讯海量技术实践干货哦~ 下载Demo - 2.77 MB (原始地址):handwri ...
- C#中调用Matlab人工神经网络算法实现手写数字识别
手写数字识别实现 设计技术参数:通过由数字构成的图像,自动实现几个不同数字的识别,设计识别方法,有较高的识别率 关键字:二值化 投影 矩阵 目标定位 Matlab 手写数字图像识别简介: 手写 ...
- 实现手写数字识别(数据集50000张图片)比较3种算法神经网络、灰度平均值、SVM各自的准确率—Jason niu
对手写数据集50000张图片实现阿拉伯数字0~9识别,并且对结果进行分析准确率, 手写数字数据集下载:http://yann.lecun.com/exdb/mnist/ 首先,利用图片本身的属性,图片 ...
- 利用c++编写bp神经网络实现手写数字识别详解
利用c++编写bp神经网络实现手写数字识别 写在前面 从大一入学开始,本菜菜就一直想学习一下神经网络算法,但由于时间和资源所限,一直未展开比较透彻的学习.大二下人工智能课的修习,给了我一个学习的契机. ...
随机推荐
- [leetcode/lintcode 题解] 微软 面试题:实现 Trie(前缀树)
实现一个 Trie,包含 insert, search, 和 startsWith 这三个方法. 在线评测地址:领扣题库官网 样例 1: 输入: insert(" ...
- FreeMark导出word文件
1.编辑好word 2.将word模板另存为xml格式, 把需要动态生成的文字用${xxx}代替 eg: 张强 替换为:${name} 注意:图片是很长的一个base64的字符,同样替换就好 比如替换 ...
- 【Kubernetes学习笔记】-服务访问之 IP & Port & Endpoint 辨析
目录 不同类型的IP Pod IP Cluster IP 不同类型的Port port nodePort TargetPort containerPort hostPort Endpoint Endp ...
- tp5 上传图片(自定义图片路径)
控制器调用 /** * [goods_addimg 图片上传] * @return [type] [description] */ public function addimg(){ if (requ ...
- MindManager导出Word文档功能介绍
Mindmanager思维导图软件作为一款能与Microsoft office软件无缝集成的思维导图软件,支持Word文档的快速导入与导出,并支持Word文档的目录生成.模板套用等,极大地方便了用户完 ...
- 3种终极方法,彻底解决CDR不显示缩略图!
站长所在的印刷出版行业,一般都是使用版本较低的CDR软件,以便更好的兼容出版厂,不然新版本的文件发厂出片时却打不开,而转低版本的话又容易出错.从最开始的 CorelDRAW 9 到现在的 CORELD ...
- 如何使用ABBYY FineReader 处理无法识别的字符?
在识别PDF文档时,我们可能会遇到文档中存在多种语言.多种不同类型文字字符的情况.在ABBYY FineReader 15(Windows系统)OCR文字识别软件的默认语言数据下,可能无法识别PDF文 ...
- 本地VM安装虚拟机,使用xshell连接
首先把VM设置成上面那样 在ubuntu里面安装ssh apt-get install openssh-server 启动服务 /etc/init.d/ssh startifconfig 查看ip x ...
- hashmap(有空可以看看算法这本书中对于这部分的实现,很有道理)
//转载:https://baijiahao.baidu.com/s?id=1618550070727689060&wfr=spider&for=pc 1.为什么用HashMap? H ...
- 【CF600E】Lomsat gelral——树上启发式合并
(题面来自luogu) 题意翻译 一棵树有n个结点,每个结点都是一种颜色,每个颜色有一个编号,求树中每个子树的最多的颜色编号的和. ci <= n <= 1e5 裸题.统计时先扫一遍得到出 ...