以前帮朋友写的代码,现在公布出来,道理很简单的,切割,提取验证码,因为验证码字体并未重合,所以切割起来相当的简单,如果您要做分类信息的网站,采集还是可取的,识别率100%
疯狂代码原创发布,转载请注明出处
C#代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace CrazyCoder.Common.Decode
{
public class GanjiImageDecode : CrazyCoder.Common.Decode.ImageDeCodeBase
{
public GanjiImageDecode(Bitmap pic) : base(pic) { }
public GanjiImageDecode(string path) : base(path) { }
//特征码数组
string[] CodeArray = new string[] {
"00011111000001111111000111000111001100000110110000000111100000001111000000011110000000111100000001101100000110011100011100011111110000011111000",//0
"0111111110110011001100110011001100110011001100110011",//1
"001111100011111110110000111000000011000000011000000110000001110000111000001110000011000000110000000111111111111111111",//2
"001111100011111110110000111000000011000000011000000111000011110000011110000000111000000011110000111011111110001111100",//3
"00000011100000000111000000011110000001101100000110011000011000110001100001100111000011001111111111111111111111000000011000000000110000000001100",//4
"111111110111111110110000000110000000110000000111111000000001110000000111000000011000000011010000111111111110011111100",//5
"0001111000001111111001110001000110000000110000000011001111001111111110111000011111000000110110000011011100011100111111100001111100",//6
"11111111111111110000011000001100000011000001100000110000001100000010000001100000011000000110000001100000",//7
"001111100011111110111000111110000011111000111011111110011111110111000111110000011110000011111000111011111110001111100",//8
"0011111000011111110011100011101100000110110000011111100011110111111011001111001100000000110000000110001000111001111111000011111000",//9
"11111111"//-
};
public Bitmap[] GetPic()
{
ToGrayByPixels(); //灰度处理
Bitmap bmp = GetPicValidByValue(128);
Bitmap[] pics = GetSplitPics2(bmp,128); //分割
for (int i = 0; i < pics.Length; i++)
{
if (pics[i] != null)
{
Bitmap b = pics[i];
pics[i] = GetPicValidByValue(pics[i], 128);
b.Dispose();
}
}
return pics;
}
public string GetCodeString()
{
Bitmap[] pics = GetPic();
string numStr = "";
for (int i = 0; i < pics.Length; i++)
{
string str = GanjiImageDecode.GetSingleBmpCode(pics[i], 128);
for (int j = 0; j < CodeArray.Length; j++)
{
if (CodeArray[j] == str)
{
if (j < CodeArray.Length - 1)
{
numStr += j.ToString();
}
else
{
numStr += "-";
}
}
}
}
return numStr;
}
}
}
2008-8-20 at 4:39
2008-9-17 at 22:00
2008-9-30 at 20:21
2008-10-24 at 12:43
2008-12-11 at 12:51
2009-6-23 at 17:00