Sign in to follow this  
Followers 0
davidkim

image search / compare using coffer

1 post in this topic

#1 ·  Posted (edited)

this source is image retrieval using example

Posted Image

first random numeric 4 digit display.....................

Posted Image

[start] button click is 4 digit numeric search....... point 0x00ff00 label overlap....

Posted Image

user input number 4 digit search can........

back jpg file

Posted Image

safe.zip

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <array.au3>
#include <ScreenCapture.au3>
#region ### START Koda GUI section ### Form=
Dim $11[10]
Dim $22[10]
Dim $1pic[5]
Dim $2pic[10]
For $i = 1 To 9
$11[$i] = @ScriptDir & "pic" & $i & ".BMP"
$22[$i] = @ScriptDir & "picR" & $i & ".BMP"
Next
Global $back = @ScriptDir & "picback.jpg"
Dim $Num[5]
Global $s2, $s3
Dim $la[5]

Dim $x[10]
Dim $y[10]
$x[1] = 3 + 138
$x[2] = 3 + 138 + 48
$x[3] = 3 + 138 + 96
$x[4] = 3 + 138
$x[5] = 3 + 138 + 48
$x[6] = 3 + 138 + 96
$x[7] = 3 + 138
$x[8] = 3 + 138 + 48
$x[9] = 3 + 138 + 96
$y[1] = 25 + 254
$y[2] = 25 + 254
$y[3] = 25 + 254
$y[4] = 25 + 254 + 48
$y[5] = 25 + 254 + 48
$y[6] = 25 + 254 + 48
$y[7] = 25 + 254 + 94
$y[8] = 25 + 254 + 94
$y[9] = 25 + 254 + 94


$Form1_1 = GUICreate("safe box", 565, 517, -1, -1)
GUISetBkColor(0xFFFFFF)
$Pic1 = GUICtrlCreatePic($back, 0, 0, 512, 512)
GUICtrlSetState(-1, $gui_disable)
$1pic[1] = GUICtrlCreatePic("", 188, 79, 33, 33)
$1pic[2] = GUICtrlCreatePic("", 188 + 33, 79, 33, 33)
$1pic[3] = GUICtrlCreatePic("", 188 + 66, 79, 33, 33)
$1pic[4] = GUICtrlCreatePic("", 188 + 99, 79, 33, 33)
$2pic[1] = GUICtrlCreatePic("", 138, 254, 48, 48)
$2pic[2] = GUICtrlCreatePic("", 138 + 48, 254, 48, 48)
$2pic[3] = GUICtrlCreatePic("", 138 + 96, 254, 48, 48)
$2pic[4] = GUICtrlCreatePic("", 138, 254 + 48, 48, 48)
$2pic[5] = GUICtrlCreatePic("", 138 + 48, 254 + 48, 48, 48)
$2pic[6] = GUICtrlCreatePic("", 138 + 96, 254 + 48, 48, 48)
$2pic[7] = GUICtrlCreatePic("", 138, 254 + 94, 48, 48)
$2pic[8] = GUICtrlCreatePic("", 138 + 48, 254 + 94, 48, 48)
$2pic[9] = GUICtrlCreatePic("", 138 + 96, 254 + 94, 48, 48)
$start = GUICtrlCreateButton("start", 456, 104, 99, 25)
$user_input = GUICtrlCreateInput("", 456, 144, 99, 21, $ES_NUMBER)
$set = GUICtrlCreateButton("reset", 456, 176, 99, 25)
$exit = GUICtrlCreateButton("exit", 456, 447, 99, 25)
GUISetState(@SW_SHOW)
Global $handle = WinGetHandle("safe box")
#endregion ### END Koda GUI section ###
set()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $start
Check_Top_Numeric()
Check_Buttom_Numeric()
Case $set
set()
Case $exit
Exit
EndSwitch
WEnd
Func set()
For $i = 1 To 4
GUICtrlDelete($la[$i])
Next
Dim $s_Out, $a_Chars = StringSplit('123456789', '')
For $i_Count = 1 To $a_Chars[0]
_ArraySwap($a_Chars[$i_Count], $a_Chars[Random(1, $a_Chars[0], 1)])
Next
For $i_Count = 1 To $a_Chars[0]
$s_Out &= $a_Chars[$i_Count]
Next
For $i = 1 To 9
GUICtrlSetImage($2pic[$i], $22[$a_Chars[$i]])
Next
If GUICtrlRead($user_input) = '' Then
Dim $a_ran = StringSplit('123456789', '')
For $i_ct = 1 To $a_ran[0]
_ArraySwap($a_ran[$i_ct], $a_ran[Random(1, $a_ran[0], 1)])
Next
$ran = $a_ran[5] & $a_ran[7] & $a_ran[1] & $a_ran[3]
Else
$ran = GUICtrlRead($user_input)
EndIf
$a_ran = StringSplit($ran, '')
For $i = 1 To 4
GUICtrlSetImage($1pic[$i], $11[$a_ran[$i]])
Next
EndFunc ;==>set
Func top_scan_numeric($1, $2, $3, $4, $save_bmp)
_ScreenCapture_SetBMPFormat(4)
_ScreenCapture_CaptureWnd($save_bmp, $handle, $1, $2, $3, $4, False)
EndFunc ;==>top_scan_numeric
Func Buttom_scan_numeric($1, $2, $save_bmp)
_ScreenCapture_SetBMPFormat(4)
_ScreenCapture_CaptureWnd($save_bmp, $handle, $1, $2, $1 + 48, $2 + 48, False)
EndFunc ;==>Buttom_scan_numeric
Func Check_Top_Numeric()
FileDelete(@ScriptDir & "picT1.BMP")
FileDelete(@ScriptDir & "picT2.BMP")
FileDelete(@ScriptDir & "picT3.BMP")
FileDelete(@ScriptDir & "picT4.BMP")
top_scan_numeric(188 + 3, 79 + 25, 188 + 33 + 3, 79 + 33 + 25, @ScriptDir & "picT1.bmp")
Sleep(100)
top_scan_numeric(188 + 33 + 3, 79 + 25, 188 + 66 + 3, 79 + 33 + 25, @ScriptDir & "picT2.bmp")
Sleep(100)
top_scan_numeric(188 + 66 + 3, 79 + 25, 188 + 99 + 3, 79 + 33 + 25, @ScriptDir & "picT3.bmp")
Sleep(100)
top_scan_numeric(188 + 99 + 3, 79 + 25, 188 + 132 + 3, 79 + 33 + 25, @ScriptDir & "picT4.bmp")
Sleep(100)
_GDIPlus_Startup()
For $Li = 1 To 4
For $i = 1 To 9
$hImage1 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "pic" & $i & ".bmp")
$iX = _GDIPlus_ImageGetWidth($hImage1)
$iY = _GDIPlus_ImageGetHeight($hImage1)
$hImage2 = _GDIPlus_ImageLoadFromFile(@ScriptDir & "pic" & "T" & $Li & ".bmp")
$iIW = _GDIPlus_ImageGetWidth($hImage2)
$iIH = _GDIPlus_ImageGetHeight($hImage2)
$bm1 = _GDIPlus_BitmapCloneArea($hImage1, 0, 0, 33, 33, $GDIP_PXF32ARGB)
$bm2 = _GDIPlus_BitmapCloneArea($hImage2, 0, 0, 33, 33, $GDIP_PXF32ARGB)
Local $compare = CompareBitmapPixels($bm1, $bm2)
$s2 = Round(100 - (Number($compare) / 2304) * 100, 0)
If $s2 > 89 Then $s3 = $i
_GDIPlus_BitmapDispose($bm1)
_GDIPlus_BitmapDispose($bm2)
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
Next
$Num[$Li] = $s3
Next
_GDIPlus_Shutdown()
EndFunc ;==>Check_Top_Numeric

