



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 上海南湖职业技术学院《行书2》2023-2024学年第一学期期末试卷
- 黑龙江省鹤岗市绥滨五中学2025届数学七上期末学业水平测试试题含解析
- 湖北省襄阳市襄城区2025届化学九年级第一学期期末联考试题含解析
- 五年级数学(小数四则混合运算)计算题专项练习及答案汇编
- 山东省滕州市业水平考试数(基础卷)2025届七年级数学第一学期期末综合测试模拟试题含解析
- 武汉工程大学邮电与信息工程学院《三维设计》2023-2024学年第一学期期末试卷
- 湖南省长沙市部分学校2025届数学八上期末预测试题含解析
- 周口师范学院《植物营养与肥料学双语》2023-2024学年第一学期期末试卷
- 九江职业技术学院《人体生理学》2023-2024学年第一学期期末试卷
- 二年级看图写话格式范文
- 社区获得性肺炎ppt
- 直流屏检修作业指导书(word文档)
- YY/T 1293.2-2022接触性创面敷料第2部分:聚氨酯泡沫敷料
- GB/T 19404-2003微波铁氧体器件主要性能测量方法
- GB/T 18418-2017家用卫生杀虫用品电热蚊香液
- GB/T 17456.2-2010球墨铸铁管外表面锌涂层第2部分:带终饰层的富锌涂料涂层
- 政府用地项目用地报批流程
- 高校毕业生学籍档案管理课件
- 老年人的生理变化特点课件
- 徐健顺吟诵文集(.12.16)
- 临床药师用药干预记录表
评论
0/150
提交评论