提交 acbd36a9 编写于 作者: F feilong

修正车辆目标跟踪的路径bug

上级 cfdcccae
...@@ -19,6 +19,8 @@ tracks = np.empty((0, 5)) ...@@ -19,6 +19,8 @@ tracks = np.empty((0, 5))
sort = Sort(5, 0, 0.2) sort = Sort(5, 0, 0.2)
# do track and render on image # do track and render on image
def track_and_render(detections, img): def track_and_render(detections, img):
global total_frames global total_frames
global total_time global total_time
...@@ -35,17 +37,18 @@ def track_and_render(detections, img): ...@@ -35,17 +37,18 @@ def track_and_render(detections, img):
else: else:
# if skip frame in detection process # if skip frame in detection process
tracks = sort.update() tracks = sort.update()
# get the fps, calculate avg speed in 100 frames # get the fps, calculate avg speed in 100 frames
cycle_time = time.time() - start_time cycle_time = time.time() - start_time
total_time += cycle_time total_time += cycle_time
if total_frames % 100 == 0: if total_frames % 100 == 0:
print("Total Tracking took: %.3f seconds for %d frames or %.1f FPS" % (total_time, total_frames, total_frames / total_time)) print("Total Tracking took: %.3f seconds for %d frames or %.1f FPS" %
(total_time, total_frames, total_frames / total_time))
total_time = 0.0 total_time = 0.0
total_frames = 0 total_frames = 0
# render on frame image # render on frame image
for track in tracks: for track in tracks:
# [left, top, right, bottom, id] # [left, top, right, bottom, id]
pt1 = (int(track[0]), int(track[1])) pt1 = (int(track[0]), int(track[1]))
pt2 = (int(track[2]), int(track[3])) pt2 = (int(track[2]), int(track[3]))
...@@ -53,7 +56,7 @@ def track_and_render(detections, img): ...@@ -53,7 +56,7 @@ def track_and_render(detections, img):
cv2.putText(img, str(int(track[4])), cv2.putText(img, str(int(track[4])),
(pt1[0], pt1[1] - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (pt1[0], pt1[1] - 5), cv2.FONT_HERSHEY_SIMPLEX, 0.7,
(0, 255, 255), 1) (0, 255, 255), 1)
# return frame image to caller # return frame image to caller
return img return img
...@@ -61,34 +64,35 @@ def track_and_render(detections, img): ...@@ -61,34 +64,35 @@ def track_and_render(detections, img):
# main # main
if __name__ == '__main__': if __name__ == '__main__':
# detection data, generated by object-detector algo model, including frame image # detection data, generated by object-detector algo model, including frame image
path = 'mot_benchmark\\MY_TEST\\www3' path = 'mot_benchmark/MY_TEST/www3'
# read test data from disk in a loop one frame by frame and send it to sort tracker # read test data from disk in a loop one frame by frame and send it to sort tracker
for i in range(400000): for i in range(400000):
# read frame image # read frame image
bg = cv2.imread(path + '\\' + str(i % 800 + 1) + '.jpg') bg = cv2.imread(path + '/' + str(i % 800 + 1) + '.jpg')
# rescale # rescale
bg = cv2.resize(bg, (int(1280 / scale), int(720 / scale))) bg = cv2.resize(bg, (int(1280 / scale), int(720 / scale)))
# read detection data in current frame # read detection data in current frame
dets = [] dets = []
with open(path + '\\' + str(i % 800 + 1) + '.txt') as txt: with open(path + '/' + str(i % 800 + 1) + '.txt') as txt:
lines = txt.readlines() lines = txt.readlines()
for line in lines: for line in lines:
items = line.split(' ') items = line.split(' ')
left = float(items[1]) left = float(items[1])
top = float(items[2]) top = float(items[2])
right = float(items[3]) right = float(items[3])
bottom = float(items[4]) bottom = float(items[4])
dets.append((left / scale, top / scale, right / scale, bottom / scale, int(items[0]))) dets.append((left / scale, top / scale, right /
scale, bottom / scale, int(items[0])))
# send to the tracker and draw the result on background image # send to the tracker and draw the result on background image
if len(dets) > 0: if len(dets) > 0:
bg = track_and_render(dets, bg) bg = track_and_render(dets, bg)
cv2.imshow('tracker', bg) cv2.imshow('tracker', bg)
cv2.waitKey(40) cv2.waitKey(40)
cv2.destroyAllWindows() cv2.destroyAllWindows()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册