查找最近坐标点 - FindNearestPos
函数简介
返回离指定坐标点最近的识别结果,用于颜色识别结果及图像识别结果的筛选。
接口名称
FindNearestPos
DLL调用
long FindNearestPos(long ola, char* json, int type, int x, int y);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| json | 字符串 | 识别结果返回值 |
| type | 整数型 | 识别类型:1 颜色识别,2 图像识别 |
| x | 整数型 | 目标点的X坐标 |
| y | 整数型 | 目标点的Y坐标 |
示例
C++
long instance = CreateCOLAPlugInterFace();
// 假设 jsonResult 为图像识别返回的JSON结果
char* jsonResult = "..."; // 识别结果
// 查找离坐标(200,300)最近的图像识别结果
long ptr = FindNearestPos(instance, jsonResult, 2, 200, 300);
char* nearest = GetStringFromPtr(instance, ptr);
FreeStringPtr(instance, ptr);
Python
# 待补充
返回值
返回字符串指针。
传入颜色识别时返回:
{"x": 10, "y": 20}
| 字段名 | 类型 | 说明 |
|---|---|---|
| x | 整数 | x 字段值。 |
| y | 整数 | y 字段值。 |
传入图像识别时返回:
{
"MatchVal": 0.85,
"MatchState": true,
"Index": 0,
"Angle": 45.0,
"X": 100,
"Y": 200,
"Width": 100,
"Height": 100
}
返回的字符串指针需要调用 FreeStringPtr 释放内存。
