From acbd36a9bfac0f4a6632e63be2883735b98cd35b Mon Sep 17 00:00:00 2001 From: feilong Date: Thu, 16 Dec 2021 20:56:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=BD=A6=E8=BE=86=E7=9B=AE?= =?UTF-8?q?=E6=A0=87=E8=B7=9F=E8=B8=AA=E7=9A=84=E8=B7=AF=E5=BE=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../obj_tracker_run.py" | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git "a/data/1.OpenCV\345\210\235\351\230\266/6.\350\247\206\351\242\221\345\210\206\346\236\220/2.\347\233\256\346\240\207\350\267\237\350\270\252/obj_tracker_run.py" "b/data/1.OpenCV\345\210\235\351\230\266/6.\350\247\206\351\242\221\345\210\206\346\236\220/2.\347\233\256\346\240\207\350\267\237\350\270\252/obj_tracker_run.py" index d2128a8..4ed6370 100755 --- "a/data/1.OpenCV\345\210\235\351\230\266/6.\350\247\206\351\242\221\345\210\206\346\236\220/2.\347\233\256\346\240\207\350\267\237\350\270\252/obj_tracker_run.py" +++ "b/data/1.OpenCV\345\210\235\351\230\266/6.\350\247\206\351\242\221\345\210\206\346\236\220/2.\347\233\256\346\240\207\350\267\237\350\270\252/obj_tracker_run.py" @@ -19,6 +19,8 @@ tracks = np.empty((0, 5)) sort = Sort(5, 0, 0.2) # do track and render on image + + def track_and_render(detections, img): global total_frames global total_time @@ -35,17 +37,18 @@ def track_and_render(detections, img): else: # if skip frame in detection process tracks = sort.update() - + # get the fps, calculate avg speed in 100 frames cycle_time = time.time() - start_time total_time += cycle_time 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_frames = 0 - + # render on frame image - for track in tracks: + for track in tracks: # [left, top, right, bottom, id] pt1 = (int(track[0]), int(track[1])) pt2 = (int(track[2]), int(track[3])) @@ -53,7 +56,7 @@ def track_and_render(detections, img): cv2.putText(img, str(int(track[4])), (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 img @@ -61,34 +64,35 @@ def track_and_render(detections, img): # main if __name__ == '__main__': - + # 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 for i in range(400000): # read frame image - bg = cv2.imread(path + '\\' + str(i % 800 + 1) + '.jpg') + bg = cv2.imread(path + '/' + str(i % 800 + 1) + '.jpg') # rescale bg = cv2.resize(bg, (int(1280 / scale), int(720 / scale))) - + # read detection data in current frame dets = [] - with open(path + '\\' + str(i % 800 + 1) + '.txt') as txt: + with open(path + '/' + str(i % 800 + 1) + '.txt') as txt: lines = txt.readlines() for line in lines: items = line.split(' ') left = float(items[1]) top = float(items[2]) right = float(items[3]) - bottom = float(items[4]) - - dets.append((left / scale, top / scale, right / scale, bottom / scale, int(items[0]))) - + bottom = float(items[4]) + + dets.append((left / scale, top / scale, right / + scale, bottom / scale, int(items[0]))) + # send to the tracker and draw the result on background image if len(dets) > 0: bg = track_and_render(dets, bg) cv2.imshow('tracker', bg) cv2.waitKey(40) - + cv2.destroyAllWindows() -- GitLab