Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 使用AutoIt进行图像搜索_Image_Ui Automation_Autoit - Fatal编程技术网

Image 使用AutoIt进行图像搜索

Image 使用AutoIt进行图像搜索,image,ui-automation,autoit,Image,Ui Automation,Autoit,我只是想用AutoIt做一个简单的ImageSearch脚本。但是我不能让它正常工作,即使我确定我搜索的图像在屏幕上 这是我的密码: #include <ImageSearch.au3> global $x , $y HotKeySet ("{F1}",StartScriptc) HotKeySet ("{F2}",StopScript) While 1 Sleep(200) WEnd Func StartScript

我只是想用AutoIt做一个简单的ImageSearch脚本。但是我不能让它正常工作,即使我确定我搜索的图像在屏幕上

这是我的密码:

#include <ImageSearch.au3>
global $x , $y
     
HotKeySet ("{F1}",StartScriptc)
HotKeySet ("{F2}",StopScript)
 
While 1
   Sleep(200)
WEnd
 
Func StartScriptc()
    ;WinActivate("MyWindow")
    FindPicture()
EndFunc
 
Func StopScript()
    Exit
EndFunc
    
Func FindPicture()
    While 1
        ConsoleWrite ("Before search" & @CRLF)
        $search =  _ImageSearch("test2.bmp",0,$x,$y,50)
        if $search = 1 Then
            ConsoleWrite ("Found it!" & @CRLF)
        Else
            ConsoleWrite ("Fail!" & @CRLF)
        EndIf
     WEnd
EndFunc
#包括
全球$x,$y
热键集(“{F1}”,StartScriptc)
热键集(“{F2}”,StopScript)
而1
睡眠(200)
温德
Func StartScriptc()
;WinActivate(“我的窗口”)
FindPicture()
EndFunc
Func StopScript()
出口
EndFunc
Func FindPicture()
而1
控制台写入(“搜索前”和@CRLF)
$search=_ImageSearch(“test2.bmp”,0,$x,$y,50)
如果$search=1,则
控制台写入(“找到了!”&@CRLF)
其他的
控制台写入(“失败!”&@CRLF)
恩迪夫
温德
EndFunc
当我运行这段代码时,我得到了“beforesearch”输出,但它从未传递到_ImageSearch()函数后面的行。相反,scipt刚刚结束(我猜是崩溃) 以下是我得到的输出:

搜查前

14:10:51 AutoIt3.exe结束。rc:-1073741819

14:10:51 Autoit3包装完成

退出代码:322225477时间:9.844

我不是ImageSearch.au3的作者,它来自。 我尝试了32位和64位版本,但都没有成功。我将DLL和ImageSearch脚本与.bmp文件和测试脚本放在同一个文件夹中

这个图像搜索库适合我

#包含一次
; ------------------------------------------------------------------------------
;
; AutoIt版本:3.0
; 语言:英语
; 描述:帮助图像搜索的功能
;                 要求ImageSearchDLL.dll是可加载的
;
; ------------------------------------------------------------------------------
;===============================================================================
;
; 描述:查找桌面上图像的位置
; 语法:_ImageSearchArea,_ImageSearch
; 参数:
;                   $findImage—要在桌面上定位的图像
;                   $公差-0表示无公差(0-255)。当颜色
;                                图像与桌面不同。e、 GIF
;                   $resultPosition-设置返回的图像的x,y位置。
;                                     1表示图像中心,0表示图像左上角
;                   $x$y-返回图像的x和y位置
;
; 返回值:成功时-返回1
;                   失败时-返回0
;
; 注意:使用_ImageSearch搜索整个桌面,使用_ImageSearch区域指定
;       要搜索的桌面区域
;
;===============================================================================
Func_ImageSearch($findImage,$resultPosition,ByRef$x,ByRef$y,$tolerance)
返回_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)
如果$tolerance>0,则$findImage=“*”&$tolerance&“”&$findImage
$result=DllCall(“ImageSearchDLL.dll”、“str”、“ImageSearch”、“int”、$x1、“int”、$y1、“int”、$right、“int”、$bottom、“str”、$findImage)
; 如果错误退出
如果$result[0]=“0”,则返回0
; 否则,获取匹配的x、y位置和要显示的图像大小
; 计算搜索中心
$array=StringSplit($result[0],“|”)
$x=Int(数字($array[2]))
$y=Int(数字($array[3]))
如果$resultPosition=1,则
$x=$x+Int(数字($array[4])/2)
$y=$y+Int(数字($array[5])/2)
恩迪夫
返回1
EndFunc
;===============================================================================
;
; 描述:等待指定的秒数,图像才会出现
;     
; 语法:_WaitForImageSearch,_WaitForImageSearch
; 参数:
;                   $waitSecs-尝试查找图像的秒数
;                   $findImage—要在桌面上定位的图像
;                   $公差-0表示无公差(0-255)。当颜色
;                                图像与桌面不同。e、 GIF
;                   $resultPosition-设置返回的图像的x,y位置。
;                                     1表示图像中心,0表示图像左上角
;                   $x$y-返回图像的x和y位置
;
; 返回值:成功时-返回1
;                   失败时-返回0
;
;
;===============================================================================
Func_WaitForImageSearch($findImage、$waitSecs、$resultPosition、ByRef$x、ByRef$y、$tolerance)
$waitSecs=$waitSecs*1000
$startTime=TimerInit()
而TimerDiff($startTime)<$waitSecs
睡眠(100)
$result=\u图像搜索($findImage,$resultPosition,$x,$y,$tolerance)
如果$result>0,则
返回1
恩迪夫
温德
返回0
EndFunc
;===============================================================================
;
; 描述:对一组数据中的任何一个等待指定的秒数
;                   要显示的图像
;     
; 语法:_waitforimagesearch
; 参数:
;                   $waitSecs-尝试查找图像的秒数
;                   $findImage—要在桌面上定位的图像数组
;                              - 数组[0]设置为要循环通过的图像数
;                                数组[1]是第一个映像
;                   $公差-0表示无公差(0-255)。当颜色
;                                图像与桌面不同。e、 GIF
;                   $resultPosition-设置返回的图像的x,y位置。
;                                     1表示图像中心,0表示图像左上角
;                   $x$y-返回图像的x和y位置
#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