cv2.matchTemplate出现错误:(215:断言失败)

2024-09-30 16:41:31 发布

您现在位置:Python中文网/ 问答频道 /正文

import cv2
import numpy as np


kamera = cv2.VideoCapture(0)

while True :
    ret,kare = kamera.read()

    gri_kare = cv2.cvtColor(kare,cv2.COLOR_BGR2GRAY)

    nesne = cv2.imread("nesn.jpg",0)

    w,h = nesne.shape

    res = cv2.matchTemplate(gri_kare,nesne,cv2.TM_CCOEFF_NORMED)

    esikdeger = 0.8

    loc = np.where(res > esikdeger)

    for n in zip(loc) :
        cv2.rectangle(nesne,n,(n[0]+h,n[1]+w),(255,255,255),2,)

    cv2.imshow("asd",kare)


    if cv2.waitKey(25) & 0xFF == ord("q"):
        break


kamera.release()
cv2.destroyAllWindows()

我得到一个错误:

^{pr2}$

Tags: importnumpytrueasnprescv2loc