CSDN验证码识别

获取图像部分

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;
  }

验证码识别部分

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;
  }
 }
转载请注明出处:lovebanyi 风云

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值