ms-types 0.10.8 → 0.10.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/types/lua/action.lua +119 -89
- package/types/lua/ai.lua +34 -16
- package/types/lua/appleocr.lua +35 -22
- package/types/lua/cloud.lua +25 -12
- package/types/lua/config.lua +18 -11
- package/types/lua/cryptoUtils.lua +35 -27
- package/types/lua/cv.lua +173 -25
- package/types/lua/device.lua +38 -20
- package/types/lua/dotocr.lua +8 -2
- package/types/lua/file.lua +61 -40
- package/types/lua/global.lua +56 -20
- package/types/lua/hid.lua +147 -101
- package/types/lua/hotupdate.lua +25 -3
- package/types/lua/http.lua +71 -41
- package/types/lua/image.lua +222 -98
- package/types/lua/ime.lua +37 -13
- package/types/lua/logger.lua +22 -12
- package/types/lua/media.lua +54 -14
- package/types/lua/mysql.lua +61 -12
- package/types/lua/netcard.lua +25 -11
- package/types/lua/node.lua +4 -2
- package/types/lua/paddleocr.lua +35 -21
- package/types/lua/pip.lua +30 -18
- package/types/lua/system.lua +112 -31
- package/types/lua/tomatoocr.lua +73 -26
- package/types/lua/tts.lua +26 -10
- package/types/lua/ui.lua +35 -14
- package/types/lua/utils.lua +27 -17
- package/types/lua/yolo.lua +25 -17
- package/types/lua/yolocls.lua +27 -18
package/types/lua/tomatoocr.lua
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- TomatoOCR模块
|
|
2
3
|
---@class TomatoOCR
|
|
3
4
|
local _TomatoOCR = {}
|
|
4
5
|
|
|
@@ -10,74 +11,120 @@ local _TomatoOCR = {}
|
|
|
10
11
|
---@field versionName string 版本名称
|
|
11
12
|
|
|
12
13
|
--- 初始化 TomatoOCR 并设置基本配置
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
---@param mode string 运行模式 debug:调试模型;删除或传别的任何值为正式模式
|
|
15
|
+
---@param licenseData string 授权码 请传入你在 TomatoOCR 官网申请的授权码
|
|
16
|
+
---@param remark string|nil 备注信息(可选)
|
|
17
|
+
---@return TomatoInitResult|nil 设置结果
|
|
18
|
+
---@example -- 不带备注
|
|
19
|
+
--- local result1 = tomatoocr.initializeWithConfig("online", "授权码")
|
|
20
|
+
--- -- 带备注
|
|
21
|
+
--- local result2 = tomatoocr.initializeWithConfig("online", "授权码", "测试环境")
|
|
22
|
+
--- logi(result1, result2)
|
|
17
23
|
function _TomatoOCR.initializeWithConfig(mode, licenseData, remark) return nil end
|
|
18
24
|
|
|
19
25
|
--- 设置HTTP间隔
|
|
20
|
-
|
|
26
|
+
---@param v number 间隔秒数 设置网络请求间隔时间,非必设置。0-86400
|
|
27
|
+
---@example tomatoocr.setHttpIntervalTime(3600)
|
|
21
28
|
function _TomatoOCR.setHttpIntervalTime(v) end
|
|
22
29
|
|
|
23
30
|
--- 设置识别类型
|
|
24
|
-
|
|
31
|
+
---@param s string 识别类型 模型类型,默认 ch-3.0,除此之外还有 ch-2.0, ch, cht, japan, korean, number
|
|
32
|
+
---@example -- 普通中英文识别,3.0版模型
|
|
33
|
+
--- tomatoocr.setRecType("ch-3.0")
|
|
34
|
+
--- -- 普通中英文识别,2.0版模型
|
|
35
|
+
--- tomatoocr.setRecType("ch-2.0")
|
|
36
|
+
--- -- 普通中英文识别,1.0版模型
|
|
37
|
+
--- tomatoocr.setRecType("ch")
|
|
38
|
+
--- -- 繁体
|
|
39
|
+
--- tomatoocr.setRecType("cht")
|
|
40
|
+
--- -- 日语
|
|
41
|
+
--- tomatoocr.setRecType("japan")
|
|
42
|
+
--- -- 韩语
|
|
43
|
+
--- tomatoocr.setRecType("korean")
|
|
44
|
+
--- -- 数字模型
|
|
45
|
+
--- tomatoocr.setRecType("number")
|
|
25
46
|
function _TomatoOCR.setRecType(s) end
|
|
26
47
|
|
|
27
48
|
--- 设置检测框类型
|
|
28
|
-
|
|
49
|
+
---@param s string 检测框类型 默认"rect": 由于手机上截图文本均为矩形文本;"quad":可准确检测倾斜文本
|
|
50
|
+
---@example -- 矩形文本
|
|
51
|
+
--- tomatoocr.setDetBoxType("rect")
|
|
52
|
+
--- -- 倾斜文本
|
|
53
|
+
--- tomatoocr.setDetBoxType("quad")
|
|
29
54
|
function _TomatoOCR.setDetBoxType(s) end
|
|
30
55
|
|
|
31
56
|
--- 设置检测框展开比例
|
|
32
|
-
|
|
57
|
+
---@param v number 设置检测模型框选文本范围大小的参数,非必设置,默认为1.9。值范围1.6-2.5之间,值越大框选范围越大,值越小框选范围越小;当框选到了,但识别得分较低,就可以调整该参数改善准确率。
|
|
58
|
+
---@example tomatoocr.setDetUnclipRatio(1.9)
|
|
33
59
|
function _TomatoOCR.setDetUnclipRatio(v) end
|
|
34
60
|
|
|
35
61
|
--- 设置检测框缩放比例
|
|
36
|
-
|
|
62
|
+
---@param v number 检测框缩放比例
|
|
63
|
+
---@example tomatoocr.setDetScaleRatio(1.2)
|
|
37
64
|
function _TomatoOCR.setDetScaleRatio(v) end
|
|
38
65
|
|
|
39
66
|
--- 设置识别分数阈值
|
|
40
|
-
|
|
67
|
+
---@param v number 设置识别模型过滤得分的参数,非必设置,默认0.1。由于返回的识别结果数据太多太乱,可以通过设置该参数,过滤一些得分较低不准的数据,使得结果看起来更加简练。
|
|
68
|
+
---@example tomatoocr.setRecScoreThreshold(0.1)
|
|
41
69
|
function _TomatoOCR.setRecScoreThreshold(v) end
|
|
42
70
|
|
|
43
71
|
--- 设置返回类型
|
|
44
|
-
|
|
72
|
+
---@param s string 设置调用插件识别返回格式的参数,非必设置,默认为json。默认"json": 包含得分、坐标和文字;"text":纯文字;"num":纯数字;自定义输入想要返回的文本:".¥1234567890",仅只返回这些内容
|
|
73
|
+
---@example tomatoocr.setReturnType("json")
|
|
45
74
|
function _TomatoOCR.setReturnType(s) end
|
|
46
75
|
|
|
47
76
|
--- 设置二值化阈值
|
|
48
|
-
|
|
77
|
+
---@param v number 设置图像二值化的参数,非必设置,默认0,不进行二值化。 二值化设定0-255,常规情况下不需要设置,可配合中调试应用使用。
|
|
78
|
+
---@example tomatoocr.setBinaryThresh(0)
|
|
49
79
|
function _TomatoOCR.setBinaryThresh(v) end
|
|
50
80
|
|
|
51
81
|
--- 设置运行模式
|
|
52
|
-
|
|
82
|
+
---@param s string 运行模式
|
|
83
|
+
---@example tomatoocr.setRunMode("fast")
|
|
53
84
|
function _TomatoOCR.setRunMode(s) end
|
|
54
85
|
|
|
55
86
|
--- 设置图像滤色参数
|
|
56
|
-
|
|
57
|
-
|
|
87
|
+
---@param filterColor string 颜色过滤,通过逗号相互连,第一个是颜色值,第二个是负偏色,第三个是正偏色;不同颜色之间以"|"连接
|
|
88
|
+
---@param backgroundColor string 滤色后的背景色,传""或black的时候,背景是黑色,传“white”的时候,背景是白色
|
|
89
|
+
---@example tomatoocr.setFilterColor("#41917A,38,38", "black")
|
|
90
|
+
--- tomatoocr.setFilterColor("#41917A,38,38|#E091A8,50,50", "white")
|
|
58
91
|
function _TomatoOCR.setFilterColor(filterColor, backgroundColor) end
|
|
59
92
|
|
|
60
93
|
--- OCR识别
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
94
|
+
---@param input string 输入源(imageId、URL字符串、文件路径或"screen","screen"表示使用当前屏幕)
|
|
95
|
+
---@param type integer 识别类型 默认3: 检测 + 识别;0: 只检测;1: 方向分类+识别;2: 只识别;3: 检测+识别
|
|
96
|
+
---@param x integer 边界框左上角x坐标
|
|
97
|
+
---@param y integer 边界框左上角y坐标
|
|
98
|
+
---@param ex integer 边界框右下角x坐标
|
|
99
|
+
---@param ey integer 边界框右下角y坐标
|
|
100
|
+
---@return string OCR识别结果JSON字符串
|
|
101
|
+
---@example -- 识别屏幕
|
|
102
|
+
--- local result1 = tomatoocr.ocrImage("screen", 0, 0, 0, 0, 0)
|
|
103
|
+
--- logi("识别屏幕结果:" .. result1)
|
|
104
|
+
--- -- 识别文件
|
|
105
|
+
--- local result2 = tomatoocr.ocrImage("/path/to/image.png", 0)
|
|
106
|
+
--- logi("识别文件结果:" .. result2)
|
|
107
|
+
--- -- 识别指定屏幕区域
|
|
108
|
+
--- local result3 = tomatoocr.ocrImage("screen", 0)
|
|
109
|
+
--- logi("识别指定屏幕区域结果:" .. result3)
|
|
68
110
|
function _TomatoOCR.ocrImage(input, type, x, y, ex, ey) return '' end
|
|
69
111
|
|
|
70
112
|
--- 查找点击点
|
|
71
|
-
|
|
72
|
-
|
|
113
|
+
---@param js string 要找的文字
|
|
114
|
+
---@return string 找“要找的文字”的中心点 没有找到返回空字符串
|
|
115
|
+
---@example local result = tomatoocr.findTapPoint('{"text": "确定"}')
|
|
116
|
+
--- logi(result)
|
|
73
117
|
function _TomatoOCR.findTapPoint(js) return '' end
|
|
74
118
|
|
|
75
119
|
--- 查找多个点击点
|
|
76
|
-
|
|
77
|
-
|
|
120
|
+
---@param js string 要找的文字
|
|
121
|
+
---@return string 找“要找的文字”的所有相匹配的中心点 没有找到返回空字符串
|
|
122
|
+
---@example local result = tomatoocr.findTapPoints('{"texts": ["确定", "取消"]}')
|
|
123
|
+
--- logi(result)
|
|
78
124
|
function _TomatoOCR.findTapPoints(js) return '' end
|
|
79
125
|
|
|
80
126
|
--- 释放已加载的 OCR 模型和内部资源
|
|
127
|
+
---@example tomatoocr.release()
|
|
81
128
|
function _TomatoOCR.release() end
|
|
82
129
|
|
|
83
130
|
---@type TomatoOCR
|
package/types/lua/tts.lua
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- TTS(文本转语音)模块
|
|
2
3
|
---@class TTS
|
|
3
4
|
local _TTS = {}
|
|
4
5
|
|
|
@@ -9,34 +10,49 @@ local _TTS = {}
|
|
|
9
10
|
---@field quality integer 质量等级
|
|
10
11
|
|
|
11
12
|
--- 说话
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
---@param text string 要转换的文本
|
|
14
|
+
---@param rate number|nil 语速,范围0.0-1.0,默认0.5
|
|
15
|
+
---@param pitch number|nil 音调,范围0.5-2.0,默认1.0
|
|
16
|
+
---@param volume number|nil 音量,范围0.0-1.0,默认1.0
|
|
17
|
+
---@param lang string|nil 语言代码,默认"zh-CN"
|
|
18
|
+
---@return boolean 是否成功开始播放
|
|
19
|
+
---@example local success = tts.speak("你好世界", 0.5, 1.0, 1.0, "zh-CN")
|
|
18
20
|
function _TTS.speak(text, rate, pitch, volume, lang) return true end
|
|
19
21
|
|
|
20
22
|
--- 等待结束
|
|
23
|
+
---@example tts.waitEnd()
|
|
21
24
|
function _TTS.waitEnd() end
|
|
22
25
|
|
|
23
26
|
--- 停止
|
|
27
|
+
---@example tts.stop()
|
|
24
28
|
function _TTS.stop() end
|
|
25
29
|
|
|
26
30
|
--- 是否正在说话
|
|
27
|
-
|
|
31
|
+
---@return boolean 是否正在播放
|
|
32
|
+
---@example if tts.isSpeaking() then
|
|
33
|
+
--- logi("正在播放")
|
|
34
|
+
--- end
|
|
28
35
|
function _TTS.isSpeaking() return false end
|
|
29
36
|
|
|
30
37
|
--- 设置声音
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
---@param voice string 语音标识符
|
|
39
|
+
---@return boolean 是否设置成功
|
|
40
|
+
---@example local success = tts.setVoice("com.apple.ttsbundle.siri_Yu-shu_zh-CN_compact")
|
|
41
|
+
--- if success then
|
|
42
|
+
--- logi("语音设置成功")
|
|
43
|
+
--- end
|
|
33
44
|
function _TTS.setVoice(voice) return true end
|
|
34
45
|
|
|
35
46
|
--- 获取可用的语音列表
|
|
36
|
-
|
|
47
|
+
---@return VoiceInfo[] 语音信息数组
|
|
48
|
+
---@example local voices = tts.getAvailableVoices()
|
|
49
|
+
--- for _, voice in ipairs(voices) do
|
|
50
|
+
--- logi("语音: " .. voice.name .. ", 语言: " .. voice.language)
|
|
51
|
+
--- end
|
|
37
52
|
function _TTS.getAvailableVoices() return {} end
|
|
38
53
|
|
|
39
54
|
--- 释放 TTS 资源
|
|
55
|
+
---@example tts.free()
|
|
40
56
|
function _TTS.free() end
|
|
41
57
|
|
|
42
58
|
---@type TTS
|
package/types/lua/ui.lua
CHANGED
|
@@ -1,46 +1,67 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- UI模块
|
|
2
3
|
---@class UI
|
|
3
4
|
local _UI = {}
|
|
4
5
|
|
|
5
6
|
--- 显示WebView
|
|
7
|
+
---@example ui.show()
|
|
6
8
|
function _UI.show() end
|
|
7
9
|
|
|
8
10
|
--- 隐藏WebView
|
|
11
|
+
---@example ui.hide()
|
|
9
12
|
function _UI.hide() end
|
|
10
13
|
|
|
11
14
|
--- 显示Toast
|
|
12
|
-
|
|
15
|
+
---@param message string 提示消息内容
|
|
16
|
+
---@example ui.showToast("操作成功")
|
|
13
17
|
function _UI.showToast(message) end
|
|
14
18
|
|
|
15
19
|
--- 确认框
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
---@param title string 对话框标题
|
|
21
|
+
---@param message string 对话框内容
|
|
22
|
+
---@return boolean 用户选择结果,确定返回true,取消返回false
|
|
23
|
+
---@example local result = ui.confirm("确认", "是否继续操作?")
|
|
24
|
+
--- if result then
|
|
25
|
+
--- logi("用户点击了确定")
|
|
26
|
+
--- else
|
|
27
|
+
--- logi("用户点击了取消")
|
|
28
|
+
--- end
|
|
19
29
|
function _UI.confirm(title, message) return false end
|
|
20
30
|
|
|
21
31
|
--- 输入框
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
---@param title string 对话框标题
|
|
33
|
+
---@param message string 对话框内容
|
|
34
|
+
---@return string 用户输入的内容,取消返回空字符串
|
|
35
|
+
---@example local input = ui.confirmInput("输入", "请输入您的姓名:")
|
|
36
|
+
--- if input then
|
|
37
|
+
--- logi("用户输入了:" .. input)
|
|
38
|
+
--- else
|
|
39
|
+
--- logi("用户取消了输入")
|
|
40
|
+
--- end
|
|
25
41
|
function _UI.confirmInput(title, message) return '' end
|
|
26
42
|
|
|
27
43
|
--- 警告框
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
---@param title string 对话框标题
|
|
45
|
+
---@param message string 对话框内容
|
|
46
|
+
---@example ui.alert("警告", "操作失败,请重试!")
|
|
30
47
|
function _UI.alert(title, message) end
|
|
31
48
|
|
|
32
49
|
--- 事件监听
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
---@param callback UIEventCallback 事件回调函数,传入 null 会取消监听
|
|
51
|
+
---@example ui.onEvent(function(event, data)
|
|
52
|
+
--- logi("event: " .. event, data)
|
|
53
|
+
--- end)
|
|
35
54
|
function _UI.onEvent(callback) end
|
|
36
55
|
|
|
37
56
|
--- 调用已注册函数
|
|
38
|
-
|
|
39
|
-
|
|
57
|
+
---@param key string 函数名 registerUIFunc 注册的函数名
|
|
58
|
+
---@param data table<string, any> 传递的数据
|
|
59
|
+
---@example ui.call("jsMethod", { name = "快点JS" })
|
|
40
60
|
function _UI.call(key, data) end
|
|
41
61
|
|
|
42
62
|
--- 执行JS代码
|
|
43
|
-
|
|
63
|
+
---@param code string JavaScript代码字符串
|
|
64
|
+
---@example ui.eval("console.log('Hello from KuaiJS')")
|
|
44
65
|
function _UI.eval(code) end
|
|
45
66
|
|
|
46
67
|
---@type UI
|
package/types/lua/utils.lua
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- 工具模块
|
|
2
3
|
---@class Utils
|
|
3
4
|
local _Utils = {}
|
|
4
5
|
|
|
5
6
|
--- 时间格式化
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
---@param fmt string 格式化字符串
|
|
8
|
+
---@return string 格式化后的时间字符串
|
|
9
|
+
---@example utils.timeFormat("yyyy-MM-dd HH:mm:ss")
|
|
8
10
|
function _Utils.timeFormat(fmt) return '' end
|
|
9
11
|
|
|
10
12
|
--- 随机数
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
---@param min integer 最小值
|
|
14
|
+
---@param max integer 最大值
|
|
15
|
+
---@return integer 随机数
|
|
16
|
+
---@example utils.random(1, 10)
|
|
14
17
|
function _Utils.random(min, max) return 0 end
|
|
15
18
|
|
|
16
19
|
--- 把应用带到前台
|
|
17
|
-
|
|
20
|
+
---@return boolean 是否成功
|
|
21
|
+
---@example utils.takeMeToFront()
|
|
18
22
|
function _Utils.takeMeToFront() return false end
|
|
19
23
|
|
|
20
24
|
--- 生成随机 UUID
|
|
21
|
-
|
|
25
|
+
---@return string 随机UUID字符串
|
|
26
|
+
---@example utils.randomUUID()
|
|
22
27
|
function _Utils.randomUUID() return '' end
|
|
23
28
|
|
|
24
29
|
--- 字符串转小写 hex
|
|
25
|
-
|
|
26
|
-
|
|
30
|
+
---@param source string 字符串
|
|
31
|
+
---@return string hex字符串
|
|
32
|
+
---@example utils.hexString("hello")
|
|
27
33
|
function _Utils.hexString(source) return '' end
|
|
28
34
|
|
|
29
35
|
--- 字符串转 Base64
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
---@param source string 字符串
|
|
37
|
+
---@return string base64字符串
|
|
38
|
+
---@example utils.base64Encoded("hello")
|
|
32
39
|
function _Utils.base64Encoded(source) return '' end
|
|
33
40
|
|
|
34
41
|
--- Base64 转字符串
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
---@param source string base64字符串
|
|
43
|
+
---@return string 字符串
|
|
44
|
+
---@example utils.base64Decoded("aGVsbG8=")
|
|
37
45
|
function _Utils.base64Decoded(source) return '' end
|
|
38
46
|
|
|
39
47
|
--- hex 字符串转 Base64
|
|
40
|
-
|
|
41
|
-
|
|
48
|
+
---@param hexString string 16进制字符串
|
|
49
|
+
---@return string base64字符串
|
|
50
|
+
---@example utils.hexStringBase64Encoded("68656c6c6f")
|
|
42
51
|
function _Utils.hexStringBase64Encoded(hexString) return '' end
|
|
43
52
|
|
|
44
53
|
--- Base64 转 hex 字符串
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
---@param base64HexString string base64字符串
|
|
55
|
+
---@return string 16进制字符串
|
|
56
|
+
---@example utils.hexStringBase64Decoded("aGVsbG8=")
|
|
47
57
|
function _Utils.hexStringBase64Decoded(base64HexString) return '' end
|
|
48
58
|
|
|
49
59
|
---@type Utils
|
package/types/lua/yolo.lua
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- YOLO目标检测模块
|
|
2
3
|
---@class Yolo
|
|
3
4
|
local _Yolo = {}
|
|
4
5
|
|
|
@@ -15,32 +16,39 @@ local _Yolo = {}
|
|
|
15
16
|
---@field classId integer 类别 ID
|
|
16
17
|
|
|
17
18
|
--- 加载 YOLO 模型(版本 5/8/11/26)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
---@param paramPath string ncnn模型的param文件的绝对路径
|
|
20
|
+
---@param binPath string ncnn模型的bin文件绝对路径
|
|
21
|
+
---@param nc integer|nil 模型的标签数量;传 0 或省略时根据模型输出自动推断,显式传入但不匹配时检测返回空数组
|
|
22
|
+
---@param version integer|nil 模型版本,默认11, 支持 5 8 11 26。5 为官方 YOLOv5 6.0/6.2/7.0,兼容官方 export 单输出和三头原始特征
|
|
23
|
+
---@param useGpu boolean|nil 是否使用 GPU 加载
|
|
24
|
+
---@return string|nil 加载成功返回模型ID字符串,失败返回null
|
|
25
|
+
---@example local modelId = yolo.load("yolov8n.param", "yolov8n.bin", 0)
|
|
24
26
|
function _Yolo.load(paramPath, binPath, nc, version, useGpu) return nil end
|
|
25
27
|
|
|
26
28
|
--- 区域检测,坐标映射为原图/全屏绝对坐标
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
---@param id string 模型ID
|
|
30
|
+
---@param input string 图像ID,"screen"用当前屏幕检测,可以填入图像ID或者http图片地址或文件地址
|
|
31
|
+
---@param x integer 裁剪区域左上角 x 坐标,默认 0
|
|
32
|
+
---@param y integer 裁剪区域左上角 y 坐标,默认 0
|
|
33
|
+
---@param ex integer 裁剪区域右下角 x 坐标,默认 0
|
|
34
|
+
---@param ey integer 裁剪区域右下角 y 坐标,默认 0
|
|
35
|
+
---@param target integer|nil 图像进入后缩放的检测大小,模型训练一般都用640,因此这里的640一般不要改
|
|
36
|
+
---@param thr number|nil 置信度,默认0.4,小于这个值的会被过滤掉
|
|
37
|
+
---@param nms number|nil 重叠阈值,一般是0.5不需要更改
|
|
38
|
+
---@return YoloResult[] 检测结果数组,坐标为原图/全屏绝对坐标
|
|
39
|
+
---@example local results = yolo.detectAbs(modelId, "screen", 100, 100, 500, 400, 640, 0.4, 0.5)
|
|
40
|
+
--- if #results > 0 then
|
|
41
|
+
--- action.click(results[0].centerX, results[0].centerY)
|
|
42
|
+
--- end
|
|
37
43
|
function _Yolo.detectAbs(id, input, x, y, ex, ey, target, thr, nms) return {} end
|
|
38
44
|
|
|
39
45
|
--- 释放模型
|
|
40
|
-
|
|
46
|
+
---@param id string 模型ID
|
|
47
|
+
---@example yolo.free(modelId)
|
|
41
48
|
function _Yolo.free(id) end
|
|
42
49
|
|
|
43
50
|
--- 释放全部模型
|
|
51
|
+
---@example yolo.freeAll()
|
|
44
52
|
function _Yolo.freeAll() end
|
|
45
53
|
|
|
46
54
|
---@type Yolo
|
package/types/lua/yolocls.lua
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
---@meta
|
|
2
|
+
--- YOLO图像分类模块
|
|
2
3
|
---@class YoloCls
|
|
3
4
|
local _YoloCls = {}
|
|
4
5
|
|
|
@@ -10,42 +11,50 @@ local _YoloCls = {}
|
|
|
10
11
|
---@field top5conf number[] top5 对应的概率,顺序与 top5 一致
|
|
11
12
|
|
|
12
13
|
--- 加载 YOLO 分类模型
|
|
13
|
-
---@param paramPath string
|
|
14
|
-
---@param binPath string
|
|
15
|
-
---@param nc integer|nil
|
|
16
|
-
---@param useGpu boolean|nil
|
|
17
|
-
---@return string|nil
|
|
14
|
+
---@param paramPath string ncnn 模型 param 文件路径
|
|
15
|
+
---@param binPath string ncnn 模型 bin 文件路径
|
|
16
|
+
---@param nc integer|nil 模型类别数量,传 0 或省略时按模型输出自动推断,显式传入但不匹配时分类返回空结果
|
|
17
|
+
---@param useGpu boolean|nil 是否使用 GPU 加载
|
|
18
|
+
---@return string|nil 加载成功返回模型 ID 字符串,失败返回 null
|
|
19
|
+
---@example local modelId = yolocls.load("yolo11n_cls.ncnn.param", "yolo11n_cls.ncnn.bin", 1000, false)
|
|
18
20
|
function _YoloCls.load(paramPath, binPath, nc, useGpu) return nil end
|
|
19
21
|
|
|
20
22
|
--- 图像分类
|
|
21
|
-
---@param modelId string
|
|
22
|
-
---@param img string
|
|
23
|
-
---@param targetSize integer|nil
|
|
24
|
-
---@return YoloClsProbs
|
|
23
|
+
---@param modelId string 模型 ID
|
|
24
|
+
---@param img string 图像 ID,"screen" 使用当前屏幕,也可以填入图像 ID、HTTP 图片地址或文件路径
|
|
25
|
+
---@param targetSize integer|nil 分类输入大小,默认 224
|
|
26
|
+
---@return YoloClsProbs Ultralytics Probs 风格分类概率结果
|
|
27
|
+
---@example local result = yolocls.classify(modelId, "screen", 224)
|
|
28
|
+
--- if result.top1 ~= nil then
|
|
29
|
+
--- logi(result.top1 .. ": " .. result.top1conf)
|
|
30
|
+
--- end
|
|
25
31
|
function _YoloCls.classify(modelId, img, targetSize)
|
|
26
32
|
---@type YoloClsProbs
|
|
27
33
|
return { data = {}, top1 = nil, top5 = {}, top1conf = nil, top5conf = {} }
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
--- 对指定区域执行图像分类
|
|
31
|
-
---@param modelId string
|
|
32
|
-
---@param img string
|
|
33
|
-
---@param x integer|nil
|
|
34
|
-
---@param y integer|nil
|
|
35
|
-
---@param ex integer|nil
|
|
36
|
-
---@param ey integer|nil
|
|
37
|
-
---@param targetSize integer|nil
|
|
38
|
-
---@return YoloClsProbs
|
|
37
|
+
---@param modelId string 模型 ID
|
|
38
|
+
---@param img string 图像 ID,"screen" 使用当前屏幕,也可以填入图像 ID、HTTP 图片地址或文件路径
|
|
39
|
+
---@param x integer|nil 裁剪区域左上角 x 坐标,默认 0
|
|
40
|
+
---@param y integer|nil 裁剪区域左上角 y 坐标,默认 0
|
|
41
|
+
---@param ex integer|nil 裁剪区域右下角 x 坐标,默认 0
|
|
42
|
+
---@param ey integer|nil 裁剪区域右下角 y 坐标,默认 0
|
|
43
|
+
---@param targetSize integer|nil 分类输入大小,默认 224
|
|
44
|
+
---@return YoloClsProbs Ultralytics Probs 风格分类概率结果
|
|
45
|
+
---@example local result = yolocls.classifyRegion(modelId, "screen", 100, 100, 500, 400, 224)
|
|
39
46
|
function _YoloCls.classifyRegion(modelId, img, x, y, ex, ey, targetSize)
|
|
40
47
|
---@type YoloClsProbs
|
|
41
48
|
return { data = {}, top1 = nil, top5 = {}, top1conf = nil, top5conf = {} }
|
|
42
49
|
end
|
|
43
50
|
|
|
44
51
|
--- 释放指定模型
|
|
45
|
-
---@param modelId string
|
|
52
|
+
---@param modelId string 模型 ID
|
|
53
|
+
---@example yolocls.free(modelId)
|
|
46
54
|
function _YoloCls.free(modelId) end
|
|
47
55
|
|
|
48
56
|
--- 释放全部模型
|
|
57
|
+
---@example yolocls.freeAll()
|
|
49
58
|
function _YoloCls.freeAll() end
|
|
50
59
|
|
|
51
60
|
---@type YoloCls
|