匹配多个对象

简介: 匹配多个对象
import cv2
import numpy as np

# 原图
origin = cv2.imread('./image/many-cat.png')
# 原图灰度化
origin_gray= cv2.cvtColor(origin,cv2.COLOR_BGR2GRAY)
# 直接读取模版灰度图
template = cv2.imread('./image/min-cat.png',0)
# 202,167
print(template.shape)
# 1是宽0是高
# w = template.shape[1]
# h = template.shape[0]
h,w = template.shape

# 模版匹配
res = cv2.matchTemplate(origin_gray,template,cv2.TM_CCOEFF_NORMED)
# 设定阈值,认为相关系数大于0.8,就认为是匹配上了
threshold = 0.98
# print(res)
# print(res>=threshold)
# where函数找到位置坐标,是一个元组,一个x轴,一个y轴
# print(np.where(res>=threshold))
# 找到复核条件的坐标,返回x,y的列表,在一起
# print(np.argwhere(res>=threshold))
loc = np.argwhere(res>=threshold)
# print(loc)
for pt in loc:
    bottom_right = (pt[1] + w,pt[0] + h)
    cv2.rectangle(origin,pt[::-1],bottom_right,(0,0,255),2)

# loc = np.where(res >= threshold)
# for pt in zip(*loc[::-1]):
#     bottom_right=(pt[0] + w,pt[1] + h)
#     cv2.rectangle(origin,pt,bottom_right,(0,0,255),2)

cv2.imshow('origin',origin)
cv2.waitKey(0)
cv2.destroyAllWindows()
目录
相关文章
|
10月前
|
JavaScript 前端开发 Java
正则表达式深度解析:匹配任意字符串
【4月更文挑战第1天】
4866 0
|
6月前
|
JavaScript
判断一个对象为空对象的方法
判断一个对象为空对象的方法
70 4
|
前端开发
判断数组对象中是否满足某条件
判断数组对象中是否满足某条件
69 0
|
10月前
2020-10-10 数组和对象的区分方法
2020-10-10 数组和对象的区分方法
|
10月前
|
Java
java8中过滤、获取指定属性转换为集合、字符串拼接、移除某个对象的使用
java8中过滤、获取指定属性转换为集合、字符串拼接、移除某个对象的使用
|
JSON JavaScript 数据格式
根据多种条件过滤对象的JSON数组
根据多种条件过滤对象的JSON数组
162 0
【Groovy】集合遍历 ( 调用集合的 any 函数判定集合中是否有指定匹配规则的元素 | 代码示例 )
【Groovy】集合遍历 ( 调用集合的 any 函数判定集合中是否有指定匹配规则的元素 | 代码示例 )
235 0
【Groovy】集合遍历 ( 调用集合的 any 函数判定集合中是否有指定匹配规则的元素 | 代码示例 )
|
Java
【Groovy】集合遍历 ( 使用集合的 find 方法查找集合元素 | 闭包中使用 == 作为查找匹配条件 | 闭包中使用 is 作为查找匹配条件 | 闭包使用 true 作为条件 | 代码示例 )
【Groovy】集合遍历 ( 使用集合的 find 方法查找集合元素 | 闭包中使用 == 作为查找匹配条件 | 闭包中使用 is 作为查找匹配条件 | 闭包使用 true 作为条件 | 代码示例 )
365 0
Drools规则引擎-如果判断某个对象中的集合是否包含指定的值
Drools规则引擎-如果判断某个对象中的集合是否包含指定的值
339 0
正则匹配指定字符之间的内容,并替换(多个匹配替换)
var str="是吗@Test1:我觉得你说的很对@Test:学无止境"; var r=str.match(/@.*?:/ig); for (var index = 0; index < r.
2446 0