mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-11 17:47:37 +03:00
include tolerance for displaying of path and zone
some browsers (firefox and probably brave) intentionally reduce precision of seeking with currentTime for privacy reasons
This commit is contained in:
parent
af765af0d2
commit
b9ca9e49dd
@ -13,6 +13,9 @@ import { cn } from "@/lib/utils";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Event } from "@/types/event";
|
import { Event } from "@/types/event";
|
||||||
|
|
||||||
|
// Use a small tolerance (10ms) for browsers with seek precision by-design issues
|
||||||
|
const TOLERANCE = 0.01;
|
||||||
|
|
||||||
type ObjectTrackOverlayProps = {
|
type ObjectTrackOverlayProps = {
|
||||||
camera: string;
|
camera: string;
|
||||||
showBoundingBoxes?: boolean;
|
showBoundingBoxes?: boolean;
|
||||||
@ -166,38 +169,42 @@ export default function ObjectTrackOverlay({
|
|||||||
}) || [];
|
}) || [];
|
||||||
|
|
||||||
// show full path once current time has reached the object's start time
|
// show full path once current time has reached the object's start time
|
||||||
const combinedPoints = [...savedPathPoints, ...eventSequencePoints]
|
// event.start_time is in DETECT stream time, so convert it to record stream time for comparison
|
||||||
.sort((a, b) => a.timestamp - b.timestamp)
|
const eventStartTimeRecord =
|
||||||
.filter(
|
(eventData?.start_time ?? 0) + annotationOffset / 1000;
|
||||||
|
|
||||||
|
const allPoints = [...savedPathPoints, ...eventSequencePoints].sort(
|
||||||
|
(a, b) => a.timestamp - b.timestamp,
|
||||||
|
);
|
||||||
|
const combinedPoints = allPoints.filter(
|
||||||
(point) =>
|
(point) =>
|
||||||
currentTime >= (eventData?.start_time ?? 0) &&
|
currentTime >= eventStartTimeRecord - TOLERANCE &&
|
||||||
point.timestamp >= (eventData?.start_time ?? 0) &&
|
point.timestamp <= effectiveCurrentTime + TOLERANCE,
|
||||||
point.timestamp <= (eventData?.end_time ?? Infinity),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// Get color for this object
|
// Get color for this object
|
||||||
const label = eventData?.label || "unknown";
|
const label = eventData?.label || "unknown";
|
||||||
const color = getObjectColor(label, objectId);
|
const color = getObjectColor(label, objectId);
|
||||||
|
|
||||||
// Get current zones
|
// zones (with tolerance for browsers with seek precision by-design issues)
|
||||||
const currentZones =
|
const currentZones =
|
||||||
timelineData
|
timelineData
|
||||||
?.filter(
|
?.filter(
|
||||||
(event: TrackingDetailsSequence) =>
|
(event: TrackingDetailsSequence) =>
|
||||||
event.timestamp <= effectiveCurrentTime,
|
event.timestamp <= effectiveCurrentTime + TOLERANCE,
|
||||||
)
|
)
|
||||||
.sort(
|
.sort(
|
||||||
(a: TrackingDetailsSequence, b: TrackingDetailsSequence) =>
|
(a: TrackingDetailsSequence, b: TrackingDetailsSequence) =>
|
||||||
b.timestamp - a.timestamp,
|
b.timestamp - a.timestamp,
|
||||||
)[0]?.data?.zones || [];
|
)[0]?.data?.zones || [];
|
||||||
|
|
||||||
// Get current bounding box
|
// bounding box (with tolerance for browsers with seek precision by-design issues)
|
||||||
const currentBox = timelineData
|
const boxCandidates = timelineData?.filter(
|
||||||
?.filter(
|
|
||||||
(event: TrackingDetailsSequence) =>
|
(event: TrackingDetailsSequence) =>
|
||||||
event.timestamp <= effectiveCurrentTime && event.data.box,
|
event.timestamp <= effectiveCurrentTime + TOLERANCE &&
|
||||||
)
|
event.data.box,
|
||||||
.sort(
|
);
|
||||||
|
const currentBox = boxCandidates?.sort(
|
||||||
(a: TrackingDetailsSequence, b: TrackingDetailsSequence) =>
|
(a: TrackingDetailsSequence, b: TrackingDetailsSequence) =>
|
||||||
b.timestamp - a.timestamp,
|
b.timestamp - a.timestamp,
|
||||||
)[0]?.data?.box;
|
)[0]?.data?.box;
|
||||||
@ -221,6 +228,7 @@ export default function ObjectTrackOverlay({
|
|||||||
getObjectColor,
|
getObjectColor,
|
||||||
config,
|
config,
|
||||||
camera,
|
camera,
|
||||||
|
annotationOffset,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Collect all zones across all objects
|
// Collect all zones across all objects
|
||||||
@ -274,9 +282,10 @@ export default function ObjectTrackOverlay({
|
|||||||
|
|
||||||
const handlePointClick = useCallback(
|
const handlePointClick = useCallback(
|
||||||
(timestamp: number) => {
|
(timestamp: number) => {
|
||||||
onSeekToTime?.(timestamp, false);
|
// Convert detect stream timestamp to record stream timestamp before seeking
|
||||||
|
onSeekToTime?.(timestamp + annotationOffset / 1000, false);
|
||||||
},
|
},
|
||||||
[onSeekToTime],
|
[onSeekToTime, annotationOffset],
|
||||||
);
|
);
|
||||||
|
|
||||||
const zonePolygons = useMemo(() => {
|
const zonePolygons = useMemo(() => {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user