繁体   English   中英

使用 bbox、opencv 和 python 对视频进行对象跟踪

[英]Object Tracking on a video using bbox, opencv and python

我正在尝试创建一个可以跟随我选择的人类的机器人,为此我使用带有 python 和 openCV 的树莓派。

我想围绕一个人创建 bbox,我想让我的相机跟踪那个人,我在互联网上找到了一些代码,我试图把它们放在一起,但是当我启动代码时,它给了我图像,我可以选择一个对象,但是它不会更新帧并且图像被冻结。

当我按下空格键或另一个键时,它也会给我一个错误:“ok = tracker.init(image, bbox) NameError: name 'tracker' is not defined”

有人可以给我一些建议吗? 这是仅用于对象跟踪的代码:

from picamera import PiCamera
import time
import cv2
import numpy as np

# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))

while True:
    for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
        image = frame.array
        bbox = cv2.selectROI(image, False)
        ok = tracker.init(image, bbox) 
        cv2.imshow("Camera Output", image)
        #rawCapture.truncate(0)
        ok, bbox = tracker.update(image)
        fps = cv2.getTickFrequency() / (cv2.getTickCount() - timer)

        if ok:
            p1 = (int(bbox[0]), int(bbox[1]))
            p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3]))
            cv2.rectangle(frame, pi, p2, (255, 0, 0), 2, 1)
        else:
            cv2.putText(image, "Tracking failure detected", (100, 80),
                        cv2.FONT_HERSHEY_SIMPLEX, 0.75, (0, 0, 255), 2)

        cv2.putText(frame, tracker_type + "Tracker", (100, 20),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50, 170, 50), 2);
        cv2.putText(image, "FPS:" ++ str(int(fps)), (100, 50),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.75, (50, 170, 50), 2);
        cv2.imshow("Tracking", image)

        k = cv2.waitKey(5) #& 0xFF
        if "q" == chr(k & 255):
            break```





所以没有定义方法tracker 我发现这个初始化方法。 你可以这样做:

tracker = cv2.TrackerKCF_create()

这是考虑到你要实现opencv功能

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM