主题
查找最近坐标点 - FindNearestPos
函数简介
返回离指定坐标点最近的识别结果,用于颜色识别结果及图像识别结果的筛选。
接口名称
FindNearestPosDLL调用
c
long FindNearestPos(long ola, char* json, int type, int x, int y);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| json | 字符串 | 识别结果返回值。 |
| type | 整数型 | 识别类型:1 颜色识别,2 图像识别。 |
| x | 整数型 | 目标点的X坐标。 |
| y | 整数型 | 目标点的Y坐标。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string nearest = ola.FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);csharp
using OLAPlug;
var ola = new OLAPlugServer();
string nearest = ola.FindNearestPos(@"[{"x":100,"y":200,"id":1},{"x":150,"y":220,"id":2},{"x":300,"y":100,"id":3}]", 2, 120, 210);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
nearest = ola.FindNearestPos(r'[{"x":100,"y":200,"id":1},{"x":150,"y":220,"id":2},{"x":300,"y":100,"id":3}]', 2, 120, 210)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);cpp
var ola = com("OlaPlug.OlaSoft")
ola.FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.FindNearestPos(“[{\“x\“:100,\“y\“:200,\“id\“:1},{\“x\“:150,\“y\“:220,\“id\“:2},{\“x\“:300,\“y\“:100,\“id\“:3}]“, 2, 120, 210);aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
std::string nearest = FindNearestPos("[{\"x\":100,\"y\":200,\"id\":1},{\"x\":150,\"y\":220,\"id\":2},{\"x\":300,\"y\":100,\"id\":3}]", 2, 120, 210);csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
string nearest = FindNearestPos(@"[{"x":100,"y":200,"id":1},{"x":150,"y":220,"id":2},{"x":300,"y":100,"id":3}]", 2, 120, 210);python
from ctypes import CDLL, c_int, c_int64
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
nearest = ola.FindNearestPos(r'[{"x":100,"y":200,"id":1},{"x":150,"y":220,"id":2},{"x":300,"y":100,"id":3}]', 2, 120, 210)返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 返回字符串指针。 传入颜色识别时返回:。 |
json
{"x": 10, "y": 20}| 字段名 | 类型 | 说明 |
|---|---|---|
| x | 整数 | x 字段值。 |
| y | 整数 | y 字段值。 |
传入图像识别时返回:
json
{
"MatchVal": 0.85,
"MatchState": true,
"Index": 0,
"Angle": 45.0,
"X": 100,
"Y": 200,
"Width": 100,
"Height": 100
}返回的字符串指针需要调用 FreeStringPtr 释放内存。
