姜尧 2023-09-19 17:12:25 +08:00
commit 5eba772ad2
1 changed files with 9 additions and 2 deletions

11
app.py
View File

@ -68,15 +68,22 @@ def worker(id,source,region=None,stream=False):
detections = detections[(detections.tracker_id != None)] detections = detections[(detections.tracker_id != None)]
count += 1 count += 1
names = {}
for xyxy,_, confidence, class_id, tracker_id in detections: for xyxy,_, confidence, class_id, tracker_id in detections:
ball = balls.get(model.model.names[class_id],{}) name = model.model.names[class_id]
if name in names:
print("Name duplicate",name)
continue
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
if region - count < 3: if region - count < 3:
ball["final"] = ball.get("final",0) + 1 ball["final"] = ball.get("final",0) + 1
balls[model.model.names[class_id]] = ball balls[name] = ball
names[name] = True
names = {}
if count < region: if count < region:
continue continue
json_data = json.dumps({"table":id,"balls":balls,"time":int(time.time()*1000)}) json_data = json.dumps({"table":id,"balls":balls,"time":int(time.time()*1000)})