



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、验证码识别常用算法图像处理(验证码识别)程序中常用算法:灰度,二值化,去噪(1*1像素或者 3*3 像素等) 代码:view plaincopy to clipboardprint?/ 灰度private void btnGray_Click( object sender, EventArgs e) tryint Height = this .picBase.Image.Height;int Width = this .picBase.Image.Width; Bitmap newbitmap = newBitmap(Width, Height); Bitmap oldbitmap = (Bi
2、tmap)this .picBase.Image;Color pixel;for ( int x = 0; x Width; x+)for ( int y = 0; y Height; y+) pixel = oldbitmap.GetPixel(x, y);newbitmap.SetPixel(x, y, Gray(pixel); this .picBase.Image = newbitmap; catch (Exception err) MessageBox.Show( 灰度化失败 原因: + err.Message);/ 灰度化算法protected static Color Gray(
3、Color c)int rgb = Convert.ToInt32(double )(0.3 * c.R) + (0.59 * c.G) + (0.11 * c.B);return Color.FromArgb(rgb, rgb, rgb);/ 灰度private void btnGray_Click( object sender, EventArgs e) tryint Height = this .picBase.Image.Height; int Width = this .picBase.Image.Width;Bitmap newbitmap =newBitmap(Width, He
4、ight);Bitmap oldbitmap = (Bitmap)this .picBase.Image;Color pixel;for ( int x = 0; x Width; x+)for ( int y = 0; y Height; y+) pixel = oldbitmap.GetPixel(x, y);newbitmap.SetPixel(x, y, Gray(pixel);this .picBase.Image = newbitmap;catch (Exception err)MessageBox.Show( 灰度化失败 原因: + err.Message);/ 灰度化算法pro
5、tected static Color Gray(Color c)int rgb = Convert.ToInt32( double )(0.3 * c.R) + (0.59 * c.G) + (0.11 * c.B); return Color.FromArgb(rgb, rgb, rgb);图像二值化 效果图: 代码:view plaincopy to clipboardprint?/ 二值化private void btnDobleValue_Click( object sender, EventArgs e)this .picBase.Image = Binarizate(Bitmap
6、) this .picBase.Image);public static Bitmap Binarizate(Bitmap map)int tv = ComputeThresholdValue(map);int x = map.Width;int y = map.Height;for ( int i = 0; i x; i+)for ( int j = 0; j = tv) map.SetPixel(i, j, Color.FromArgb(0xff, 0xff, 0xff);else map.SetPixel(i, j, Color.FromArgb(0, 0, 0);return map;
7、/ 二值化 private void btnDobleValue_Click( object sender, EventArgs e)this .picBase.Image);this .picBase.Image = Binarizate(Bitmap)public static Bitmap Binarizate(Bitmap map) int tv = ComputeThresholdValue(map);int x = map.Width;int y = map.Height;for ( int i = 0; i x; i+)for ( int j = 0; j = tv)map.Se
8、tPixel(i, j, Color.FromArgb(0xff, 0xff, 0xff); elsemap.SetPixel(i, j, Color.FromArgb(0, 0, 0); return map;图像去噪( 1*1 像素) 效果图: 代码:view plaincopy to clipboardprint?private void btnClean11_Click( object sender, EventArgs e) this .picBase.Image = OperateBitmap.ClearNoise(Bitmap)this .picBase.Image,4);/1*
9、1 除噪public static Bitmap ClearNoise(Bitmap bitmap,int MaxNearPoints)Color piexl;int nearDots = 0;/int XSpan, YSpan, tmpX, tmpY;/ 逐点判断for ( int i = 0; i bitmap.Width; i+)for ( int j = 0; j bitmap.Height; j+)piexl = bitmap.GetPixel(i, j);if (piexl.R != 255)nearDots = 0;/ 判断周围 8个点是否全为空边框全去掉 bitmap.SetP
10、ixel(i, j, Color.FromArgb(255, 255, 255);elseif (bitmap.GetPixel(i - 1, j - 1).R != 255 ) nearDots+;if (bitmap.GetPixel(i, j - 1).R != 255) nearDots+; if (bitmap.GetPixel(i + 1, j - 1).R != 255) nearDots+; if (bitmap.GetPixel(i - 1, j).R != 255) nearDots+; if (bitmap.GetPixel(i + 1, j).R != 255) nea
11、rDots+; if (bitmap.GetPixel(i - 1, j + 1).R != 255) nearDots+; if (bitmap.GetPixel(i, j + 1).R != 255) nearDots+; if (bitmap.GetPixel(i + 1, j + 1).R != 255) nearDots+; if (nearDots 4)bitmap.SetPixel(i, j, Color.FromArgb(255, 255, 255); / 去掉单点 & 粗细小 3邻边点 else / 背景bitmap.SetPixel(i, j, Color.FromArgb
12、(255, 255, 255);return bitmap;private void btnClean11_Click( object sender, EventArgs e)this .picBase.Image = OperateBitmap.ClearNoise(Bitmap)this .picBase.Image,4);/1*1 除噪public static Bitmap ClearNoise(Bitmap bitmap,int MaxNearPoints)Color piexl;int nearDots = 0;/int XSpan, YSpan, tmpX, tmpY;/ 逐点判
13、断for ( int i = 0; i bitmap.Width; i+)for ( int j = 0; j bitmap.Height; j+)piexl = bitmap.GetPixel(i, j);if (piexl.R != 255)nearDots = 0;/ 判断周围 8个点是否全为空if (i = 0 | i = bitmap.Width - 1 | j = 0 | j = bitmap.Height - 1)/边框全去掉bitmap.SetPixel(i, j, Color.FromArgb(255, 255, 255);elseif (bitmap.GetPixel(i
14、- 1, j - 1).R != 255 ) nearDots+;if (bitmap.GetPixel(i, j - 1).R != 255) nearDots+;if (bitmap.GetPixel(i + 1, j - 1).R != 255) nearDots+;if (bitmap.GetPixel(i - 1, j).R != 255) nearDots+;if (bitmap.GetPixel(i + 1, j).R != 255) nearDots+;if (bitmap.GetPixel(i - 1, j + 1).R != 255) nearDots+;if (bitmap.GetPixel(i, j + 1).R != 255) nearDots+;if (bitmap.GetPixel(i + 1,
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 图书讲座系列策划方案计划
- 班级工作计划顺利推进
- 2025年离合器主缸项目合作计划书
- 2025年高密度聚乙烯土工膜合作协议书
- 绿色建筑项目2024年合作意向书
- 金融科技公司风控系统设计与优化措施研究报告
- 消防维修工程合同协议书
- 房地产营销合作项目协议书
- 工业机器人班级文化建设方案设计
- 季度市场营销工作计划与执行步骤
- 小升初、小学生满分优秀作文汇编100篇
- 次声波在临床医学及麻醉中的作用 次声波在临床麻醉中的作用
- 2022年云南省中考数学试题及答案解析
- 完整版新能源汽车充电站应急预案
- TS16949五大工具:SPC
- 五年级下册-综合实践教案
- 贵州出版社小学五年级下册综合实践活动教案全册
- 依据FEM9851所作堆垛机循环时间计算
- 牛津大学剑桥大学介绍课件
- 胎心监护及判读学习教案
- SAP-ABAP-实用培训教程
评论
0/150
提交评论