Comments (7)
Hi @SkalskiP, I implemented something similar. I hope this will be helpful to you. You might need to refine it.
import supervision as sv
from supervision.geometry.core import Point, Position
from typing import Dict, List, Optional, Union
from supervision.detection.core import Detections
from supervision.draw.color import Color, ColorPalette
import numpy as np
import cv2
class Trace:
xy: np.ndarray
class_id: Optional[np.ndarray] = None
tracker_id: Optional[np.ndarray] = None
def __init__(
self,
position: Position = Position.CENTER,
max_length: int = 10,
):
self.trace: Dict[int, List[sv.Point]] = {}
self.position = position
self.max_length = max_length
self.frame_counter = 0
# Counter, x, y, class, trackid
self.storage = np.zeros((0, 5))
def update(self, frame_counter: int, detections: Detections) -> None:
if detections.xyxy.shape[0]>0:
xyxy = detections.xyxy
x = (xyxy[:, 0] + xyxy[:, 2]) / 2
y = (xyxy[:, 1] + xyxy[:, 3]) / 2
new_detections = np.zeros(shape=(xyxy.shape[0], 5))
new_detections[:, 0] = frame_counter
new_detections[:, 1] = x
new_detections[:, 2] = y
new_detections[:, 3] = detections.class_id
new_detections[:, 4] = detections.tracker_id
self.storage = np.append(self.storage, new_detections, axis=0)
self.frame_counter = frame_counter
self._remove_previous()
def _remove_previous(self):
to_remove_frames = self.frame_counter - self.max_length
if self.storage.shape[0]>0:
valid = np.where(self.storage[:, 0] > to_remove_frames)
self.storage = self.storage[valid]
class TraceAnnotator:
def __init__(
self,
color: Union[Color, ColorPalette] = ColorPalette.default(),
thickness: int = 2
):
self.color: Union[Color, ColorPalette] = color
self.thickness: int = thickness
self.boundry_tolerance = 20
def annotate(self, scene: np.ndarray, trace: Trace) -> np.ndarray:
img_h, img_w, _ = scene.shape
unique_ids = np.unique(trace.storage[:, -1])
for unique_id in unique_ids:
valid = np.where(trace.storage[:, -1] == unique_id)[0]
frames =trace.storage[valid, 0]
latest_frame = np.argmax(frames)
points_to_draw = trace.storage[valid, 1:3]
n_pts = points_to_draw.shape[0]
headx, heady = int(points_to_draw[latest_frame][0]), int(points_to_draw[latest_frame][1])
if headx > self.boundry_tolerance and heady > self.boundry_tolerance:
class_id = trace.storage[0, -2]
idx = int(unique_id)
color = (
self.color.by_idx(idx)
if isinstance(self.color, ColorPalette)
else self.color
)
for i in range(n_pts-1):
px, py = int(points_to_draw[i][0]), int(points_to_draw[i][1])
qx, qy = int(points_to_draw[i+1][0]), int(points_to_draw[i+1][1])
cv2.line(scene, (px, py), (qx, qy), color.as_bgr(), self.thickness)
scene = cv2.circle(scene, (headx, heady), int(10), color.as_bgr(), thickness=-1)
return scene
from supervision.
Hello there, thank you for opening an Issue ! 🙏🏻 The team was notified and they will get back to you asap.
from supervision.
@SkalskiP Do you have any idea or design for this like how it looks like?
from supervision.
Hi @SkalskiP 👋 , I have started building this API. It only needs minor improvement. Ready for this feature in next release 🔥
from supervision.
hi @SkalskiP 👋 , here is the preliminary results.
from supervision.
@hardikdava can you open PR with this annotator into the feature/redesigned_annotators
branch?
from supervision.
The task finally compleated with https://github.com/roboflow/supervision/releases/tag/0.15.0 🔥
from supervision.
Related Issues (20)
- Hi @s-madhavan001 👋🏻 All you need is here: https://github.com/roboflow/supervision/tree/develop/examples/time_in_zone HOT 2
- How to add class filter in yolov8 tracker and zone counting HOT 10
- sv.Detections has exactly N of each member, except for `tracker_id`. HOT 3
- [DetectionDataset] - expand `from_yolo` to include support for OBB (Oriented Bounding Boxes) HOT 11
- [PolygonZone] - drop `frame_resolution_wh` requirement HOT 5
- Interpolation error on computing average precision HOT 3
- Update to support new `from_transformers` methods HOT 1
- [DetectionDataset] - extend `from_coco` and `as_coco` with support for masks in RLE format HOT 10
- the result.mp4 cannot be played on the browser HOT 4
- Adding a function to convert Supervision.Detections to Ultralytics.Results? HOT 2
- Filter Detections Error HOT 7
- TraceAnnotator fails when there are no detections present due to IndexError HOT 7
- I want to filter detections so that only the classes "No Helmet", "Person", "Rider" are detected. HOT 1
- Multi-can tracking HOT 1
- ultralytics_stream_example do not work HOT 8
- ByteTrack memory consumption increases indefinitely HOT 4
- [KeyPoints] - add `from_mediapipe` connector allowing Supervision to be used with Google MediaPipe models HOT 4
- Request: as_coco Parameter Adjustment for sv.DetectionDataset in Supervision API HOT 7
- HaloAnnotator does not work HOT 1
- I want to show zone_annotator all the time
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from supervision.