[英]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```
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.