openCV匹配两个对象python和跟踪

时间:2018-01-21 00:14:19

标签: python opencv tracking matching

我的对象enter image description here有图像 和我的对象  enter image description here

当我执行我的代码时

    import cv2
import numpy as np
cap = cv2.VideoCapture("c.mp4")
while(True):
    ret, img_rgb = cap.read()
    img_rgb = img_rgb[400:1200,10:1000]
    img_rgb = cv2.imread('ccc.jpg')
    img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
    template = cv2.imread('job/ff2.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]):
        print("yes")
        cv2.rectangle(img_gray, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)

    cv2.imshow('res.png',img_gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break
cv2.waitKey(0)
cap.release()
cv2.destroyAllWindows()

检测到我的物体 enter image description here

但是当我使用视频时,它在视频https://youtu.be/O1IB0dnDrWw

中找不到我的对象

请帮助

0 个答案:

没有答案