主题
解析匹配图像多结果JSON - ParseMatchImageAllJson
函数简介
解析匹配图像JSON数组,获取指定索引的匹配结果详细信息。
接口名称
ParseMatchImageAllJsonDLL调用
c
int ParseMatchImageAllJson(string str, int parseIndex, int* matchState, int* x, int* y, int* width, int* height, double* matchVal, double* angle, int* index);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| str | 字符串 | 匹配图像JSON字符串。 |
| parseIndex | 整数型 | 解析索引(从0开始)。 |
| matchState | 整数型指针 | 输出:匹配状态。 |
| x | 整数型指针 | 输出:匹配点X坐标。 |
| y | 整数型指针 | 输出:匹配点Y坐标。 |
| width | 整数型指针 | 输出:匹配图片宽度。 |
| height | 整数型指针 | 输出:匹配图片高度。 |
| matchVal | 双精度浮点数指针 | 输出:匹配值。 |
| angle | 双精度浮点数指针 | 输出:匹配角度。 |
| index | 整数型指针 | 输出:匹配索引。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
const char* resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]";
int32_t matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
double matchVal = 0, angle = 0;
int32_t ret = ola.ParseMatchImageAllJson(resultJson, 0, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);
if (ret == 1) {
// 第 0 个匹配结果
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
string resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]";
int ret = ola.ParseMatchImageAllJson(resultJson, 0, out int matchState, out int x, out int y, out int width, out int height, out double matchVal, out double angle, out int index);
if (ret == 1)
{
// 第 0 个匹配结果
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
result_json = '[{"MatchState":true,"X":120,"Y":80,"Width":32,"Height":32,"MatchVal":0.95,"Angle":0,"Index":0},{"MatchState":true,"X":300,"Y":200,"Width":32,"Height":32,"MatchVal":0.88,"Angle":0,"Index":1}]'
ret, match_state, x, y, width, height, match_val, angle, index = ola.ParseMatchImageAllJson(result_json, 0)
if ret == 1:
pass # 第 0 个匹配结果java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
String resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]";
// 按 Java SDK 解析第 0 个匹配结果cpp
var ola = com("OlaPlug.OlaSoft")
var resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]"
var ret = ola.ParseMatchImageAllJson(resultJson, 0, matchState, x, y, width, height, matchVal, angle, index)vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
resultJson = "[{\""MatchState\"":true,\""X\"":120,\""Y\"":80,\""Width\"":32,\""Height\"":32,\""MatchVal\"":0.95,\""Angle\"":0,\""Index\"":0},{\""MatchState\"":true,\""X\"":300,\""Y\"":200,\""Width\"":32,\""Height\"":32,\""MatchVal\"":0.88,\""Angle\"":0,\""Index\"":1}]"
ret = ola.ParseMatchImageAllJson(resultJson, 0, matchState, x, y, width, height, matchVal, angle, index)text
.局部变量 ola, OLAPlug
ola.创建 ()
resultJson = “[{“MatchState“:true,“X“:120,“Y“:80,“Width“:32,“Height“:32,“MatchVal“:0.95,“Angle“:0,“Index“:0},{“MatchState“:true,“X“:300,“Y“:200,“Width“:32,“Height“:32,“MatchVal“:0.88,“Angle“:0,“Index“:1}]“
ret = ola.ParseMatchImageAllJson (resultJson, 0, matchState, x, y, width, height, matchVal, angle, index)aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]";
var ret = ola.ParseMatchImageAllJson(resultJson, 0, matchState, x, y, width, height, matchVal, angle, index);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
文本型 resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]"
整数 ret = ola.ParseMatchImageAllJson(resultJson, 0, matchState, x, y, width, height, matchVal, angle, index)cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
const char* resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]";
int32_t matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
double matchVal = 0, angle = 0;
int32_t ret = ola.ParseMatchImageAllJson(resultJson, 0, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
const char* resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]";
int matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
double matchVal = 0, angle = 0;
ParseMatchImageAllJson(instance, resultJson, 0, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int ParseMatchImageAllJson(long ola, string str, int parseIndex, out int matchState, out int x, out int y, out int width, out int height, out double matchVal, out double angle, out int index);
long instance = CreateCOLAPlugInterFace();
string resultJson = "[{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0},{\"MatchState\":true,\"X\":300,\"Y\":200,\"Width\":32,\"Height\":32,\"MatchVal\":0.88,\"Angle\":0,\"Index\":1}]";
ParseMatchImageAllJson(instance, resultJson, 0, out int matchState, out int x, out int y, out int width, out int height, out double matchVal, out double angle, out int index);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
from ctypes import c_double
match_state = c_int(0)
x = c_int(0)
y = c_int(0)
width = c_int(0)
height = c_int(0)
index = c_int(0)
match_val = c_double(0)
angle = c_double(0)
result_json = b'[{"MatchState":true,"X":120,"Y":80,"Width":32,"Height":32,"MatchVal":0.95,"Angle":0,"Index":0},{"MatchState":true,"X":300,"Y":200,"Width":32,"Height":32,"MatchVal":0.88,"Angle":0,"Index":1}]'
ola.ParseMatchImageAllJson(instance, result_json, 0, match_state, x, y, width, height, match_val, angle, index)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| parseIndex 参数从0开始计数 | parseIndex 参数从0开始计数。 |
| 结合 GetMatchImageAllCount | 结合 GetMatchImageAllCount 使用可以遍历所有匹配结果。 |
| 所有输出参数必须提供有效指针 | 所有输出参数必须提供有效指针。 |
