MatchingResult
[v4.1.0 新增]
matches
数组的元素是一个 Match 对象:
point
{Point} 匹配位置
similarity
{number} 相似度
例如:
1var result = images.matchTemplate(img, template, {
2 max: 100,
3});
4result.matches.forEach((match) => {
5 log("point = " + match.point + ", similarity = " + match.similarity);
6});
points
first()
第一个匹配结果。如果没有任何匹配,则返回null
。
last()
最后一个匹配结果。如果没有任何匹配,则返回null
。
leftmost()
位于大图片最左边的匹配结果。如果没有任何匹配,则返回null
。
topmost()
位于大图片最上边的匹配结果。如果没有任何匹配,则返回null
。
rightmost()
位于大图片最右边的匹配结果。如果没有任何匹配,则返回null
。
bottommost()
位于大图片最下边的匹配结果。如果没有任何匹配,则返回null
。
best()
相似度最高的匹配结果。如果没有任何匹配,则返回null
。
worst()
相似度最低的匹配结果。如果没有任何匹配,则返回null
。
sortBy(cmp)
- cmp {Function}|{string} 比较函数,或者是一个字符串表示排序方向。例如"left"表示将匹配结果按匹配位置从左往右排序、"top"表示将匹配结果按匹配位置从上往下排序,"left-top"表示将匹配结果按匹配位置从左往右、从上往下排序。方向包括
left
(左), top
(上), right
(右), bottom
(下)。
- {MatchingResult}
对匹配结果进行排序,并返回排序后的结果。
1var result = images.matchTemplate(img, template, {
2 max: 100,
3});
4log(result.sortBy("top-right"));