0.23.0/detection/tools/line_zone/ #1548
Replies: 2 comments 2 replies
-
I don’t know what I’m missing here. The intersection is not working. Any guesses on what mistake I’m making: import supervision as sv
from supervision.geometry.core import Position
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
class YoloObjectDetection:
def __init__(self, model):
self.model = model
self.frame = None
self.detections = None
self. color_codes = ["#FF0000"] # Red
self.start, self.end = sv.Point(x=0, y=1080), sv.Point(x=2600, y=1080)
self.line_zone = sv.LineZone(start=self.start, end=self.end)
def predict(self, q_img):
try:
frame = q_img.get()
box_annotator = sv.BoxAnnotator()
line_annotator = sv.LineZoneAnnotator()
label_annotator = sv.LabelAnnotator(text_padding=8, text_position=Position.CENTER, text_scale=1, text_thickness=2)
result = self.model.track(source=frame, agnostic_nms=True, iou=0.5, imgsz=640, conf=0.75, persist=True, verbose=False, classes=0)
result = result[0]
detections = sv.Detections.from_ultralytics(result)
if detections:
if result.boxes.id is not None:
detections.tracker_id = result.boxes.id.cpu().numpy().astype(int)
labels = [
f"{tracker_id} {self.model.names[class_id]}"
for box, mask, confidence, class_id, tracker_id, class_name
in detections
]
self.line_zone.trigger(detections)
frame = line_annotator.annotate(frame=frame, line_counter=self.line_zone)
frame = box_annotator.annotate(
scene=frame,
detections=detections
)
frame = label_annotator.annotate(
scene=frame, detections=detections, labels=labels)
return frame
else:
return frame
except Exception as er:
print(er) |
Beta Was this translation helpful? Give feedback.
1 reply
-
If I want only specific detections to trigger an event (e.g., only certain categories trigger the event while others do not), how should I write the code to implement this condition? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
0.23.0/detection/tools/line_zone/
A set of easy-to-use utilities that will come in handy in any computer vision project.
https://supervision.roboflow.com/0.23.0/detection/tools/line_zone/
Beta Was this translation helpful? Give feedback.
All reactions