tracker_id

main
luanhailiang 2023-10-07 18:56:28 +08:00
parent 07b0813f73
commit 46e7a6560e
1 changed files with 8 additions and 8 deletions

16
app.py
View File

@ -109,23 +109,23 @@ def worker(id,source,region=None,stream=False):
del(frame) del(frame)
result = result[0] result = result[0]
detections = sv.Detections.from_yolov8(result) detections = sv.Detections.from_yolov8(result)
if result.boxes.id is not None: # if result.boxes.id is not None:
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int) # detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
else: # else:
detections.tracker_id = np.array([]) # detections.tracker_id = np.array([])
detections.conf = np.array([]) # detections.conf = np.array([])
detections.xyxy=np.empty((0, 4), dtype=np.float32) # detections.xyxy=np.empty((0, 4), dtype=np.float32)
# detections = detections[(detections.tracker_id != None)] # detections = detections[(detections.tracker_id != None)]
count += 1 count += 1
names = {} names = {}
for xyxy,_, confidence, class_id, tracker_id in detections: for xyxy,_, confidence, class_id in detections:
name = model.model.names[class_id] name = model.model.names[class_id]
if name in names: if name in names:
print("Name duplicate",name) print("Name duplicate",name)
continue continue
ball = balls.get(name,{}) ball = balls.get(name,{})
ball["tkid"] = int(tracker_id) # ball["tkid"] = int(tracker_id)
ball["conf"] = round(float(confidence), 2) ball["conf"] = round(float(confidence), 2)
ball["xyxy"] = [int(xyxy[0]), int(xyxy[1]), int(xyxy[2]), int(xyxy[3])] ball["xyxy"] = [int(xyxy[0]), int(xyxy[1]), int(xyxy[2]), int(xyxy[3])]
ball["count"] = ball.get("count",0) + 1 ball["count"] = ball.get("count",0) + 1