图片比较,结果输出
我要比较两个图片内容是否一样,之前看到前辈写的代码,可是怎么没有对比结果显示呢,这部分应该怎么写#include <GUIConstants.au3>
#include<ButtonConstants.au3>
#include<WindowsConstants.au3>
Opt("PixelCoordMode", 2)
Global $Color=0xEF0000
Global $Pic
Global $U32
Global $GDI
GUICreate("", 313, 201)
$Path1 = GUICtrlCreateInput("Muestra2.bmp", 24, 48, 193, 21)
$Path2 = GUICtrlCreateInput("Muestra1.bmp", 24, 92, 193, 21)
$Browse1 = GUICtrlCreateButton("Browse", 226, 48, 61, 23, 0)
$Browse2 = GUICtrlCreateButton("Browse", 226, 92, 61, 23, 0)
$compare = GUICtrlCreateButton("&Compare", 95, 152, 127, 31, $BS_DEFPUSHBUTTON)
GUICtrlCreateGroup(" Paths ", 8, 14, 293, 123)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Browse1
$newPath=FileOpenDialog("",@MyDocumentsDir,"(*.jpg;*bmp)")
if Not @error Then
GUICtrlSetData($Path1,$newPath)
EndIf
Case $Browse2
$newPath=FileOpenDialog("",@MyDocumentsDir,"(*.jpg;*bmp)")
if Not @error Then
GUICtrlSetData($Path2,$newPath)
EndIf
Case $compare
$Pic1Path=GUICtrlRead($Path1)
$Pic2Path=GUICtrlRead($Path2)
$U32=DllOpen("user32.dll")
$GDI=DllOpen("GDI32.dll")
$Test = Compare($Pic1Path,$Pic2Path, 200,200)
DllClose($U32)
DllClose($U32)
MsgBox(4144,"",$Test)
EndSwitch
WEnd
Func Compare($Pic1, $Pic2, $Width, $Height)
Local $Color[$Width + 1][$Height + 1], $Color2[$Width + 1][$Height + 1], $Var = 0
$Test = GUICreate("", $Width, $Height, -1, -1, $WS_POPUP,$WS_EX_TOPMOST)
GUISetState()
$Pic = GUICtrlCreatePic($Pic1, "", "", $Width, $Height)
For $y = 1 To $Height
For $x = 1 To $Width
$Color[$x][$y] = PixelGetColor($x, $y)
Next
Next
GUICtrlSetImage($Pic, $Pic2)
For $y = 1 To $Height
For $x = 1 To $Width
$Color2[$x][$y] = PixelGetColor($x, $y)
If $Color[$x][$y] = $Color2[$x][$y] Then
$Var += 1
Else
dibujar($x,$y)
EndIf
Next
Next
$Need = $Height * $Width
$Result = ($Var / $Need) * 100
;~ GUIDelete($Test)
Return Round($Result, 1) & "%" & $Var
EndFunc ;==>Compares
Func dibujar($nX,$nY)
$hand = DllCall($U32,"int", "GetDC", "hwnd",GUICtrlGetHandle($Pic)); 0)
$pen = DllCall($GDI, "int", "CreatePen", "int", 0 , "int",2, "int", $Color)
DllCall($GDI, "int", "SelectObject", "int", $hand, "int", $pen)
DllCall($GDI, "int", "MoveToEx", "hwnd", $hand, "int",$nX, "int", $nY, "int", 0)
DllCall($GDI, "int", "LineTo", "hwnd", $hand, "int", $nX, "int", $nY)
EndFunc
楼主能否提供个示例文件测试阿福前辈有一个作品是找图的我改了点东西作为他用 不知道是否适用于楼主的需求。 回复 3# zch11230
请教 一下
因为有背景的问题,是否可以做相似度来找图,即和原图达85%的相似度之类,来用识别数字和英文, 回复 4# auto
可以使用大漠插件……找图找字找色挺好使的 回复 5# cumtljj
有没有实际使用的例子??? {:face (327):} 回复 6# auto
可以在论坛搜索 本帖最后由 cumtljj 于 2014-6-20 12:47 编辑
图片为bmp就行了 插件百度一下吧
$dll_path=@ScriptDir & '\dm.dll'
Global $DM = _RegDM($dll_path)
If IsObj($DM) Then
$ver = $DM.Ver()
;~ MsgBox(0,0,'> 插件版本:' & $ver & @CRLF)
Else
MsgBox(64, '提示:', '注册大漠插件失败!!!')
Exit
EndIf
Func _RegDM($dll_path)
Local $obj = ObjCreate("dm.dmsoft")
If Not IsObj($obj) Then
RunWait(@ComSpec & ' /c regsvr32 /s ' & FileGetShortName($dll_path), '', @SW_HIDE)
$obj = ObjCreate("dm.dmsoft")
EndIf
Return $obj
EndFunc
;********************************以上是注册插件命令,需要使用时,直接复制上面的代码即可**********
;~ ;屏幕识别
Local $i ,$b,$c
$a=TimerInit()
$i=$dm.findpicE(0,0,@DesktopWidth,@DesktopHeight,"C:\Documents and Settings\Administrator\桌面\1.bmp",000000,1,0)
$c=StringSplit($i,"|")
If$c>=0 Then
$b=TimerDiff($a)
MouseMove($c,$c)
MsgBox(0,0,'找到啦'&@CRLF&"找图总用时:"&$b&@CRLF&"坐标:"&$c&","&$c)
Else
MsgBox(16,'错误',"没有匹配的图",3)
EndIf
回复 6# auto 回复 9# cumtljj
win8 ,注册显示成功,但是绑定窗口失败。参数换了好几个,就没有成功过 回复 10# auto
绑定什么窗口?这个不需要什么绑定窗口啊? 还有就是大漠插件在win8上可能运行有问题
页:
[1]