函数:image.findImageInRegion 误差找图

函数功能:在指定区域中,寻找指定的图案,返回其左上角顶点坐标

引擎版本:仅支持 v1.0.3 及其以上版本

函数方法

x,y = image.findImage(path,x1,y1,x2,y2,deviation)

参数 类型 必填 说明
path userdata 将要寻找的图片文件名,
支持相对路径及决定路径
x1 number 找图区域左上角顶点屏幕横坐标
y1 number 找图区域左上角顶点屏幕纵坐标
x2 number 找图区域右下角顶点屏幕横坐标
y2 number 找图区域右下角顶点屏幕纵坐标
deviation number 不写或者小于 0 默认为 500000,
数字越大越容易找到,
但准确度也会随之降低
返回值 类型 说明
x,y number 找到的图片的左上角顶点坐标,如未找到则返回 -1,-1
ret number 图片匹配偏差度

函数用例

--相对路径表示当前流程文件夹:/sdcard/LuaBox/Projects/流程名称/
--积木编程端口号为 50007,发送 IDE 的工程默认会将图片文件发送到当前流程文件夹下
--表示当前流程文件夹下的 ceshi.png 文件
path = "ceshi.png"
--判断文件是否存在
flag = file.isExist(path)
if  flag then
    toast("图片存在",5)
    mSleep(3000)
    x,y,ret = image.findImageInRegion(path,0,0,100,100)
    if x~=-1 and x~=-1 then
        toast("x:"..x.."\r\n".."y:"..y,5)
        mSleep(2000)
        toast("相似度:"..ret,5)
        mSleep(2000)
    else
        toast("未找到",5)
        mSleep(2000)

    end
else
    toast("图片不存在",5)
    mSleep(3000)
end
--全屏截图
img1 = image.snapshot()
path = "/sdcard/LuaBox/Projects/1/ceshi.png"
if  img1 ~= nil then
    --裁剪
    img2=image.crop(img1,10, 10, 100, 100)
    if img2 then
        image.save(img2,path)
        mSleep(2000)
        --判断裁剪图片是否存在
        flag = file.isExist(path)
        if  flag then
            x,y,ret = image.findImageInRegion(path,0,0,110,110)
            if x~=-1 and x~=-1 then
                toast("x:"..x.."\r\n".."y:"..y,5)
                mSleep(2000)
                toast("相似度:"..ret,5)
                mSleep(2000)
            else
                toast("未找到",5)
                mSleep(2000)

            end
        else
          toast("保存文件失败,文件不存在",5)
          mSleep(2000)
        end
    else
        toast("裁剪失败",5)
        mSleep(2000)
    end
else
    toast("截屏失败",5)
    mSleep(2000)
end

注意事项

  • 查找的图片支持使用 QQ、微信及手机自带截图软件等软件裁剪出来的图。

  • 目前积木编程函数和触动精灵函数不通用,请仔细查看本手册,此手册中函数仅支持积木编程,不支持触动精灵,同理请勿将触动精灵函数在积木编程运行。

Copyright 北京帮你玩科技有限公司 2022 all right reserved,powered by Gitbook该文章修订时间: 2023-08-09 17:19:31

results matching ""

    No results matching ""