主题
查找文字 - FindStrDetail
函数简介
查找指定文字的坐标,默认返回最优结果,支持 ShowMatchWindow 弹窗显示结果。
接口名称
FindStrDetailDLL调用
long FindStrDetail(long ola, int x1, int y1, int x2, int y2, string str, string colorList, string dict, double matchVal);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| x1 | 整数型 | 查找区域的左上角X坐标。 |
| y1 | 整数型 | 查找区域的左上角Y坐标。 |
| x2 | 整数型 | 查找区域的右下角X坐标。 |
| y2 | 整数型 | 查找区域的右下角Y坐标。 |
| str | 字符串 | 待查找的字符串,可以是字符串组合,比如"str1|str2|str3",中间用"|"来分割字符串 |
| colorList | 字符串 | 颜色模型配置字符串,用于限定图像匹配中的颜色范围,格式说明见 颜色模型说明 - ColorModel。JSON格式示例:[{"StartColor":"3278FA","EndColor":"6496FF","Type":0}];简化格式示例:3278FA-000000|6496FF-202020 或 3278FA~6496FF 或 FF0000|00FF00 |
| dict | 字符串 | 字库名称,为空时搜索所有字库;多个字库用 | 分割,如 dict1|dict2 |
| matchVal | 双精度浮点数 | 相似度,如 0.85,最大为 1。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
MatchData result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9);
if (result.MatchState) {
int x = result.X;
int y = result.Y;
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
var result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9);
if (result.MatchState)
{
int x = result.X;
int y = result.Y;
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
# 0,0,0,0 表示绑定窗口整个客户区
result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9)
if result.get("MatchState"):
x = result["X"]
y = result["Y"]java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.ApiResult;
import com.olaplug.model.Point;
import com.olaplug.model.MatchResult;
import java.util.List;
OLAPlugServer ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
MatchResult result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9);
if (result != null && result.MatchState) {
int x = result.X;
int y = result.Y;
}go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// 0,0,0,0 表示绑定窗口整个客户区
result := ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9)
if result.MatchState {
x := result.X
y := result.Y
}rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// 0,0,0,0 表示绑定窗口整个客户区
let result = ola.find_str_detail(0, 0, 0, 0, "确定", "000000", "", 0.9);
if result.match_state {
let x = result.x;
let y = result.y;
}cpp
var ola = com("OlaPlug.OlaSoft")
// 0,0,0,0 表示绑定窗口整个客户区
var result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9)
if(result.MatchState) {
var x = result.X
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 0,0,0,0 表示绑定窗口整个客户区
Set result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9)
If result.MatchState Then
' 使用 result.X、result.Y
End Iftext
.局部变量 ola, OLAPlug
ola.Create ()
' 0,0,0,0 表示绑定窗口整个客户区
result = ola.FindStrDetail(0, 0, 0, 0, “确定“, “000000“, ““, 0.9)
.如果真 (result.MatchState)
' 使用 result.X、result.Y
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
var result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9);
if(result.MatchState){
var x = result.X;
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 0,0,0,0 表示绑定窗口整个客户区
MatchData result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9)
如果真 (result.MatchState)
// 使用 result.X、result.Ycpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
MatchData result = ola.FindStrDetail(0, 0, 0, 0, "确定", "000000", "", 0.9);
if (result.MatchState) {
int32_t x = result.X;
int32_t y = result.Y;
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
long ptr = FindStrDetail(instance, 0, 0, 0, 0, "确定", "000000", "", 0.9);
if (ptr != 0) {
char buffer[4096] = {0};
GetStringFromPtr(ptr, buffer, sizeof(buffer));
FreeStringPtr(ptr);
}csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long FindStrDetail(long ola, int x1, int y1, int x2, int y2, string str, string colorJson, string dict, double matchVal);
long instance = CreateCOLAPlugInterFace();
long ptr = FindStrDetail(instance, 0, 0, 0, 0, "确定", "000000", "", 0.9);
if (ptr != 0) {
StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
GetStringFromPtr(ptr, sb, sb.Capacity);
FreeStringPtr(ptr);
string result = sb.ToString();
}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()
ptr = ola.FindStrDetail(instance, 0, 0, 0, 0, b"确定", b"000000", b"", 0.9)
if ptr:
buf = create_string_buffer(4096)
ola.GetStringFromPtr(ptr, buf, 4096)
ola.FreeStringPtr(ptr)
result = buf.value.decode("utf-8")返回值
| 返回值 | 说明 |
|---|---|
| (返回值) | 字符串指针地址,返回JSON格式的匹配结果,如:。 |
json
{
"MatchVal": 0.85,
"MatchState": true,
"Index": 0,
"Angle": 45.0,
"X": 100,
"Y": 200,
"Width": 100,
"Height": 100
}| 字段名 | 类型 | 说明 |
|---|---|---|
| MatchVal | 浮点数 | 匹配相似度。 |
| MatchState | 布尔 | 是否匹配成功。 |
| Index | 整数 | 结果索引(从 0 开始)。 |
| Angle | 浮点数 | 匹配角度。 |
| X | 整数 | X 坐标。 |
| Y | 整数 | Y 坐标。 |
| Width | 整数 | 宽度。 |
| Height | 整数 | 高度。 |
- MatchVal:实际匹配的相似度值
- MatchState:是否匹配成功
- Index:多图匹配时的图片索引,从0开始
- Angle:匹配到的图像旋转角度
- X/Y:匹配点坐标
- Width/Height:匹配模板宽高
返回的字符串指针需调用 FreeStringPtr 释放内存。
