Skip to content

查找最近坐标点 - FindNearestPos

函数简介

返回离指定坐标点最近的识别结果,用于颜色识别结果及图像识别结果的筛选。

接口名称

FindNearestPos

DLL调用

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 释放内存。