Videos and live streams are checked frame by frame. A model can miss an object for a frame or two: it turns, something passes in front of it, or its score dips just under the flag's threshold. Without tracking, a blur blinks off for those frames and a timeline has gaps.
With tracking, each finding is followed from frame to frame as the same object, and the frames a model misses still carry it. Tracking is free and off unless you turn it on.
Turn it on#
For a video, add "tracking": true to the request:
curl https://api.detectivision.ai/api/v1/moderation \
-H "Api-Key: $DETECTIVISION_API_KEY" \
-H "Content-Type: application/json" \
-d '{"type": "video_moderation", "input": "https://example.com/clip.mp4", "fps": 2, "tracking": true}'import os, requests
r = requests.post(
"https://api.detectivision.ai/api/v1/moderation",
headers={"Api-Key": os.environ["DETECTIVISION_API_KEY"]},
json={"type": "video_moderation", "input": "https://example.com/clip.mp4", "fps": 2, "tracking": True},
timeout=180,
)
print(r.json())const res = await fetch("https://api.detectivision.ai/api/v1/moderation", {
method: "POST",
headers: { "Api-Key": process.env.DETECTIVISION_API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ type: "video_moderation", input: "https://example.com/clip.mp4", fps: 2, tracking: true }),
signal: AbortSignal.timeout(180_000),
});
console.log(await res.json());For a live stream, start the session with it: {"source": "camera", "fps": 5, "tracking": true}. See Live streams.
In the dashboard's Playground, turn on the Tracking switch on the Video or Live Stream tab.
What changes in the answer#
- The answer says
"tracking": true(videos). A live session showstrackingin its state. - Every detection has
track: the object's number, the same in every frame it appears in. - Detections that tracking added have
"tracked": true. They carry the object's best confidence, so they count toward flags like any other detection. - With
"mode": "censor", a censored video hides the object on every frame, following it between the checked ones.
A video checked at 2 frames a second, where the model missed the cigarette at 1.5 s (detections shortened: label and frame left out):
{
"tracking": true,
"flags": [
{
"flag": "smoking",
"confidence": 0.91,
"detections": [
{ "t": 1.0, "track": 1, "confidence": 0.91, "bbox": [412, 188, 470, 231] },
{ "t": 1.5, "track": 1, "tracked": true, "confidence": 0.91, "bbox": [418, 184, 476, 228] },
{ "t": 2.0, "track": 1, "confidence": 0.87, "bbox": [424, 180, 482, 225] }
]
}
]
}The filled box at 1.5 s lies halfway between the two it was seen in, because the object moved.
How objects are followed#
Tracking works like ByteTrack, the common method for tracking by detection:
- A detection at or above the flag's threshold is matched to an object already followed: by how much their boxes overlap where the object was last seen or is expected to be, or, for an object that moved fast, by how close they are.
- A new object is followed once it has been seen in two checked frames in a row. Something seen in a single frame is reported as it is and is never carried to other frames, so one wrong detection stays one frame.
- A weaker detection, at least half the threshold, keeps an object that is already followed. It never starts one.
- An object not seen again within two checked frames, or within a second if that is longer, is let go.
Videos and live streams#
A video is checked whole, so tracking knows what comes before and after each frame. A live stream is checked as it happens, so tracking can only look back.
| Videos | Live streams | |
|---|---|---|
| Between two sightings | Filled in; the box moves from one to the other. | Covered from where the object was last seen to where its motion should have taken it. |
| After the last sighting | The next checked frame. | Two checked frames, and at least a second. |
| Before the first sighting | One sampling step, at most half a second. | Nothing: the future is not known yet. |
In a live session, a frame that only tracking covers is flagged, but it never becomes a moment. A moment's picture always shows what a model saw.
Note
After an object leaves the picture, a live session keeps covering where it was for about a second. An object that moves very fast just before it is first seen can be only partly covered in those frames.
Price#
Tracking is free: it uses the detections the models already made, with no extra model calls. Without it, answers are exactly as before.