破解校内的图片识别码。

Posted 0x16

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了破解校内的图片识别码。相关的知识,希望对你有一定的参考价值。

 

using  System;
using  System.Collections.Generic;
using  System.Text;
using  System.Drawing;

namespace  XiaoNei.VerifyImage
{
    
public static class Verify
    
{
        
private static int[,] imageDatas;
        
private static String code;
        
private static Bitmap image;

        
/**//// <summary>
        
/// 获取验证码
        
/// </summary>
        
/// <param name="filename">输入文件名</param>
        
/// <returns>验证码</returns>

       
        
public static String getCode(String filename)      
        
{
            Bitmap image 
= new Bitmap(filename);
            readDatas(image);
            code 
= "" + getBestCode(getSimple(35)) +
                    getBestCode(getSimple(
313)) +
                    getBestCode(getSimple(
321)) +
                    getBestCode(getSimple(
329));
            Console.WriteLine(code);

            
//测试识别是否正确,文件名中含有验证码
            
//if (filename.IndexOf(code) < 0)
               
// Console.WriteLine("Error");
            return code;
        }


        
/**//// <summary>
        
/// 初始化数据
        
/// </summary>

        private static void readDatas(Bitmap image)
        
{

            imageDatas 
= new int[image.Height, image.Width];
            Color pixelColor;
            
for (int h = 0; h < image.Height; h++)
            
{
                
for (int w = 0; w < image.Width; w++)
                
{
                    pixelColor 
= image.GetPixel(w, h);

                    imageDatas[h, w] 
= pixelColor.R > 0 ? 1 : 0;
                }
//for
            }
//for
        }

        
/**//// <summary>
        
/// 取数字块
        
/// </summary>
        
/// <param name="x">横坐标</param>
        
/// <param name="y">纵坐标</param>
        
/// <returns>一维数组</returns>

        private static int[] getSimple(int x, int y)
        
{
            
int[] simple = new int[9 * 6];
            
int count = 0;
            
for (int h = x; h < x + 9; h++)
            
{
                
for (int w = y; w < y + 6; w++)
                
{
                    simple[count
++= imageDatas[h, w];
                }

            }

            
return simple;
        }

        
/**//// <summary>
        
/// 最和谐的数字
        
/// </summary>
        
/// <param name="x">数字块</param>
        
/// <returns>结果</returns>

        private static int getBestCode(int[] x)
        
{
            
int bestNumber = -1;
            
double bestVal = 0.0;
            
for (int index = 0; index < 10; index++)
            
{
                
double val = compareSimple(NumberData.getNumber(index), x);
                
if (bestVal <= val)
                
{
                    bestVal 
= val;
                    bestNumber 
= index;
                }

            }

            
return bestNumber;
        }

        
/**//// <summary>
        
/// 获取两个数字图像数组的和谐百分比
        
/// </summary>
        
/// <param name="t">匹配数字数组</param>
        
/// <param name="x">待匹配数字数组</param>
        
/// <returns>和谐百分比</returns>

        private static double compareSimple(int[] t, int[] x)
        
{
            
int count = 0;
            
int val = 0;
            
for (int i = 0; i < t.Length; i++)
            
{
                
if (1 == t[i])
                
{
                    count
++;
                    
if (1 == x[i])
                    
{
                        val
++;
                    }

                }

            }

            
return (val + 0.0/ count;
        }

    }



}


最近在做一个校内刷人气的小工具,顺便把图像识别搞了一下。 把源代码贴出来。请高手指教。

using  System;
using  System.Drawing;
using  System.Collections;
using  System.ComponentModel;
using  System.Windows.Forms;
using  System.Net; 
using  System.IO;
using  System.Text;

namespace  XiaoNei.VerifyImage
{
   
public  class DownLoadImage
    
{
        
/// <summary>
        
/// 从图片地址下载图片到本地磁盘
        
/// </summary>
        
/// <param name="ToLocalPath">图片本地磁盘地址</param>
        
/// <param name="Url">图片网址</param>
        
/// <returns></returns>

        public static bool SavePhotoFromUrl(string FileName, string Url)
        
{
            
bool Value = false;
            WebResponse response 
= null;
            Stream stream 
= null;

            
try
            
{
                HttpWebRequest request 
= (HttpWebRequest)WebRequest.Create(Url);

                response 
= request.GetResponse();
                stream 
= response.GetResponseStream();

                
if (!response.ContentType.ToLower().StartsWith("text/"))
                
{
                    Value 
= SaveBinaryFile(response, FileName);

                }


            }

            
catch (Exception err)
            
{
                
string aa = err.ToString();
            }

            
return Value;
        }

        
/// <summary>
        
/// Save a binary file to disk.
        
/// </summary>
        
/// <param name="response">The response used to save the file</param>

        // 将二进制文件保存到磁盘
        private static bool SaveBinaryFile(WebResponse response, string FileName)
        
{
            
bool Value = true;
(原创)牛逼!通过Python做文字识别到破解图片验证码

验证码识别---基本流程

Python破解验证码技术,识别率高达百分之八十

教程 | 用Python识别图片验证码中的文字

web 自动化-验证码识别登录 图片验证码

验证码识别之模板匹配方法