0.23.0/detection/tools/line_zone/ #1548
Replies: 3 comments 4 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.
-
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.
-
hi, I am having some issues understanding the trigger method. when i do: the code is like this: zone_line = sv.LineZone(start=LINE_START, end=LINE_END)
# Create line annotator
zone_line_annotator = sv.LineZoneAnnotator(thickness=1, text_thickness=2, text_scale=1, color=sv.Color.WHITE)
for frame in frames_generator:
results = model.infer(frame, confidence=confidence, iou_threshold=iou)[0]
detections = sv.Detections.from_inference(results)
#detections = detections[find_in_list(detections.class_id, classes)]
detections = tracker.update_with_detections(detections)
annotated_frame = frame.copy()
annotated_frame = box_annotator.annotate(
scene=annotated_frame, detections=detections[detections.class_id == 0])
labels = [f"#{tracker_id} {confidence:0.2f}"
for confidence,tracker_id
in zip(detections.confidence, detections.tracker_id)
]
annotated_frame = label_annotator.annotate(
scene=annotated_frame, detections=detections, labels=labels)
## polygon that detects leaving customers
#zone_out.trigger(detections=detections)
## Line that detects leaving customers
zone_line.trigger(detections=detections[detections.class_id == 0])
# update line counter
annotated_frame = zone_line_annotator.annotate(annotated_frame, line_counter=zone_line)
print(zone_line.trigger(detections=detections[detections.class_id == 0]))
#print(detections[detections.class_id == 0].tracker_id)
print(zone_line.in_count, zone_line.out_count) I think that I should be expecting a True when they cross the line right? |
Beta Was this translation helpful? Give feedback.
-
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