c#实现识别图片上的验证码数字

2019-12-30 11:03:40刘景俊
  • for (int y = 0; y < h; y++)  { 
  • for (int x = 0; x < w; x++)  { 
  • p[0] = p[1] = p[2] = (int)vSource[x, y] > 161 ? (byte)255 : (byte)0;  //p[0] = p[1] = p[2] = (int)GetAverageColor(vSource, x, y, w, h) > 50 ? (byte)255 : (byte)0; 
  • p += nn;   
  • }  p += offset; 
  • }  bmpDest.UnlockBits(dataDest); 
  •   orcbmp = bmpDest; 
  • orcbmp.Save("d:二值化.png");  pictureBox29.Image = Image.FromFile("d:二值化.png"); 
  • }   
  • //OCR的值  if (orcbmp != null) 
  • {  string result = Ocr(orcbmp); 
  • label32.Text = result.Replace("n", "rn").Replace(" ", "");  } 
  •   } 

    C#识别验证码图片通用类

     

     
    1. using System;  using System.Collections.Generic; 
    2. using System.Text;  using System.Collections; 
    3. using System.Drawing;  using System.Drawing.Imaging; 
    4. using System.Runtime.InteropServices;   
    5. namespace BallotAiying2  { 
    6. class UnCodebase  { 
    7. public Bitmap bmpobj;  public UnCodebase(Bitmap pic)