1361739590 发表于 2013-2-28 13:35:26

图片对比(已解决)

本帖最后由 1361739590 于 2013-3-6 11:23 编辑

有一张大图和一张小图,其实小图是从大图截取下来的,怎么能判断出大图中包含小图的图片,谢谢。
搜索没找到。

1361739590 发表于 2013-3-1 08:54:56

帮个忙{:face (229):}

1361739590 发表于 2013-3-1 08:54:58

帮个忙{:face (229):}

waynew 发表于 2013-3-1 09:37:16

不就是图像查找嘛,给LZ描述的这么纠结。

waynew 发表于 2013-3-1 09:39:40

#include-once
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with Image Search
;               Require that the ImageSearchDLL.dll be loadable
;
; ------------------------------------------------------------------------------

;===============================================================================
;
; Description:      Find the position of an image on the desktop
; Syntax:         _ImageSearchArea, _ImageSearch
; Parameter(s):
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                              image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):On Success - Returns 1
;                   On Failure - Returns 0
;
; Note: Use _ImageSearch to search the entire desktop, _ImageSearchArea to specify
;       a desktop region to search
;
;===============================================================================
Func _ImageSearch($findImage,$resultPosition,ByRef $x, ByRef $y,$tolerance)
   return _ImageSearchArea($findImage,$resultPosition,0,0,@DesktopWidth,@DesktopHeight,$x,$y,$tolerance)
EndFunc

Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
        ;MsgBox(0,"asd","" & $x1 & " " & $y1 & " " & $right & " " & $bottom)
        if $tolerance>0 then $findImage = "*" & $tolerance & " " & $findImage
        $result = DllCall("ImageSearchDLL.dll","str","ImageSearch","int",$x1,"int",$y1,"int",$right,"int",$bottom,"str",$findImage)

        ; If error exit
    if $result="0" then return 0

        ; Otherwise get the x,y location of the match and the size of the image to
        ; compute the centre of search
        $array = StringSplit($result,"|")

   $x=Int(Number($array))
   $y=Int(Number($array))
   if $resultPosition=1 then
      $x=$x + Int(Number($array)/2)
      $y=$y + Int(Number($array)/2)
   endif
   return 1
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for an image to appear
;
; Syntax:         _WaitForImageSearch, _WaitForImagesSearch
; Parameter(s):
;                                        $waitSecs- seconds to try and find the image
;                   $findImage - the image to locate on the desktop
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                              image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):On Success - Returns 1
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImageSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
        $waitSecs = $waitSecs * 1000
        $startTime=TimerInit()
        While TimerDiff($startTime) < $waitSecs
                sleep(100)
                $result=_ImageSearch($findImage,$resultPosition,$x, $y,$tolerance)
                if $result > 0 Then
                        return 1
                EndIf
        WEnd
        return 0
EndFunc

;===============================================================================
;
; Description:      Wait for a specified number of seconds for any of a set of
;                   images to appear
;
; Syntax:         _WaitForImagesSearch
; Parameter(s):
;                                        $waitSecs- seconds to try and find the image
;                   $findImage - the ARRAY of images to locate on the desktop
;                              - ARRAY is set to the number of images to loop through
;                                                               ARRAY is the first image
;                   $tolerance - 0 for no tolerance (0-255). Needed when colors of
;                              image differ from desktop. e.g GIF
;                   $resultPosition - Set where the returned x,y location of the image is.
;                                     1 for centre of image, 0 for top left of image
;                   $x $y - Return the x and y location of the image
;
; Return Value(s):On Success - Returns the index of the successful find
;                   On Failure - Returns 0
;
;
;===============================================================================
Func _WaitForImagesSearch($findImage,$waitSecs,$resultPosition,ByRef $x, ByRef $y,$tolerance)
        $waitSecs = $waitSecs * 1000
        $startTime=TimerInit()
        While TimerDiff($startTime) < $waitSecs
                for $i = 1 to $findImage
                  sleep(100)
                  $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
                  if $result > 0 Then
                          return $i
                  EndIf
                Next
        WEnd
        return 0
EndFunc

waynew 发表于 2013-3-1 09:40:54

上面代码的出处:http://www.autoitscript.com/forum/topic/148005-imagesearch-usage-explanation/page__view__findpost__p__1054372__hl__%2B_imagesearcharea

waynew 发表于 2013-3-1 09:41:10

不用感谢我,我是雷锋。

mbdnmt 发表于 2013-3-3 01:47:14

回复 5# waynew


    还需要一个dll文件才能用的吧?

1361739590 发表于 2013-3-4 09:58:11

回复 5# waynew


   需要 ImageSearchDLL.dll 的吧

1361739590 发表于 2013-3-6 10:17:31

回复 7# waynew


    谢谢Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
里面参数$resultPositionByRef $x, ByRef $y, $tolerance 是什么意思?

1361739590 发表于 2013-3-6 11:25:21

回复 6# waynew


    谢谢{:face (411):}

1361739590 发表于 2013-3-6 11:25:36

回复 5# waynew


    谢谢{:face (411):}

1361739590 发表于 2013-3-6 11:25:59

回复 8# mbdnmt


    谢谢需要 ImageSearchDLL.dll

1361739590 发表于 2013-3-6 11:27:55

不知道这个找图方法消耗的时间是多少。
页: [1]
查看完整版本: 图片对比(已解决)