识别CSDN验证码的思路

csdn可以说的技术界的老大了,而CSDN的验证码识别如下,看如下代码

简单验证码的识别:CSDN验证码的识别
取图像部分,ASP.NET_SessionID=这个值你要自己取这样的话就可以做成自动登录了

private Streamgeturl( ref string str)
{
stringurl="http://www.csdn.net/member/ShowExPwd.aspx";
WebRequestmyWebRequest
=WebRequest.Create(url);

myWebRequest.Headers.Add(
"Cookie","ASP.NET_SessionId=tr0p4g45xa0qzg45bmlqprnn");
WebResponsemyWebResponse
=myWebRequest.GetResponse();
StreamReceiveStream
=myWebResponse.GetResponseStream();
str
=myWebResponse.Headers[6];
returnReceiveStream;

}

private string getNumber()
{
stringstr;
str
="";
StreamgeturlStream
=geturl(refstr);
Bitmapmap
=newBitmap(geturlStream,false);
pictureBox1.Image
=(Image)map;
csdncsdn1
=newcsdn();
returncsdn1.readMap(map)+str;
}

验证码识别部分(很简单类型的):

分割图片变成四个部分.

接下来判断象素点.再判断特征点 100%识别

usingSystem;
usingSystem.Drawing;
usingSystem.Drawing.Drawing2D;
usingSystem.Drawing.Imaging;

namespacebinbin
{
/**////


///Class1的摘要说明。
///

publicclasscsdn
{
publiccsdn()
{

}

publicstringreadMap(Bitmapimage)
{
stringstr;
RectangleF[]block
=newRectangleF[4];
block[
0]=newRectangle(3,0,8,18);
block[
1]=newRectangle(12,0,8,18);
block[
2]=newRectangle(21,0,8,18);
block[
3]=newRectangle(30,0,8,18);
//分别克隆图片的四个部分
Bitmap[]s=newBitmap[4];
s[
0]=image.Clone(block[0],PixelFormat.DontCare);
s[
1]=image.Clone(block[1],PixelFormat.DontCare);
s[
2]=image.Clone(block[2],PixelFormat.DontCare);
s[
3]=image.Clone(block[3],PixelFormat.DontCare);
str
=ReadMap(s[0]).ToString();
str
=str+ReadMap(s[1]).ToString();
str
=str+ReadMap(s[2]).ToString();
str
=str+ReadMap(s[3]).ToString();
returnstr;
}

privateintReadMap(Bitmapk)
{
intn=0;
intm=0;
Colorcolor;
for(inti=7;i>=0;i--)
{
for(intj=17;j>=0;j--)
{
color
=k.GetPixel(i,j);
if(color.GetBrightness()==1.0)
{
n
=n+1;//白色点
}

else
{
m
=m+1;//蓝色点
}


}

}

switch(m)
{
case22:
color
=k.GetPixel(7,12);
if(color.GetBrightness()==1)
{
return2;
}

else
{
return3;
}

case25:
return4;
case26:
return5;
case28:
return0;
case30:
return8;
case18://1829还要特殊处理
color=k.GetPixel(7,4);
if(color.GetBrightness()==1)
{
return1;
}

else
{
return7;
}

case29:

color
=k.GetPixel(1,15);
if(color.GetBrightness()==1)
{
return6;
}

else
{
return9;
}

default:
break;
}

return-1;
}

}

}

你可能感兴趣的:(识别CSDN验证码的思路)