下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年广西国际商务职业技术学院单招综合素质笔试备考试题含详细答案解析
- 2026年春季湘艺版小学音乐一年级下册教学计划含教学进度表
- 4.7.4 选择健康的生活方式(第二课时)教学设计-2025-2026学年人教版生物(2024)八年级上册
- 2026广东韶关市乐昌市黄圃镇人民政府消防专职人员招聘1人笔试备考试题及答案解析
- 2026福建龙岩新罗区大池中心幼儿园招聘3人笔试备考题库及答案解析
- 2026福建漳州市龙海区人力资源和社会保障局招聘1人笔试备考试题及答案解析
- 2026广东肇庆市高要区事业单位招聘高层次人才5人笔试备考试题及答案解析
- 2026中原科技学院许昌校区招聘240人笔试备考题库及答案解析
- 2026福建宁德古田县实验小学招聘编外工作人员的1人笔试备考题库及答案解析
- 2026河南驻马店高新技术产业开发投资有限公司招聘工作人员1人笔试备考试题及答案解析
- 安全生产费用投入等制度
- 2026版离婚协议书(官方标准版)
- 生产过程安全基本要求
- 北京市2025北京市公园管理中心所属事业单位招聘111人笔试历年参考题库典型考点附带答案详解(3卷合一)2套试卷
- 湖北交投集团考试真题及答案
- 超声科医学教育与学术交流的未来
- T/CADBM 3-2018竹木纤维集成墙面
- 服装行业质量控制流程
- 知识产权保护国别指南(澳大利亚)
- 廉洁应征承诺书
- SPSS教程中文完整版
评论
0/150
提交评论