找回密码
 加入
搜索
查看: 4836|回复: 13

[图形处理] 图片对比(已解决)

[复制链接]
发表于 2013-2-28 13:35:26 | 显示全部楼层 |阅读模式
本帖最后由 1361739590 于 2013-3-6 11:23 编辑

有一张大图和一张小图,其实小图是从大图截取下来的,怎么能判断出大图中包含小图的图片,谢谢。
搜索没找到。
 楼主| 发表于 2013-3-1 08:54:56 | 显示全部楼层
帮个忙
 楼主| 发表于 2013-3-1 08:54:58 | 显示全部楼层
帮个忙
发表于 2013-3-1 09:37:16 | 显示全部楼层
不就是图像查找嘛,给LZ描述的这么纠结。
发表于 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]="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[0],"|")

   $x=Int(Number($array[2]))
   $y=Int(Number($array[3]))
   if $resultPosition=1 then
      $x=$x + Int(Number($array[4])/2)
      $y=$y + Int(Number($array[5])/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[0] is set to the number of images to loop through
;                                                                 ARRAY[1] 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[0]
                    sleep(100)
                    $result=_ImageSearch($findImage[$i],$resultPosition,$x, $y,$tolerance)
                    if $result > 0 Then
                            return $i
                    EndIf
                Next
        WEnd
        return 0
EndFunc
发表于 2013-3-1 09:40:54 | 显示全部楼层
发表于 2013-3-1 09:41:10 | 显示全部楼层
不用感谢我,我是雷锋。
发表于 2013-3-3 01:47:14 | 显示全部楼层
回复 5# waynew


    还需要一个dll文件才能用的吧?
 楼主| 发表于 2013-3-4 09:58:11 | 显示全部楼层
回复 5# waynew


   需要 ImageSearchDLL.dll 的吧
 楼主| 发表于 2013-3-6 10:17:31 | 显示全部楼层
回复 7# waynew


    谢谢  Func _ImageSearchArea($findImage,$resultPosition,$x1,$y1,$right,$bottom,ByRef $x, ByRef $y, $tolerance)
里面参数$resultPosition  ByRef $x, ByRef $y, $tolerance 是什么意思?
 楼主| 发表于 2013-3-6 11:25:21 | 显示全部楼层
回复 6# waynew


    谢谢
 楼主| 发表于 2013-3-6 11:25:36 | 显示全部楼层
回复 [url=http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&pid=509895&ptid=37481]5#[/url] waynew


    谢谢
 楼主| 发表于 2013-3-6 11:25:59 | 显示全部楼层
回复 8# mbdnmt


    谢谢  需要 ImageSearchDLL.dll
 楼主| 发表于 2013-3-6 11:27:55 | 显示全部楼层
不知道这个找图方法消耗的时间是多少。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 04:52 , Processed in 0.114258 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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