下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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-2026学年期末试卷
- 2026道德与法治一年级拓展空间 戏曲文化初识
- 2026道德与法治二年级知识窗 压力应对方法
- 社会安全生产主题讲解
- 2023中考英语阅读理解知识点题型
- 2023年综合知识题库
- 消防安全海报黑白设计
- 医护健康宣教资料
- 2023年自学考试医学心理学试题答案及评分参考
- 2026年天津东丽区高三一模高考模拟英语试卷(含答案详解)
- 设计院安全生产管理制度
- 新《金融机构客户尽职调查和客户身份资料及交易记录保存管理办法》解读课件
- 2025年民用无人机驾驶航空器操控员理论合格证考试答案
- 肾脏毒性药物科普
- 维修燃气锅炉合同范本
- 村级各项制度汇编
- 珊瑚成品进货合同范本
- 森林资源管理知识培训课件
- 2025级全科转岗出科考核试题及答案(消化科)
- 《网络营销实务(第4版)》高职全套教学课件
- 《老年人能力评估实务》智慧健康养老服务全套教学课件
评论
0/150
提交评论