匹配多个对象

简介: 匹配多个对象
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()
目录
相关文章
|
9月前
|
JavaScript 前端开发 Java
正则表达式深度解析:匹配任意字符串
【4月更文挑战第1天】
4600 0
|
9月前
2020-10-10 数组和对象的区分方法
2020-10-10 数组和对象的区分方法
|
Java 编译器
重载的方法能否根据返回类型进行区分?
重载的方法不能根据返回类型进行区分。方法的重载是基于方法名称和参数列表来进行区分的,与返回类型无关。这是因为在Java中,编译器在确定要调用哪个重载方法时,仅根据传递给方法的参数来进行决策。
401 0
|
JavaScript 前端开发
|
Scala 开发者
|
XML Java 数据库连接
解决表的列名和对象的属性名不匹配
解决表的列名和对象的属性名不匹配
172 0
解决表的列名和对象的属性名不匹配
运算符优先顺序(包含类型说明)
运算符优先顺序(包含类型说明)
187 0
运算符优先顺序(包含类型说明)
【Groovy】集合遍历 ( 调用集合的 any 函数判定集合中是否有指定匹配规则的元素 | 代码示例 )
【Groovy】集合遍历 ( 调用集合的 any 函数判定集合中是否有指定匹配规则的元素 | 代码示例 )
232 0
【Groovy】集合遍历 ( 调用集合的 any 函数判定集合中是否有指定匹配规则的元素 | 代码示例 )
|
Java
【Groovy】集合遍历 ( 使用集合的 findAll 方法查找集合中符合匹配条件的所有元素 | 代码示例 )
【Groovy】集合遍历 ( 使用集合的 findAll 方法查找集合中符合匹配条件的所有元素 | 代码示例 )
417 0
【Groovy】集合遍历 ( 使用集合的 findAll 方法查找集合中符合匹配条件的所有元素 | 代码示例 )

热门文章

最新文章