Search before asking
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
Search before asking
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.
except for the polygon , how to have multiple lines and update the counts?
Additional
No response