Func Check_Buttom_Numeric()
For $i = 1 To 4
GUICtrlDelete($la[$i])
Next
For $i = 1 To 9
FileDelete(@ScriptDir & "picB" & $i & ".BMP")
Buttom_scan_numeric($x[$i], $y[$i], @ScriptDir & "picB" & $i & ".BMP")
Next
_GDIPlus_Startup()
For $Ri = 1 To 4
For $i = 1 To 9
$new = _GDIPlus_ImageLoadFromFile(@ScriptDir & "picB" & $i & ".bmp")
$scan = _GDIPlus_ImageLoadFromFile(@ScriptDir & "picR" & $Num[$Ri] & ".bmp")
$bm_new = _GDIPlus_BitmapCloneArea($new, 0, 0, 48, 48, $GDIP_PXF32ARGB)
$bm_scan = _GDIPlus_BitmapCloneArea($scan, 0, 0, 48, 48, $GDIP_PXF32ARGB)
$s2 = Compare_Buttom_Numeric($bm_new, $bm_scan)
_GDIPlus_BitmapDispose($bm_new)
_GDIPlus_BitmapDispose($bm_scan)
_GDIPlus_ImageDispose($new)
_GDIPlus_ImageDispose($scan)
$sa = StringSplit($s2, "|", 1)
If $sa[1] = $sa[2] Then
    $la[$Ri] = GUICtrlCreateLabel("", $x[$i] + 25, $y[$i], 4, 4)
    GUICtrlSetBkColor(-1, 0x00ff00)
