匹配绑定窗口图片7 - MatchWindowsThresholdFromPathAll
函数简介
二值化后匹配所有符合模板图片的坐标,模板通过文件路径指定,返回相对绑定窗口坐标。
接口名称
MatchWindowsThresholdFromPathAll
DLL调用
long MatchWindowsThresholdFromPathAll(long ola, int x1, int y1, int x2, int y2, string colorJson, string templ, double matchVal, double angle, double scale);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| x1 | 整数型 | 查找区域的左上角X坐标 |
| y1 | 整数型 | 查找区域的左上角Y坐标 |
| x2 | 整数型 | 查找区域的右下角X坐标 |
| y2 | 整数型 | 查找区域的右下角Y坐标 |
| colorJson | 字符串 | 颜色模型配置字符串,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:3278FA-000000|6496FF-202020 或 3278FA~6496FF 或 FF0000|00FF00 |
| templ | 字符串 | 模板图片的路径,支持多个图片,用"|"分隔,如"test.bmp|test2.bmp|test3.bmp" |
| matchVal | 双精度浮点数 | 相似度阈值,范围0-1,如0.85表示85%相似度 |
| angle | 双精度浮点数 | 旋转角度,每次匹配后旋转指定角度继续匹配,角度越小匹配次数越多时间越长,0为不旋转速度最快 |
| scale | 双精度浮点数 | 窗口缩放比例,默认为1,可通过GetScaleFromWindows接口获取 |
示例
// 定义颜色范围
string colorJson = "[{\"StartColor\":\"3278FA\",\"EndColor\":\"6496FF\",\"Type\":0}]";
// 执行匹配
long ret = MatchWindowsThresholdFromPathAll(ola, 0, 0, 0, 0, colorJson, "test.bmp|test2.bmp", 0.85, 45.0, 1.0);
if (ret != 0) {
char* result = (char*)ret;
printf("匹配结果: %s\n", result);
FreeStringPtr(result);
}
返回值
字符串指针,返回JSON数组格式的匹配结果。DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。
返回数据格式:
[{
"MatchVal": 0.85,
"MatchState": true,
"Index": 0,
"Angle": 45.0,
"X": 100,
"Y": 200,
"Width": 100,
"Height": 100
}]
| 字段名 | 类型 | 说明 |
|---|---|---|
| MatchVal | 浮点数 | 匹配相似度。 |
| MatchState | 布尔 | 是否匹配成功。 |
| Index | 整数 | 结果索引(从 0 开始)。 |
| Angle | 浮点数 | 匹配角度。 |
| X | 整数 | X 坐标。 |
| Y | 整数 | Y 坐标。 |
| Width | 整数 | 宽度。 |
| Height | 整数 | 高度。 |
注意事项
- x1、y1、x2、y2都传0时,将搜索整个窗口客户区
- 返回的坐标是相对于绑定窗口客户区的坐标
