跳到主要内容

openCV图中找图(:cvFindImage)

函数

横坐标, 纵坐标 = 图片对象:cvFindImage(图片对象, [相似度], [起始横坐标, 起始纵坐标, 结束横坐标, 结束纵坐标])

参数

  • 图片对象 对象型

  • 相似度 整数型

    可选 默认 90 相似度范围 0 -100

  • 查找起始横坐标 整数型

    可选 默认 0

  • 查找起始纵坐标 整数型

    可选 默认 0

  • 查找结束横坐标 整数型

    可选 默认 屏幕宽度

  • 查找结束纵坐标 整数型

    可选 默认屏幕高度

返回值

  • 屏幕横坐标 整数型

    成功返回 屏幕横坐标 失败返回 -1

  • 屏幕纵坐标 整数型

    成功返回 屏幕纵坐标 失败返回 -1

说明

用于查找图片在另一张图片上的位置

该函数在 2.1.6 版本以上重新实现

示例

--简单的示例 从屏幕创建图片对象
local imgObj = screen.image() --全屏截图

local img = screen.image(100,100,200,200) --随便截个图 用来测试找图
local x ,y = imgObj:cvFindImage(img) --全屏找图
if x ~= -1 and y ~= -1 then
print(string.format("成功找到图片拉坐标: x= %d, y= %d" ,x ,y))
end

--另一个示例 从图片文件加载图片对象
local x ,y = imgObj:cvFindImage(screen.loadImageFile("/var/mobile/Media/test.png"))--全屏找图
if x ~= -1 and y ~= -1 then
print(string.format("成功找到图片拉坐标: x= %d, y= %d" ,x ,y))
end


--另一个示例 从图片文件加载图片对象
local x ,y = imgObj:cvFindImage(screen.loadImageFile("/var/mobile/Media/test.png") , 90
100,100,400,600 ) --范围找图 且相似度为 90
if x ~= -1 and y ~= -1 then
print(string.format("成功找到图片拉坐标: x= %d, y= %d" ,x ,y))
end