主题
坐标点排序 - SortPosDistance
函数简介
根据坐标点距离排序,用于颜色识别结果及图像识别结果的排序。
接口名称
SortPosDistanceDLL调用
c
long SortPosDistance(long ola, char* json, int type, int x, int y);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| json | 字符串 | 识别结果返回值。 |
| type | 整数型 | 识别类型:1 颜色识别,2 图像识别。 |
| x | 整数型 | 锚点的X坐标。 |
| y | 整数型 | 锚点的Y坐标。 |
输入 JSON 格式
json 参数需传入识别接口返回的 原始 JSON 字符串,格式须与 type 对应:
| type | 来源接口示例 | JSON 格式 |
|---|---|---|
1 颜色识别 | FindColorListEx | [{"X":100,"Y":200},{"X":150,"Y":220}] |
2 图像识别 | FindImageFromPtrAll 等 | [{"MatchVal":0.95,"MatchState":true,"Index":0,"Angle":0,"X":100,"Y":200,"Width":32,"Height":32}] |
SDK 注意:上述识别接口在 SDK 中会将 JSON 自动反序列化 为模型对象(如
Point/MatchResult、Point2D/MatchData等)。调用本接口前须 再序列化回 JSON 字符串,推荐使用 SDK 模型上的ToJSON()/toJSON()方法(列表可逐元素序列化后拼接为 JSON 数组)。原生 DLL 调用则可直接使用识别接口返回的 JSON,无需转换。
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
std::string sorted = ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);csharp
using OLAPlug;
var ola = new OLAPlugServer();
string sorted = ola.SortPosDistance(@"[{"MatchVal":0.95,"MatchState":true,"Index":0,"Angle":0,"X":100,"Y":200,"Width":32,"Height":32},{"MatchVal":0.88,"MatchState":true,"Index":1,"Angle":0,"X":150,"Y":220,"Width":32,"Height":32},{"MatchVal":0.80,"MatchState":true,"Index":2,"Angle":0,"X":300,"Y":100,"Width":32,"Height":32}]", 2, 120, 210);python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
sorted_list = ola.SortPosDistance(r'[{"MatchVal":0.95,"MatchState":true,"Index":0,"Angle":0,"X":100,"Y":200,"Width":32,"Height":32},{"MatchVal":0.88,"MatchState":true,"Index":1,"Angle":0,"X":150,"Y":220,"Width":32,"Height":32},{"MatchVal":0.80,"MatchState":true,"Index":2,"Angle":0,"X":300,"Y":100,"Width":32,"Height":32}]', 2, 120, 210)java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
sorted := ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210)rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let sorted = ola.sort_pos_distance("[{\"MatchVal\":0.95, \"MatchState\":true, \"Index\":0, \"Angle\":0, \"X\":100, \"Y\":200, \"Width\":32, \"Height\":32}, {\"MatchVal\":0.88, \"MatchState\":true, \"Index\":1, \"Angle\":0, \"X\":150, \"Y\":220, \"Width\":32, \"Height\":32}, {\"MatchVal\":0.80, \"MatchState\":true, \"Index\":2, \"Angle\":0, \"X\":300, \"Y\":100, \"Width\":32, \"Height\":32}]", 2, 120, 210);cpp
var ola = com("OlaPlug.OlaSoft")
ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.SortPosDistance(“[{\“MatchVal\“:0.95,\“MatchState\“:true,\“Index\“:0,\“Angle\“:0,\“X\“:100,\“Y\“:200,\“Width\“:32,\“Height\“:32},{\“MatchVal\“:0.88,\“MatchState\“:true,\“Index\“:1,\“Angle\“:0,\“X\“:150,\“Y\“:220,\“Width\“:32,\“Height\“:32},{\“MatchVal\“:0.80,\“MatchState\“:true,\“Index\“:2,\“Angle\“:0,\“X\“:300,\“Y\“:100,\“Width\“:32,\“Height\“:32}]“, 2, 120, 210);aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
ola.SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
std::string sorted = SortPosDistance("[{\"MatchVal\":0.95,\"MatchState\":true,\"Index\":0,\"Angle\":0,\"X\":100,\"Y\":200,\"Width\":32,\"Height\":32},{\"MatchVal\":0.88,\"MatchState\":true,\"Index\":1,\"Angle\":0,\"X\":150,\"Y\":220,\"Width\":32,\"Height\":32},{\"MatchVal\":0.80,\"MatchState\":true,\"Index\":2,\"Angle\":0,\"X\":300,\"Y\":100,\"Width\":32,\"Height\":32}]", 2, 120, 210);csharp
using System.Runtime.InteropServices;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
long instance = CreateCOLAPlugInterFace();
string sorted = SortPosDistance(@"[{"MatchVal":0.95,"MatchState":true,"Index":0,"Angle":0,"X":100,"Y":200,"Width":32,"Height":32},{"MatchVal":0.88,"MatchState":true,"Index":1,"Angle":0,"X":150,"Y":220,"Width":32,"Height":32},{"MatchVal":0.80,"MatchState":true,"Index":2,"Angle":0,"X":300,"Y":100,"Width":32,"Height":32}]", 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()
sorted_list = ola.SortPosDistance(r'[{"MatchVal":0.95,"MatchState":true,"Index":0,"Angle":0,"X":100,"Y":200,"Width":32,"Height":32},{"MatchVal":0.88,"MatchState":true,"Index":1,"Angle":0,"X":150,"Y":220,"Width":32,"Height":32},{"MatchVal":0.80,"MatchState":true,"Index":2,"Angle":0,"X":300,"Y":100,"Width":32,"Height":32}]', 2, 120, 210)完整示例
以下示例演示:识别接口获取结果 → 转换为 JSON → 按锚点距离排序 → 解析排序后的结果。
颜色识别:按鼠标位置排序
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
auto colorPoints = ola.FindColorListEx(0, 0, 0, 0, "[{\"StartColor\":\"00FF00\",\"EndColor\":\"00FF00\"}]");
if (colorPoints.empty()) return;
// 使用 toJSON 序列化为 JSON 数组
std::string colorJson = "[";
for (size_t i = 0; i < colorPoints.size(); ++i) {
if (i > 0) colorJson += ",";
colorJson += ola.toJSON(colorPoints[i]);
}
colorJson += "]";
// 按锚点 (500, 300) 由近到远排序,type=1
std::string sortedJson = ola.SortPosDistance(colorJson.c_str(), 1, 500, 300);
// 解析:格式与 FindColorListEx 相同,第一个元素为最近点
int64_t sortedArr = ola.JsonParse(sortedJson.c_str(), &err);
if (sortedArr != 0 && err == 0) {
int64_t nearest = ola.JsonGetArrayItem(sortedArr, 0, &err);
int32_t getErr = 0;
int32_t x = (int32_t)ola.JsonGetNumber(nearest, "X", &getErr);
int32_t y = (int32_t)ola.JsonGetNumber(nearest, "Y", &getErr);
ola.JsonFree(sortedArr);
}csharp
using OLAPlug;
using Newtonsoft.Json;
using System.Linq;
var ola = new OLAPlugServer();
var colorPoints = ola.FindColorListEx(0, 0, 0, 0, @"[{""StartColor"":""00FF00"",""EndColor"":""00FF00""}]");
if (colorPoints.Count == 0) return;
string colorJson = "[" + string.Join(",", colorPoints.Select(p => p.ToJSON())) + "]";
string sortedJson = ola.SortPosDistance(colorJson, 1, 500, 300);
var sortedPoints = JsonConvert.DeserializeObject<List<Point>>(sortedJson);
if (sortedPoints != null && sortedPoints.Count > 0)
{
int x = sortedPoints[0].X; // 距锚点最近
int y = sortedPoints[0].Y;
}python
import json
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
color_points = ola.FindColorListEx(0, 0, 0, 0, '[{"StartColor":"00FF00","EndColor":"00FF00"}]')
if not color_points:
return
color_json = json.dumps(color_points, ensure_ascii=False)
sorted_json = ola.SortPosDistance(color_json, 1, 500, 300)
sorted_points = json.loads(sorted_json)
if sorted_points:
x = sorted_points[0]["X"]
y = sorted_points[0]["Y"]java
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.olaplug.OLAPlugServer;
import com.olaplug.model.Point;
import java.util.List;
OLAPlugServer ola = new OLAPlugServer();
ObjectMapper mapper = new ObjectMapper();
List<Point> colorPoints = ola.FindColorListEx(0, 0, 0, 0, "[{\"StartColor\":\"00FF00\",\"EndColor\":\"00FF00\"}]");
if (colorPoints == null || colorPoints.isEmpty()) return;
String colorJson = colorPoints.stream()
.map(Point::toJSON)
.collect(java.util.stream.Collectors.joining(",", "[", "]"));
String sortedJson = ola.SortPosDistance(colorJson, 1, 500, 300);
List<Point> sortedPoints = mapper.readValue(sortedJson, new TypeReference<List<Point>>() {});
if (sortedPoints != null && !sortedPoints.isEmpty()) {
int x = sortedPoints.get(0).X;
int y = sortedPoints.get(0).Y;
}go
import (
"encoding/json"
"github.com/ola/olaplug/olaplug"
)
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
colorPoints := ola.FindColorListEx(0, 0, 0, 0, `[{"StartColor":"00FF00","EndColor":"00FF00"}]`)
if len(colorPoints) == 0 {
return
}
colorJson, _ := json.Marshal(colorPoints)
sortedJson := ola.SortPosDistance(string(colorJson), 1, 500, 300)
var sortedPoints []olaplug.Point2D
if json.Unmarshal([]byte(sortedJson), &sortedPoints) == nil && len(sortedPoints) > 0 {
x := sortedPoints[0].X
y := sortedPoints[0].Y
_ = x
_ = y
}rust
use olaplug::{OLAPlugServer, Point2D};
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let color_points = ola.find_color_list_ex(0, 0, 0, 0, r#"[{"StartColor":"00FF00","EndColor":"00FF00"}]"#);
if color_points.is_empty() {
return;
}
let color_json = format!(
"[{}]",
color_points.iter().map(|p| p.toJSON()).collect::<Vec<_>>().join(",")
);
let sorted_json = ola.sort_pos_distance(&color_json, 1, 500, 300);
if let Ok(sorted_points) = serde_json::from_str::<Vec<Point2D>>(&sorted_json) {
if let Some(nearest) = sorted_points.first() {
let x = nearest.x;
let y = nearest.y;
let _ = (x, y);
}
}图像识别:按角色位置排序多个按钮
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
long imgPtr = ola.LoadImage("scene.png");
long templPtr = ola.LoadImage("button.bmp");
if (imgPtr == 0 || templPtr == 0) return;
auto matchResults = ola.FindImageFromPtrAll(imgPtr, templPtr, "101010", 0.9);
if (matchResults.empty()) { ola.FreeImage(imgPtr); ola.FreeImage(templPtr); return; }
std::string matchJson = "[";
for (size_t i = 0; i < matchResults.size(); ++i) {
if (i > 0) matchJson += ",";
matchJson += ola.toJSON(matchResults[i]);
}
matchJson += "]";
// 按角色坐标 (400, 300) 排序,type=2
std::string sortedJson = ola.SortPosDistance(matchJson.c_str(), 2, 400, 300);
int32_t count = ola.GetMatchImageAllCount(sortedJson.c_str());
for (int32_t i = 0; i < count; i++) {
int32_t matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
double matchVal = 0, angle = 0;
ola.ParseMatchImageAllJson(sortedJson.c_str(), i, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);
}
ola.FreeImage(imgPtr);
ola.FreeImage(templPtr);csharp
using OLAPlug;
using Newtonsoft.Json;
using System.Linq;
var ola = new OLAPlugServer();
long imgPtr = ola.LoadImage("scene.png");
long templPtr = ola.LoadImage("button.bmp");
if (imgPtr == 0 || templPtr == 0) return;
var matchResults = ola.FindImageFromPtrAll(imgPtr, templPtr, "101010", 0.9);
if (matchResults.Count == 0) { ola.FreeImage(imgPtr); ola.FreeImage(templPtr); return; }
string matchJson = "[" + string.Join(",", matchResults.Select(m => m.ToJSON())) + "]";
string sortedJson = ola.SortPosDistance(matchJson, 2, 400, 300);
var sortedMatches = JsonConvert.DeserializeObject<List<MatchResult>>(sortedJson);
if (sortedMatches != null && sortedMatches.Count > 0)
{
int x = sortedMatches[0].X;
int y = sortedMatches[0].Y;
}
ola.FreeImage(imgPtr);
ola.FreeImage(templPtr);python
import json
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
img_ptr = ola.LoadImage("scene.png")
templ_ptr = ola.LoadImage("button.bmp")
if not img_ptr or not templ_ptr:
return
match_results = ola.FindImageFromPtrAll(img_ptr, templ_ptr, "101010", 0.9)
if not match_results:
ola.FreeImage(img_ptr); ola.FreeImage(templ_ptr); return
match_json = json.dumps(match_results, ensure_ascii=False)
sorted_json = ola.SortPosDistance(match_json, 2, 400, 300)
sorted_matches = json.loads(sorted_json)
if sorted_matches:
x = sorted_matches[0]["X"]
y = sorted_matches[0]["Y"]
ola.FreeImage(img_ptr)
ola.FreeImage(templ_ptr)java
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.olaplug.OLAPlugServer;
import com.olaplug.model.MatchResult;
import java.util.List;
OLAPlugServer ola = new OLAPlugServer();
ObjectMapper mapper = new ObjectMapper();
long imgPtr = ola.LoadImage("scene.png");
long templPtr = ola.LoadImage("button.bmp");
if (imgPtr == 0 || templPtr == 0) return;
List<MatchResult> matchResults = ola.FindImageFromPtrAll(imgPtr, templPtr, "101010", 0.9);
if (matchResults == null || matchResults.isEmpty()) {
ola.FreeImage(imgPtr); ola.FreeImage(templPtr); return;
}
String matchJson = matchResults.stream()
.map(MatchResult::toJSON)
.collect(java.util.stream.Collectors.joining(",", "[", "]"));
String sortedJson = ola.SortPosDistance(matchJson, 2, 400, 300);
List<MatchResult> sortedMatches = mapper.readValue(sortedJson, new TypeReference<List<MatchResult>>() {});
if (sortedMatches != null && !sortedMatches.isEmpty()) {
int x = sortedMatches.get(0).X;
int y = sortedMatches.get(0).Y;
}
ola.FreeImage(imgPtr);
ola.FreeImage(templPtr);go
import (
"encoding/json"
"github.com/ola/olaplug/olaplug"
)
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
imgPtr := ola.LoadImage("scene.png")
templPtr := ola.LoadImage("button.bmp")
if imgPtr == 0 || templPtr == 0 {
return
}
matchResults := ola.FindImageFromPtrAll(imgPtr, templPtr, "101010", 0.9)
if len(matchResults) == 0 {
ola.FreeImage(imgPtr)
ola.FreeImage(templPtr)
return
}
matchJson, _ := json.Marshal(matchResults)
sortedJson := ola.SortPosDistance(string(matchJson), 2, 400, 300)
var sortedMatches []olaplug.MatchData
if json.Unmarshal([]byte(sortedJson), &sortedMatches) == nil && len(sortedMatches) > 0 {
x := sortedMatches[0].X
y := sortedMatches[0].Y
_ = x
_ = y
}
ola.FreeImage(imgPtr)
ola.FreeImage(templPtr)rust
use olaplug::{MatchData, OLAPlugServer};
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let img_ptr = ola.load_image("scene.png");
let templ_ptr = ola.load_image("button.bmp");
if img_ptr == 0 || templ_ptr == 0 {
return;
}
let match_results = ola.find_image_from_ptr_all(img_ptr, templ_ptr, "101010", 0.9);
if match_results.is_empty() {
ola.free_image_ptr(img_ptr);
ola.free_image_ptr(templ_ptr);
return;
}
let match_json = format!(
"[{}]",
match_results.iter().map(|m| m.toJSON()).collect::<Vec<_>>().join(",")
);
let sorted_json = ola.sort_pos_distance(&match_json, 2, 400, 300);
if let Ok(sorted_matches) = serde_json::from_str::<Vec<MatchData>>(&sorted_json) {
if let Some(first) = sorted_matches.first() {
let _ = (first.x, first.y);
}
}
ola.free_image_ptr(img_ptr);
ola.free_image_ptr(templ_ptr);原生 DLL:识别 JSON 直接传入
cpp
long instance = CreateCOLAPlugInterFace();
long colorPtr = FindColorListEx(instance, 0, 0, 0, 0, "[{\"StartColor\":\"00FF00\",\"EndColor\":\"00FF00\"}]");
if (colorPtr != 0) {
char colorJson[65536] = {0};
GetStringFromPtr(colorPtr, colorJson, sizeof(colorJson));
FreeStringPtr(colorPtr);
long sortedPtr = SortPosDistance(instance, colorJson, 1, 500, 300);
if (sortedPtr != 0) {
char sortedJson[65536] = {0};
GetStringFromPtr(sortedPtr, sortedJson, sizeof(sortedJson));
FreeStringPtr(sortedPtr);
// 用 JsonParse 或 ParseMatchImageAllJson 解析 sortedJson
}
}csharp
long colorPtr = FindColorListEx(instance, 0, 0, 0, 0, "[{\"StartColor\":\"00FF00\",\"EndColor\":\"00FF00\"}]");
if (colorPtr != 0) {
var sb = new StringBuilder(GetStringSize(colorPtr) + 1);
GetStringFromPtr(colorPtr, sb, sb.Capacity);
FreeStringPtr(colorPtr);
long sortedPtr = SortPosDistance(instance, sb.ToString(), 1, 500, 300);
if (sortedPtr != 0) {
var sortedSb = new StringBuilder(GetStringSize(sortedPtr) + 1);
GetStringFromPtr(sortedPtr, sortedSb, sortedSb.Capacity);
FreeStringPtr(sortedPtr);
var sortedPoints = JsonConvert.DeserializeObject<List<Point>>(sortedSb.ToString());
}
}python
color_ptr = ola.FindColorListEx(instance, 0, 0, 0, 0, b'[{"StartColor":"00FF00","EndColor":"00FF00"}]')
if color_ptr:
buf = create_string_buffer(65536)
ola.GetStringFromPtr(color_ptr, buf, 65536)
ola.FreeStringPtr(color_ptr)
sorted_ptr = ola.SortPosDistance(instance, buf.value, 1, 500, 300)
if sorted_ptr:
sorted_buf = create_string_buffer(65536)
ola.GetStringFromPtr(sorted_ptr, sorted_buf, 65536)
ola.FreeStringPtr(sorted_ptr)
sorted_points = json.loads(sorted_buf.value.decode("utf-8"))返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 返回按距离由近到远排序后的 JSON 字符串。格式与输入 json 相同(颜色为 [{"X":..,"Y":..}] 数组,图像为 MatchResult 对象数组)。SDK 封装已自动拷贝字符串;原生 DLL 返回的字符串指针需调用 FreeStringPtr 释放内存。 |
