主题
解析匹配图像JSON - ParseMatchImageJson
函数简介
解析匹配图像JSON字符串,提取单个匹配结果的详细信息。
接口名称
ParseMatchImageJsonDLL调用
c
int ParseMatchImageJson(string str, int* matchState, int* x, int* y, int* width, int* height, double* matchVal, double* angle, int* index);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| str | 字符串 | 匹配图像JSON字符串。 |
| matchState | 整数型指针 | 输出:匹配状态。 |
| x | 整数型指针 | 输出:匹配点X坐标。 |
| y | 整数型指针 | 输出:匹配点Y坐标。 |
| width | 整数型指针 | 输出:匹配图片宽度。 |
| height | 整数型指针 | 输出:匹配图片高度。 |
| matchVal | 双精度浮点数指针 | 输出:匹配值。 |
| angle | 双精度浮点数指针 | 输出:匹配角度。 |
| index | 整数型指针 | 输出:匹配索引。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// MatchImageFromPath 等接口返回的单结果 JSON
const char* resultJson = "{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0}";
int32_t matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
double matchVal = 0, angle = 0;
int32_t ret = ola.ParseMatchImageJson(resultJson, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);
if (ret == 1 && matchState != 0) {
// 匹配成功,点击坐标 (x, y)
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
// MatchImageFromPath 等接口返回的单结果 JSON
string resultJson = "{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0}";
int ret = ola.ParseMatchImageJson(resultJson, 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 && matchState != 0)
{
// 匹配成功,点击坐标 (x, y)
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# MatchImageFromPath 等接口返回的单结果 JSON
result_json = '{"MatchState":true,"X":120,"Y":80,"Width":32,"Height":32,"MatchVal":0.95,"Angle":0,"Index":0}'
ret, match_state, x, y, width, height, match_val, angle, index = ola.ParseMatchImageJson(result_json)
if ret == 1 and match_state != 0:
pass # 匹配成功,点击坐标 (x, y)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
// MatchImageFromPath 等接口返回的单结果 JSON
String resultJson = "{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0}";
int[] out = new int[5];
double[] outD = new double[2];
int ret = ola.ParseMatchImageJson(resultJson, out, outD);
// 按 Java SDK 输出参数取值后判断 matchStatecpp
var ola = com("OlaPlug.OlaSoft")
var resultJson = "{\"MatchState\":true,\"X\":120,\"Y\":80,\"Width\":32,\"Height\":32,\"MatchVal\":0.95,\"Angle\":0,\"Index\":0}"
var ret = ola.ParseMatchImageJson(resultJson, 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}"
ret = ola.ParseMatchImageJson(resultJson, 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}“
ret = ola.ParseMatchImageJson (resultJson, 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}";
var ret = ola.ParseMatchImageJson(resultJson, 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}"
整数 ret = ola.ParseMatchImageJson(resultJson, 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}";
int32_t matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
double matchVal = 0, angle = 0;
int32_t ret = ola.ParseMatchImageJson(resultJson, &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}";
int matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
double matchVal = 0, angle = 0;
ParseMatchImageJson(instance, resultJson, &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 ParseMatchImageJson(long ola, string str, 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}";
ParseMatchImageJson(instance, resultJson, 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()
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)
from ctypes import c_double
result_json = b'{"MatchState":true,"X":120,"Y":80,"Width":32,"Height":32,"MatchVal":0.95,"Angle":0,"Index":0}'
ola.ParseMatchImageJson(instance, result_json, match_state, x, y, width, height, match_val, angle, index)返回值
| 返回值 | 说明 |
|---|---|
1 | 成功。 |
0 | 失败。 |
注意事项
| 项目 | 说明 |
|---|---|
| 用于解析单个匹配结果的JSON字符串 | 用于解析单个匹配结果的JSON字符串。 |
| 格式 | JSON格式应符合匹配图像接口返回的标准格式。 |
| 所有输出参数必须提供有效指针 | 所有输出参数必须提供有效指针。 |
