回复 1# zhenglei
看看我的识别
#include <INet.au3>
#include <GDIPlusex.au3>
#include <Array.au3>
#include <Memory.au3>
;0-9的数字值
Global $n[10][12] = [["00011110", "00111110", "01110011", "01100011", "01100011", "11000011", _
"11000011", "11000110", "11000110", "11001110", "01111100", "01111000"],["00000110", "00001110", "00111110", "01111100", "01101100", "00001100", _
"00001100", "00001100", "00001100", "00011000", "00011000", "00011000"],["00011110", "00111111", "01110011", "01100011", "00000011", "00000110", _
"00001110", "00011100", "00111000", "01110000", "11111110", "11111110"],["00011110", "00111111", "01100011", "00000011", "00000111", "00011110", _
"00011110", "00000110", "00000110", "11000110", "11111100", "01111000"],["00000001", "00000011", "00000111", "00001110", "00011110", "00110110", _
"01100110", "11000110", "11111111", "11111111", "00001100", "00001100"],["00011111", "00011111", "00110000", "00110000", "00111110", "01111111", _
"01100011", "00000011", "00000011", "11000110", "11111110", "01111000"],["00011110", "00111111", "01110011", "01100000", "11011100", "11111110", _
"11100110", "11000110", "11000110", "11001110", "01111100", "00111000"],["01111111", "01111111", "00000011", "00000110", "00001100", "00001100", _
"00011000", "00011000", "00110000", "00110000", "01100000", "01100000"],["00011110", "00111111", "01100011", "01100011", "01100111", "00111110", _
"01111100", "11100110", "11000110", "11001110", "11111100", "01111000"],["00011110", "00111110", "01110011", "01100011", "01100011", "01100111", _
"01111111", "00111011", "00000110", "11001110", "11111100", "01111000"]]
$yzm = "http://jscs.fxl.teacheredu.cn/GuoPeiAdmin/Login/ImageLog.aspx"
$hGui = GUICreate("识别例子", 100, 60)
$Label1 = GUICtrlCreateLabel("点击我的上方", 14, 40, 80, 17)
$Pic1 = GUICtrlCreatePic("", 14, 10, 50, 20)
Global $hPic = GUICtrlGetHandle(-1)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
GUIDelete()
Exit
Case $Pic1
GUICtrlSetData($Label1, myYzmShibie($yzm))
EndSwitch
WEnd
Func myYzmShibie($URL, $func_bg = 0xffffff)
Local $BitmapData, $i_width, $i_height, $Scan0, $pixelData, $s_BMPData, $i_Stride
_GDIPlus_Startup()
;获取图片
$bImage = _INetGetSource($URL, False)
$bData = Binary($bImage)
$Lenght = BinaryLen($bData)
$hData = _MemGlobalAlloc($Lenght, 0x0002)
$pData = _MemGlobalLock($hData)
$tData = DllStructCreate('byte[' & $Lenght & ']', $pData)
DllStructSetData($tData, 1, $bData)
_MemGlobalUnlock($hData)
$pStream = _WinAPI_CreateStreamOnHGlobal($hData)
$hImage = _GDIPlus_BitmapCreateFromStream($pStream)
;转换图片到pic控件显示
$hBitMap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
;把图片读入数组,来自阿福源码
$i_width = _GDIPlus_ImageGetWidth($hImage)
$i_height = _GDIPlus_ImageGetHeight($hImage)
$BitmapData = _GDIPlus_BitmapLockBits($hImage, 0, 0, $i_width, $i_height, $GDIP_ILMREAD, $GDIP_PXF24RGB)
$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_ImageDispose($hImage)
_MemGlobalFree($hData)
_GDIPlus_Shutdown()
;设置到pic控件
$oldObj = _SendMessage($hPic, 0x0172, 0, $hBitMap)
_WinAPI_DeleteObject($oldObj)
Local $hObj = _SendMessage($hPic, 0x0173)
If $hObj <> $hBitMap Then
_WinAPI_DeleteObject($hBitMap)
EndIf
DllCall('psapi.dll', 'int', 'EmptyWorkingSet', 'hWnd', -1)
;处理图片数组
Local $a_return[$i_width][$i_height], $x, $y, $s
Local $ls = "", $lls = ""
For $y = 5 To $i_height - 4;5和4分别是图片上下的空边
$s = StringMid($s_BMPData, $y * ($i_Stride * 2) + 1, $i_width * 6)
For $x = 6 To $i_width - 9;6和9分别是图片左右的空边
$a_return[$x][$y] = Number("0x" & StringMid($s, $x * 6 + 1, 6))
If $a_return[$x][$y] < $func_bg Then
$a_return[$x][$y] = 1
Else
$a_return[$x][$y] = 0
EndIf
Next
Next
Local $Number = ""
For $i = 0 To 3;读取4个数字的值
$sx = 6 + 9 * $i;6是第一个数字的起点,每个数字占9列,第9列是空白列
For $y = 5 To $i_height - 4;5和4分别是图片上下的空边
$ls = ""
For $x = $sx To $sx + 7;因为每个数字占9列,第9列是空白列,所以只读取8列
If $a_return[$x][$y] = 1 Then
$ls &= "1"
Else
$ls &= "0"
EndIf
Next
$ls &= '|'
$lls = $lls & $ls
Next
$Number &= WhatNumber($lls)
$lls = ""
Next
Return $Number
EndFunc ;==>myYzmShibie
Func WhatNumber($Sum)
Local $checktotal, $aCheck = StringSplit($Sum, "|")
For $i = 0 To 9
$checktotal = 0
For $j = 0 To 9 ;可以到11,为了加快速度最下二行不比较了,字的高度为11
If $n[$i][$j] <> $aCheck[$j + 1] Then $checktotal += 1
If $checktotal > 2 Then ExitLoop
Next
If $checktotal < 3 Then Return $i
Next
Return -1
EndFunc ;==>WhatNumber
|