找回密码
 加入
搜索
查看: 4220|回复: 5

[GUI管理] 请教验证码的识别分析原理

[复制链接]
发表于 2012-12-15 17:35:29 | 显示全部楼层 |阅读模式
本帖最后由 处男1 于 2012-12-15 17:37 编辑

创建位图后,把位图的信息获取后,然后根据什么来识别图像呢?看了很多例子,但是因为很笨,不是手把手的 教我怎么也看不懂。闹心啊
 Local $hBitmap, $BitmapData, $i_width, $i_height, $Scan0, $pixelData, $s_BMPData, $i_Stride
        _GDIPlus_Startup()

        $hBitmap = _GDIPlus_BitmapCreateFromFile($s_ImageFile)
        If @error Then 
                _GDIPlus_ShutDown ()
                Return 0;无效的图形文件或未找到该文件
        EndIf
        
        $i_width = _GDIPlus_ImageGetWidth($hBitmap)
        $i_height = _GDIPlus_ImageGetHeight($hBitmap)
        
    $BitmapData = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $i_width, $i_height, $GDIP_ILMREAD, $GDIP_PXF24RGB)
        ;If @error Then ......;
    $i_Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up.
    $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap.
    $pixelData = DllStructCreate("ubyte lData[" & (Abs($i_Stride) * $i_height) & "]", $Scan0)
        ;不要使用官方论坛上提供的Abs($i_Stride) * $i_height-1,否则无法正确处理gif冗余等情形
    $s_BMPData = DllStructGetData($pixelData, "lData")
    $s_BMPData = StringTrimLeft($s_BMPData,2);去掉头部"0x"
    _GDIPlus_BitmapUnlockBits($hBitmap, $BitmapData)
        
    _GDIPlus_ImageDispose($hBitmap)
        _WinAPI_DeleteObject ($hBitmap)
        _GDIPlus_Shutdown()
        
        If $b_Array2d Then;要求返回二维数组
                Local $a_return[$i_width][$i_height], $x, $y, $s
                For $y=0 To $i_height-1
                        $s=StringMid($s_BMPData, $y*($i_Stride*2)+1, $i_width*6)
                        ;不要使用一些例子中提出的$s=StringMid($s_BMPData, $y*($i_width*6)+1, $i_width*6),经实际测试,该方式无法正确处理:
                        ;GIF冗余,带隐藏内容的图形文件(一种数据加密方式),或者多页图形文件,当然这些情形比较少见,下同
                        For $x= 0 To $i_width-1
                                $a_return[$x][$y]= Number("0x"&StringMid($s,$x*6+1 ,6))
                                Select
                                Case $func_sc_type=1;黑白
                                        If $a_return[$x][$y]>=$func_sc Then
                                                $a_return[$x][$y]=$func_bg
                                        Else
                                                $a_return[$x][$y]=0
                                        EndIf
                                Case $func_sc_type=2;反相黑白
                                        If $a_return[$x][$y]<$func_sc Then
                                                $a_return[$x][$y]=$func_bg
                                        Else
                                                $a_return[$x][$y]=0
                                        EndIf
                                Case $func_sc_type=3;类似=1,但黑色用原色代替
                                        If $a_return[$x][$y]>=$func_sc Then
                                                $a_return[$x][$y]=$func_bg
                                        EndIf
                                EndSelect
                        Next
                Next
        Else;要求返回一维数组
                Local $a_return[$i_height], $y
                For $y=0 To $i_height-1
                        $a_return[$y]=StringMid($s_BMPData, $y*($i_Stride*2)+1, $i_width*6)
                        $a_return[$y] = myChangeRegExpSC($a_return[$y], $func_sc_type, $func_sc, $func_bg);颜色变化
                Next
        EndIf
Return $a_return
像这段代码我谁能帮我分析分析啊,这也是许多人一直迷惑的问题啊。
 楼主| 发表于 2012-12-15 17:41:28 | 显示全部楼层
代码的功能我都能查到了解,但是不明白为什么要这么用
 楼主| 发表于 2012-12-15 17:48:42 | 显示全部楼层
是不是,获取位图的结构数据,然后用正则对比,找出特征
 楼主| 发表于 2012-12-15 22:05:44 | 显示全部楼层
有没有人指点我一二啊
发表于 2012-12-17 14:53:08 | 显示全部楼层
我记得有大神发过你搜索
发表于 2012-12-23 16:51:26 | 显示全部楼层
看啦哈一般难度大一点的都是对比
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-6 22:16 , Processed in 0.076792 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表