L版本实现多线程找图

多线程找图:原理与使用说明 本示例演示如何使用 AutoHotkey L 版本 (支持原生多线程的 AHK 分支)实现「多张图片批量找图」。

多线程找图:原理与使用说明

本示例演示如何使用 AutoHotkey L 版本(支持原生多线程的 AHK 分支)实现「多张图片批量找图」。核心思路是借助 pic_search_mutithread 库,把每张待查找图片分派到独立线程并行匹配,从而大幅提升在屏幕大范围内同时查找多张目标图像的效率与响应速度。

使用流程:先用 FileSelectFile 一次性选择多张 BMP 图片(路径与图片名不能含下划线);随后按提示按住左键拖选查找区域(GetRange 返回 x/y/w/h);脚本会在该选区内并行执行 pic_search_debug 逐一比对,最终通过 obj2json 输出每张图片的查找坐标与耗时。

关键参数:thresh 为匹配相似度阈值(示例取 100),值越低匹配越严格;CoordMode, Mouse, Screen 保证拖选区域使用屏幕坐标。

AHK v1/v2 说明:本文代码为 AHK v1(L 版)语法。迁移到 AutoHotkey v2 时需注意:FileSelectFile 返回对象而非字符串、StringTrimRight 改用 RTrim()、%var% 拼接改为表达式写法;并且 v2 默认即支持多线程并发,部分场景可直接用并发替代此库。

链接:https://pan.baidu.com/s/1RaUghMhz1p0InQL4rycRng 
提取码:9xjf 

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
CoordMode, Mouse, Screen  ; 把 ToolTips 放置在相对于屏幕坐标的位置.
#include <pic_search_mutithread>
MsgBox,选择需要查找的图片,bmp格式
FileSelectFile, files, M3  ; M3 = 选择多个现有文件,路径和图片名字不能有"_"".
if (files = "")
{
    MsgBox, The user pressed cancel.
    return
}
string_path := ""
Loop, parse, files, `n
{
    if (A_Index = 1)
    {
        root_path := A_LoopField
    }
    else
    {
        string_path := root_path . "" . A_LoopField . "*" . string_path
    }
}
StringTrimRight, string_path, string_path, 1
MsgBox,% string_path
MsgBox,按住左键拖动选取查找范围
Sleep,200
MsgBox, 4096,, % GetRange(x,y,w,h) "范围:" x "," y "," w "," h
picPath := string_path
x1 := x
y1 := y
x2 := x+w
y2 := y+h
thresh := 100
obj := {}
pic_search_debug(picPath, x1, y1, x2, y2, time, obj, thresh)
MsgBox,% obj2json(obj)
return
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA捐赠
共{{data.count}}人
人已捐赠
应用

开源 中文 热榜工具 不出茅庐便知三分天下 双击鼠标能吃全网新瓜~

2021-6-19 16:32:51

教程

自己写的一个固话自动拨号程序,分享出来

2021-7-8 14:47:41

6 条回复 A文章作者 M管理员
  1. user14586

    先试一下

  2. 。13530

    你好 我想問下ahk怎麼實現後台取色

  3. awen162

    下载来试试

  4. longlongago

    厉害了 我的哥

  5. 415075065

    试了一下 好用

    • ahker

      pic_search_debug(picPath, x1, y1, x2, y2, time, obj, thresh)
      正式使用的时候,改用pic_search(picPath, x1, y1, x2, y2, time, obj, thresh)

❯
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索