supervision: line counter is not working anymore?
Search before asking
- I have searched the Supervision issues and found no similar feature requests.
Question
this is my code I wanted to add multiple lines and count the objects, but the line counter is not working anymore with the latest supervision.
import os
import torch
os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"]="0"
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
import numpy as np
import json
from ultralytics import YOLO
import supervision as sv
# from supervision.tools.line_counter import LineCounter
# from supervision.geometry.dataclasses import Point
# LINE_START = Point(50, 1500)
# LINE_END = Point(3790, 1500)
# line_counter = LineCounter(start=LINE_START, end=LINE_END)
model = YOLO('yolov8n.pt')
def main_func(input_data,frame):
global model
if 'ignore' in input_data:
return "ignore"
else:
input_data = json.loads(input_data)
results= model.track(frame, imgsz=640, classes=0,tracker="bytetrack.yaml")[0]
detections = sv.Detections.from_yolov8(results)
if results.boxes.id is not None:
detections.tracker_id = results.boxes.id.cpu().numpy().astype(int)
detections.conf = results.boxes.conf.cpu().numpy().astype(float)
detections.xyxy = results.boxes.xyxy.cpu().numpy().astype(int)
# print(detections.tracker_id)
# print(detections.conf)
# print(detections.xyxy)
else:
detections.tracker_id = np.array([])
detections.conf = np.array([])
detections.xyxy = np.array([])
new_box=detections.xyxy
new_box = new_box.astype("int").tolist()
new_ids = detections.tracker_id.astype("int").tolist()
new_confs = detections.conf.astype("float").tolist()
print("count",count)
output = {
'frame_index':input_data['frame_index'],
'time_stamp':input_data['time_stamp'],
'detections':new_box,
'demo_run':input_data['demo_run'],
'ids':new_ids,
'confs':new_confs
}
print(output)
return output
except for the polygon , how to have multiple lines and update the counts?
Additional
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 23 (1 by maintainers)
Closing the issue.
@uzumakinaruto19 As for your in-zone time counter. Here is a sketch of the python logic that you will need.
This actually worked in my case with @maddust suggestion, thanks a ton !! @SkalskiP and @sceddd
when using the polygon zone I’m getting this error, it’s running for some seconds and throwing this error
And is it possible to get how much time an object spends in that zone alone?
Thanks in advance
Maybe you put the line in the wrong position. The logic is that if all the bounding boxes cross the line, the count will increase. In your case, you should either turn the camera to a higher position or detect the shoes and count if those shoes cross the line or you could take a look at #107 with the @maddust issue by choose the point at bottom center of the bounding box for counting.
Hi, @uzumakinaruto19 👋🏻
I’m not sure you can use YOLOv8 ByteTrack this way. Here is a snippet of code I used in the past, and it worked. Important note
supervisionAPI may differ a bit. It is pretty old code, but the YOLOv8 tracking part worked 100%.@uzumakinaruto19 did you use trigger() yet? I don’t see it in your code.