解析匹配图像多结果JSON - ParseMatchImageAllJson
函数简介
解析匹配图像JSON数组,获取指定索引的匹配结果详细信息。
接口名称
ParseMatchImageAllJson
DLL调用
int ParseMatchImageAllJson(string str, int parseIndex, int* matchState, int* x, int* y, double* matchVal, double* angle, int* index)
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| str | 字符串 | 匹配图像JSON字符串 |
| parseIndex | 整数型 | 解析索引(从0开始) |
| matchState | 整数型指针 | 输出:匹配状态 |
| x | 整数型指针 | 输出:匹配点X坐标 |
| y | 整数型指针 | 输出:匹配点Y坐标 |
| width | 整数型指针 | 输出:匹配图片高度 |
| height | 整数型指针 | 输出:匹配图片高度 |
| matchVal | 双精度指针 | 输出:匹配值 |
| angle | 双精度指针 | 输出:匹配角度 |
| index | 整数型指针 | 输出:匹配索引 |
示例
// 解析匹配图像JSON数组中的指定索引
const char* jsonStr = "[{\"MatchVal\":0.85,\"MatchState\":1,\"Index\":0,\"Angle\":45.0,,\"X\":50,,\"Y\":120,\"Width\":100,\"Height\":100},{\"MatchVal\":0.92,\"MatchState\":1,\"Index\":0,\"Angle\":0.0,,\"X\":50,,\"Y\":120,\"Width\":100,\"Height\":100}]";
// 获取匹配结果数量
int totalCount = GetMatchImageAllCount(jsonStr);
// 遍历所有匹配结果
for (int i = 0; i < totalCount; i++) {
int matchState = 0, x = 0, y = 0, index = 0,width=0,height=0;
double matchVal = 0.0, angle = 0.0;
int result = ParseMatchImageAllJson(jsonStr, i, &matchState, &x, &y,&width,&height, &matchVal, &angle, &index);
if (result == 1) {
printf("第%d个匹配结果:\n", i);
printf(" 匹配状态: %d\n", matchState);
printf(" 匹配坐标: (%d, %d)\n", x, y);
printf(" 匹配值: %.2f\n", matchVal);
printf(" 匹配角度: %.2f\n", angle);
printf(" 匹配索引: %d\n", index);
}
}
返回值
返回操作结果错误码:
1- 解析成功0- 解析失败
注意事项
- 用于解析JSON数组中的指定索引匹配结果
- parseIndex 参数从0开始计数
- 结合 GetMatchImageAllCount 使用可以遍历所有匹配结果
- 所有输出参数必须提供有效指针
