python ubuntu dlib 人臉識別11-物體追蹤

純潔的程式碼發表於2020-04-02
1. 從資料夾中讀取圖片檔案,這步可以結合ffmpeg來完成,將視訊流切圖命令為(但需要再寫個指令碼定期清理舊圖片,比如10分鐘前):

ffmpeg -i myfile.avi -r 1000 -f image2 image-%07d.png
2.讀取圖片並圈出識別出的物體:


import os
import glob

import dlib

# Path to the video frames
video_folder = os.path.join("./video_frames")

# Create the correlation tracker - the object needs to be initialized
# before it can be used
tracker = dlib.correlation_tracker()

win = dlib.image_window()
# We will track the frames as we load them off of disk
for k, f in enumerate(sorted(glob.glob(os.path.join(video_folder, "*.jpg")))):
print("Processing Frame {}".format(k))
img = dlib.load_rgb_image(f)

# We need to initialize the tracker on the first frame
if k == 0:
# Start a track on the juice box. If you look at the first frame you
# will see that the juice box is contained within the bounding
# box (74, 67, 112, 153).
tracker.start_track(img, dlib.rectangle(74, 67, 112, 153))
else:
# Else we just attempt to track from the previous frame
tracker.update(img)

win.clear_overlay()
win.set_image(img)
win.add_overlay(tracker.get_position())
dlib.hit_enter_to_continue()

---------------------
作者:_iorilan
來源:CSDN
原文:blog.csdn.net/lan_liang/a…
版權宣告:本文為博主原創文章,轉載請附上博文連結!

更多學習資料可關注:gzitcast


相關文章