From 07b0813f735fbba563913811d656176dfb9a8094 Mon Sep 17 00:00:00 2001 From: luanhailiang Date: Sat, 7 Oct 2023 18:38:22 +0800 Subject: [PATCH 1/5] result --- app.py | 3 ++- test123.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 test123.py diff --git a/app.py b/app.py index 665d848..7ea6d05 100644 --- a/app.py +++ b/app.py @@ -102,7 +102,8 @@ def worker(id,source,region=None,stream=False): print("Error opening video stream....") break continue - result = model.track(frame,device=int(id)%4,tracker='botsort.yaml') + # result = model.track(frame,device=int(id)%4,tracker='botsort.yaml') + result = model(frame) use += " track:"+str((time.time()*1000) - bgn) del(ret) del(frame) diff --git a/test123.py b/test123.py new file mode 100644 index 0000000..51fe9f9 --- /dev/null +++ b/test123.py @@ -0,0 +1,38 @@ +import cv2 +from ultralytics import YOLO + +# Load the YOLOv8 model +model = YOLO('best.pt') + +# Open the video file +video_path = "./videos/123.mp4" +cap = cv2.VideoCapture(video_path) + +cv2.namedWindow("Video", cv2.WINDOW_NORMAL) # Create a named window +cv2.resizeWindow("Video", 640, 384) # Resize this window + +# Loop through the video frames +while cap.isOpened(): + # Read a frame from the video + success, frame = cap.read() + + if success: + # Run YOLOv8 inference on the frame + results = model(frame) + + # Visualize the results on the frame + annotated_frame = results[0].plot() + + # Display the annotated frame + cv2.imshow("Video", annotated_frame) + + # Break the loop if 'q' is pressed + if cv2.waitKey(1) & 0xFF == ord("q"): + break + else: + # Break the loop if the end of the video is reached + break + +# Release the video capture object and close the display window +cap.release() +cv2.destroyAllWindows() \ No newline at end of file From 46e7a6560e5f43122c67fb69bed3a87f4dce5fc5 Mon Sep 17 00:00:00 2001 From: luanhailiang Date: Sat, 7 Oct 2023 18:56:28 +0800 Subject: [PATCH 2/5] tracker_id --- app.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app.py b/app.py index 7ea6d05..a738cb3 100644 --- a/app.py +++ b/app.py @@ -109,23 +109,23 @@ def worker(id,source,region=None,stream=False): del(frame) result = result[0] detections = sv.Detections.from_yolov8(result) - if result.boxes.id is not None: - detections.tracker_id = result.boxes.id.cpu().numpy().astype(int) - else: - detections.tracker_id = np.array([]) - detections.conf = np.array([]) - detections.xyxy=np.empty((0, 4), dtype=np.float32) + # if result.boxes.id is not None: + # detections.tracker_id = result.boxes.id.cpu().numpy().astype(int) + # else: + # detections.tracker_id = np.array([]) + # detections.conf = np.array([]) + # detections.xyxy=np.empty((0, 4), dtype=np.float32) # detections = detections[(detections.tracker_id != None)] count += 1 names = {} - for xyxy,_, confidence, class_id, tracker_id in detections: + for xyxy,_, confidence, class_id in detections: 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["xyxy"] = [int(xyxy[0]), int(xyxy[1]), int(xyxy[2]), int(xyxy[3])] ball["count"] = ball.get("count",0) + 1 From 6ea69cc121b3bd534f243fda8bba1ecde02490b2 Mon Sep 17 00:00:00 2001 From: luanhailiang Date: Sat, 7 Oct 2023 19:01:52 +0800 Subject: [PATCH 3/5] tracker_id --- app.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.py b/app.py index a738cb3..19c3749 100644 --- a/app.py +++ b/app.py @@ -119,7 +119,7 @@ def worker(id,source,region=None,stream=False): count += 1 names = {} - for xyxy,_, confidence, class_id in detections: + for xyxy,_, confidence, class_id,tracker_id in detections: name = model.model.names[class_id] if name in names: print("Name duplicate",name) From e522e43cd5fd06dd348d4924fce991914fe0b98c Mon Sep 17 00:00:00 2001 From: luanhailiang Date: Sat, 7 Oct 2023 19:10:50 +0800 Subject: [PATCH 4/5] all --- app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 19c3749..fee329f 100644 --- a/app.py +++ b/app.py @@ -83,9 +83,9 @@ def worker(id,source,region=None,stream=False): print("sleep",2*delay - (time.time()*1000 - bgn)) time.sleep((2*delay - (time.time()*1000 - bgn))/1000) bgn = (time.time()*1000) - ret, frame = cap.read() - del(ret) - del(frame) + # ret, frame = cap.read() + # del(ret) + # del(frame) ret, frame = cap.read() use += " read:"+str((time.time()*1000) - bgn) if not ret: From 272be46f635ad9f0b223ad421af418228ea08924 Mon Sep 17 00:00:00 2001 From: luanhailiang Date: Sun, 8 Oct 2023 16:59:29 +0800 Subject: [PATCH 5/5] frame --- app.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index fee329f..19c3749 100644 --- a/app.py +++ b/app.py @@ -83,9 +83,9 @@ def worker(id,source,region=None,stream=False): print("sleep",2*delay - (time.time()*1000 - bgn)) time.sleep((2*delay - (time.time()*1000 - bgn))/1000) bgn = (time.time()*1000) - # ret, frame = cap.read() - # del(ret) - # del(frame) + ret, frame = cap.read() + del(ret) + del(frame) ret, frame = cap.read() use += " read:"+str((time.time()*1000) - bgn) if not ret: