简单验证码的识别:CSDN验证码的识别取图像部分,ASP.NET_SessionID=这个值你要自己取这样的话就可以做成自动登录了
csdn可以说的技术界的老大了,而CSDN的验证码识别如下,看如下代码
简单验证码的识别:CSDN验证码的识别
取图像部分,ASP.NET_SessionID=这个值你要自己取这样的话就可以做成自动登录了
private Stream geturl(ref string str)
{
string url = "http://www.csdn.net/member/ShowExPwd.aspx";
WebRequest myWebRequest = WebRequest.Create(url);
myWebRequest.Headers.Add("Cookie","ASP.NET_SessionId=tr0p4g45xa0qzg45bmlqprnn");
WebResponse myWebResponse = myWebRequest.GetResponse();
Stream ReceiveStream = myWebResponse.GetResponseStream();
str=myWebResponse.Headers[6];
return ReceiveStream;
}
private string getNumber()
{
string str;
str="";
Stream geturlStream =geturl(ref str);
Bitmap map = new Bitmap(geturlStream,false);
pictureBox1.Image = (Image)map;
csdn csdn1= new csdn ();
return csdn1.readMap(map)+str;
}
验证码识别部分(很简单类型的):
分割图片变成四个部分.
接下来判断象素点.再判断特征点 100%识别
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
namespace binbin
{
/** <summary>
/// Class1 的摘要说明。
/// </summary>
public class csdn
{
public csdn()
{
}
public string readMap(Bitmap image)
{
string str;
RectangleF[] block=new RectangleF[4];
block[0]=new Rectangle(3,0,8,18);
block[1]=new Rectangle(12,0,8,18);
block[2]=new Rectangle(21,0,8,18);
block[3]=new Rectangle(30,0,8,18);
//分别克隆图片的四个部分
Bitmap[] s=new Bitmap[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();
return str;
}
private int ReadMap(Bitmap k)
{
int n=0;
int m=0;
Color color;
for(int i=7; i>=0;i--)
{
for( int j=17; j>=0;j--)
{
color=k.GetPixel(i,j);
if (color.GetBrightness()==1.0)
{
n=n+1;//白色点
}
else
{
m=m+1;//蓝色点
}
}
}
switch(m)
{
case 22:
color=k.GetPixel(7,12);
if (color.GetBrightness()==1)
{
return 2;
}
else
{
return 3;
}
case 25:
return 4;
case 26:
return 5;
case 28:
return 0;
case 30:
return 8;
case 18: //18 29还要特殊处理
color=k.GetPixel(7,4);
if (color.GetBrightness()==1)
{
return 1;
}
else
{
return 7;
}
case 29:
color=k.GetPixel(1,15);
if (color.GetBrightness()==1)
{
return 6;
}
else
{
return 9;
}
default:
break;
}
return -1;
}
}
}