函数:image.findImageInRegion 误差找图

优质
小牛编辑
130浏览
2023-12-01

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

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

函数方法

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

参数类型必填说明
pathuserdata将要寻找的图片文件名
x1number找图区域左上角顶点屏幕横坐标
y1number找图区域左上角顶点屏幕纵坐标
x2number找图区域右下角顶点屏幕横坐标
y2number找图区域右下角顶点屏幕纵坐标
deviationnumber相似度,范围:0 - 100,不写默认为 90,数字越大越不容易找到
返回值类型说明
x,ynumber找到的图片的左上角顶点坐标,如未找到则返回 -1,-1

函数用例

--全屏截图
img1 = image.snapshot()
path = "/sdcard/LuaBox/Projects/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 = image.findImageInRegion(path,0,0,110,110,100)
            if x~=-1 and x~=-1 then
                toast("x:"..x.."\r\n".."y:"..y,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

注意事项

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