📜  模板匹配输出的多个边界框只需要一个 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:12.393000             🧑  作者: Mango

代码示例1
img_rgb = cv2.imread('obsvu.jpg')
img_rgb = cv2.medianBlur(img_rgb, 7)

img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)

template_image = cv2.imread('template.jpg',0)
template_image = cv2.medianBlur(template_image, 5)
width, height = template_image.shape[::-1]

res = cv2.matchTemplate(img_gray, template_image, cv2.TM_CCOEFF_NORMED)

threshold =  0.6

locations = np.where(res >= threshold)

new_locations = group_locations(np.array(locations).T, 50).T

for position_tuple in zip(*new_locations.astype(int)[::-1]):
        cv2.rectangle(img_rgb, position_tuple, (position_tuple[0] + width, position_tuple[1] + height), (0,255,0), 5)