How to add callback to LineZone? #321
-
Hi, spent the afternoon playing with Supervision, it was very easy to build a toy demo but now that I am trying to add a "real" feature, I am at lost about how to interact with the LineZone object. Basically, I need to be able to perform a callback (API call in my case) whenever an objet passes Python isnt my main language so I wouldnt date to write a PR but could we add a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @AlainPilon 👋🏻 Sorry for the late response. I was AFK for the past few days. We have callbacks on our list of features with high priority. But it will probably take us 1-2 releases to get there. For now, you'll need to write some custom code to enable that. import supervision as sv
byte_tracker = sv.ByteTrack()
line_zone = sv.LineZone(start=LINE_START, end=LINE_END)
for frame in sv.get_video_frames_generator(source_path='source_video.mp4'):
results = model(frame)[0]
detections = sv.Detections.from_ultralytics(results)
detections = byte_tracker.update_with_detections(detections)
previous_in_count = line_zone.in_count
previous_out_count = line_zone.out_count
line_zone.trigger(detections)
if previous_in_count != line_zone.in_count:
in_callback()
if previous_out_count != line_zone.out_count:
out_callback() Also, keep in mind that we are working on a new implementation of |
Beta Was this translation helpful? Give feedback.
-
Thanks. I couldnt wait to took it upon myself to hack something. As stated about, Python is not my strength but I wrote this: https://github.com/AlainPilon/better_line_counter/blob/main/line_counter.py I saw that you have on your project board a story to refactor/improve the LineCounter so I will look out for it but until this, I think my solution is enough (for my requirements). I think using dependency injections would be a great pattern for LineCounter as we could inject a We are planing on using Supervision in an industrial setting so I am sure we will come up with more real life requirements! |
Beta Was this translation helpful? Give feedback.
Hi @AlainPilon 👋🏻 Sorry for the late response. I was AFK for the past few days. We have callbacks on our list of features with high priority. But it will probably take us 1-2 releases to get there.
For now, you'll need to write some custom code to enable that.