匹配图片2 - MatchImageFromPtrAll
函数简介
匹配所有符合模板图片的位置信息,源图与模板均通过内存指针传入。
接口名称
MatchImageFromPtrAll
DLL调用
long MatchImageFromPtrAll(long ola, long source, long templ, double matchVal, int type, double angle, double scale);
参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| source | 长整数型 | OLAImage对象的地址(源图片) |
| templ | 长整数型 | OLAImage对象的地址(模板图片),由LoadImage等接口生成 |
| matchVal | 双精度浮点数 | 相似度,如0.85,最大为1 |
| type | 整数型 | 匹配类型:1-灰度匹配(速度快);2-彩色匹配;3-透明匹配;4-透明彩色权重匹配;5-普通彩色匹配 |
| angle | 双精度浮点数 | 旋转角度,每次匹配后旋转指定角度继续匹配,角度越小匹配次数越多时间越长,0为不旋转速度最快 |
| scale | 双精度浮点数 | 源图缩放比例,默认为1,可通过GetScaleFromWindows接口获取 |
示例
C++
long instance = CreateCOLAPlugInterFace();
long source = LoadImage(instance, "source.bmp");
long templ = LoadImage(instance, "templ.bmp");
// 通过内存指针匹配所有结果,灰度匹配
long resultPtr = MatchImageFromPtrAll(instance, source, templ, 0.85, 1, 0, 1.0);
char* result = GetStringFromPtr(instance, resultPtr);
FreeStringPtr(instance, resultPtr);
Python
# 待补充
返回值
字符串指针,返回JSON数组格式的匹配结果。DLL调用返回字符串指针地址,需要调用 FreeStringPtr 接口释放内存。
返回数据格式:
[{
"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 | 整数 | 高度。 |
