下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 关于连江县2019-2021年招聘的编外合同教师转编内或参聘考试的备考题库及参考答案详解
- 2026年重庆市大渡口长征医院招聘备考题库及1套完整答案详解
- 2026年蚌埠市中欣国有控股有限公司公开招聘副总经理备考题库及1套参考答案详解
- 2026年深圳市龙岗区第七人民医院公开招聘聘员及劳务派遣人员的备考题库及答案详解一套
- 2026年陆军军医大学西南医院护士长招聘备考题库及答案详解参考
- 2025年建筑行业合同管理与风险防范
- 2025年大学新能源材料与器件(新能源材料研发)试题及答案
- 2025年高职关节松动训练(康复技术)试题及答案
- 2026年林业技术(树木病虫害防治)试题及答案
- 2025年高职幼儿营养(膳食搭配)试题及答案
- 质量效应2楷模路线文字版
- 消防设施检查记录表
- 酒店协议价合同
- 哈尔滨工业大学简介宣传介绍
- 青光眼的药物治疗演示
- 中国儿童错颌畸形早期矫治专家共识
- 罗永浩海淀剧场演讲
- 苏州市公务员考核实施细则
- GB/T 5147-2003渔具分类、命名及代号
- GB/T 2703-2017鞋类术语
- GB/T 21010-2007土地利用现状分类
评论
0/150
提交评论