您当前的位置: 首页 >  Python

程序员正茂

暂无认证

  • 1浏览

    0关注

    283博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

opencv-python模板匹配

程序员正茂 发布时间:2020-09-02 11:21:22 ,浏览量:1

import cv2
import numpy as np
from matplotlib import pyplot as plt

img_rgb = cv2.imread('USNI.jpg')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
template = cv2.imread('Template.jpg',0)
w, h = template.shape[::-1]

res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
    cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

cv2.imwrite('res.png',img_rgb)

关注
打赏
1660743125
查看更多评论
立即登录/注册

微信扫码登录

0.0386s