找回密码
 加入
搜索
查看: 8921|回复: 11

[图形处理] 图片比较,结果输出

  [复制链接]
发表于 2014-6-19 16:58:24 | 显示全部楼层 |阅读模式
我要比较两个图片内容是否一样,之前看到前辈写的代码,可是怎么没有对比结果显示呢,这部分应该怎么写
 楼主| 发表于 2014-6-19 16:58:45 | 显示全部楼层
#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[0], "int", $pen[0])
    DllCall($GDI, "int", "MoveToEx", "hwnd", $hand[0], "int",$nX, "int", $nY, "int", 0)
    DllCall($GDI, "int", "LineTo", "hwnd", $hand[0], "int", $nX, "int", $nY)
EndFunc
发表于 2014-6-19 20:09:22 | 显示全部楼层
楼主能否提供个示例文件测试  阿福前辈有一个作品是找图的  我改了点东西作为他用 不知道是否适用于楼主的需求。
发表于 2014-6-19 21:28:23 | 显示全部楼层
回复 3# zch11230

请教 一下
    因为有背景的问题,是否可以做相似度来找图,即和原图达85%的相似度之类,来用识别数字和英文,
发表于 2014-6-19 22:32:29 | 显示全部楼层
回复 4# auto


    可以使用大漠插件……找图找字找色挺好使的
发表于 2014-6-19 22:39:09 | 显示全部楼层
回复 5# cumtljj


    有没有实际使用的例子???
发表于 2014-6-19 23:48:21 | 显示全部楼层
发表于 2014-6-20 12:07:52 | 显示全部楼层
回复 6# auto


    可以在论坛搜索
发表于 2014-6-20 12:46:13 | 显示全部楼层
本帖最后由 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[1]>=0 Then
        $b=TimerDiff($a) 
                MouseMove($c[2],$c[3])
        MsgBox(0,0,'找到啦'&@CRLF&"找图总用时:"&$b&@CRLF&"坐标:"&$c[2]&","&$c[3])
      
Else
        MsgBox(16,'错误',"没有匹配的图",3)
EndIf
回复 6# auto
发表于 2014-6-20 13:00:11 | 显示全部楼层
回复 9# cumtljj


    win8 ,注册显示成功,但是绑定窗口失败。参数换了好几个,就没有成功过
发表于 2014-6-20 17:23:56 | 显示全部楼层
回复 10# auto


    绑定什么窗口?这个不需要什么绑定窗口啊? 还有就是大漠插件在win8上可能运行有问题
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-7 00:22 , Processed in 0.086377 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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