EndIf
Next
Next
_GDIPlus_Shutdown()
EndFunc ;==>Check_Buttom_Numeric
Func Compare_Buttom_Numeric($bm1, $bm2);new-old
Local $Bm1W, $Bm1H, $BitmapData1, $Scan0, $Bm2W, $BitmapData2, $Bm2H
Local $Scan01, $iNum = 0, $iDiff = 0, $v_BufferA, $AllPixels
Local $sREResult1, $aArray, $v_BufferB, $AllPixelsB, $sREResult2, $aArray2
$Bm1W = _GDIPlus_ImageGetWidth($bm1)
$Bm1H = _GDIPlus_ImageGetHeight($bm1)
$BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
$Scan0 = DllStructGetData($BitmapData1, "Scan0")
$Bm2W = _GDIPlus_ImageGetWidth($bm2)
$Bm2H = _GDIPlus_ImageGetHeight($bm2)
$BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
$Scan01 = DllStructGetData($BitmapData2, "Scan0")
$v_BufferA = DllStructCreate("byte[" & $Bm1H * $Bm1W * 4 & "]", $Scan0) ; Create DLL structure for all pixels
$AllPixels = DllStructGetData($v_BufferA, 1)
$sREResult1 = StringRegExpReplace(StringTrimLeft($AllPixels, 2), "(.{8})", "1 ")
$aArray = StringSplit(StringStripWS($sREResult1, 3), " ")
Local $c1 = 0, $c2 = 0
For $i = 1 To $aArray[0]
If $aArray[$i] = 'C2C2C2FF' Then
$c1 += 1
EndIf
If $aArray[$i] = 'A8A8A8FF' Then
$c2 += 1
EndIf
Next
$v_BufferB = DllStructCreate("byte[" & $Bm2H * $Bm2W * 4 & "]", $Scan01) ; Create DLL structure for all pixels
$AllPixelsB = DllStructGetData($v_BufferB, 1)
$sREResult2 = StringRegExpReplace(StringTrimLeft($AllPixelsB, 2), "(.{8})", "1 ")
$aArray2 = StringSplit(StringStripWS($sREResult2, 3), " ")
Local $d1 = 0, $d2 = 0
For $i = 1 To $aArray2[0]
If $aArray2[$i] = 'C2C2C2FF' Then
$d1 += 1
EndIf
If $aArray2[$i] = 'A8A8A8FF' Then
$d2 += 1
EndIf
Next
$iDiff = Abs($aArray2[0] - $aArray[0])
For $i = 1 To UBound($aArray) - 1 - $iDiff
If $aArray2[$i] <> $aArray[$i] Then $iNum += 1
Next
_GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
_GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)
Return $c1 & $c2 & '|' & $d1 & $d2
EndFunc ;==>Compare_Buttom_Numeric
Func CompareBitmapPixels($bm1, $bm2)
Local $Bm1W, $Bm1H, $BitmapData1, $Scan0, $Bm2W, $BitmapData2, $Bm2H
Local $Scan01, $iNum = 0, $iDiff = 0, $v_BufferA, $AllPixels
Local $sREResult1, $aArray, $v_BufferB, $AllPixelsB, $sREResult2, $aArray2
$Bm1W = _GDIPlus_ImageGetWidth($bm1)
$Bm1H = _GDIPlus_ImageGetHeight($bm1)
$BitmapData1 = _GDIPlus_BitmapLockBits($bm1, 0, 0, $Bm1W, $Bm1H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
$Scan0 = DllStructGetData($BitmapData1, "Scan0")
$Bm2W = _GDIPlus_ImageGetWidth($bm2)
$Bm2H = _GDIPlus_ImageGetHeight($bm2)
$BitmapData2 = _GDIPlus_BitmapLockBits($bm2, 0, 0, $Bm2W, $Bm2H, $GDIP_ILMREAD, $GDIP_PXF32RGB)
$Scan01 = DllStructGetData($BitmapData2, "Scan0")
$v_BufferA = DllStructCreate("byte[" & $Bm1H * $Bm1W * 4 & "]", $Scan0) ; Create DLL structure for all pixels
$AllPixels = DllStructGetData($v_BufferA, 1)
$sREResult1 = StringRegExpReplace(StringTrimLeft($AllPixels, 2), "(.{8})", "1 ")
$aArray = StringSplit(StringStripWS($sREResult1, 3), " ")
$v_BufferB = DllStructCreate("byte[" & $Bm2H * $Bm2W * 4 & "]", $Scan01) ; Create DLL structure for all pixels
$AllPixelsB = DllStructGetData($v_BufferB, 1)
$sREResult2 = StringRegExpReplace(StringTrimLeft($AllPixelsB, 2), "(.{8})", "1 ")
$aArray2 = StringSplit(StringStripWS($sREResult2, 3), " ")
$iDiff = Abs($aArray2[0] - $aArray[0])
For $i = 1 To UBound($aArray) - 1 - $iDiff
If $aArray2[$i] <> $aArray[$i] Then $iNum += 1
Next
_GDIPlus_BitmapUnlockBits($bm1, $BitmapData1)
_GDIPlus_BitmapUnlockBits($bm2, $BitmapData2)
Return $iNum + $iDiff
EndFunc ;==>CompareBitmapPixels

in korea... Posted Image large snowflakes ......

Edited by davidkim

I interest am many quite in AutoitScript.From that is [http://cafe.naver.com/autoitscript[/color]] Korea of cafe(blog) to be operating, [size="2"][color="#ff00ff"]English cannot well[/size].Many help it requests.To read, it stands it thanks.

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0