Add face details dialog

This commit is contained in:
Nicolas Mowen 2025-03-18 08:13:17 -06:00
parent 6388a72220
commit 3fbf28913d
3 changed files with 96 additions and 22 deletions

View File

@ -2,6 +2,12 @@
"description": { "description": {
"addFace": "Walk through adding a new face to the Face Library." "addFace": "Walk through adding a new face to the Face Library."
}, },
"details": {
"confidence": "Confidence",
"face": "Face Details",
"faceDesc": "Details for the face and associated object",
"timestamp": "Timestamp"
},
"documentTitle": "Face Library - Frigate", "documentTitle": "Face Library - Frigate",
"uploadFaceImage": { "uploadFaceImage": {
"title": "Upload Face Image", "title": "Upload Face Image",

View File

@ -5,6 +5,13 @@ import ActivityIndicator from "@/components/indicators/activity-indicator";
import CreateFaceWizardDialog from "@/components/overlay/detail/FaceCreateWizardDialog"; import CreateFaceWizardDialog from "@/components/overlay/detail/FaceCreateWizardDialog";
import UploadImageDialog from "@/components/overlay/dialog/UploadImageDialog"; import UploadImageDialog from "@/components/overlay/dialog/UploadImageDialog";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { import {
DropdownMenu, DropdownMenu,
DropdownMenuContent, DropdownMenuContent,
@ -21,9 +28,11 @@ import {
TooltipTrigger, TooltipTrigger,
} from "@/components/ui/tooltip"; } from "@/components/ui/tooltip";
import useContextMenu from "@/hooks/use-contextmenu"; import useContextMenu from "@/hooks/use-contextmenu";
import { useFormattedTimestamp } from "@/hooks/use-date-utils";
import useKeyboardListener from "@/hooks/use-keyboard-listener"; import useKeyboardListener from "@/hooks/use-keyboard-listener";
import useOptimisticState from "@/hooks/use-optimistic-state"; import useOptimisticState from "@/hooks/use-optimistic-state";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { RecognizedFaceData } from "@/types/face";
import { FrigateConfig } from "@/types/frigateConfig"; import { FrigateConfig } from "@/types/frigateConfig";
import axios from "axios"; import axios from "axios";
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@ -330,20 +339,75 @@ function TrainingGrid({
onClickFace, onClickFace,
onRefresh, onRefresh,
}: TrainingGridProps) { }: TrainingGridProps) {
const { t } = useTranslation(["views/faceLibrary"]);
// face data
const [selectedEvent, setSelectedEvent] = useState<RecognizedFaceData>();
const formattedDate = useFormattedTimestamp(
selectedEvent?.timestamp ?? 0,
config?.ui.time_format == "24hour"
? t("time.formattedTimestampWithYear.24hour", { ns: "common" })
: t("time.formattedTimestampWithYear.12hour", { ns: "common" }),
config?.ui.timezone,
);
return ( return (
<div className="scrollbar-container flex flex-wrap gap-2 overflow-y-scroll p-1"> <>
{attemptImages.map((image: string) => ( <Dialog
<FaceAttempt open={selectedEvent != undefined}
key={image} onOpenChange={(open) => {
image={image} if (!open) {
faceNames={faceNames} setSelectedEvent(undefined);
threshold={config.face_recognition.recognition_threshold} }
selected={selectedFaces.includes(image)} }}
onClick={(meta) => onClickFace(image, meta)} >
onRefresh={onRefresh} <DialogContent className={cn("", isDesktop && "max-w-[50%]")}>
/> <DialogHeader>
))} <DialogTitle>{t("details.face")}</DialogTitle>
</div> <DialogDescription>{t("details.faceDesc")}</DialogDescription>
</DialogHeader>
<div className="flex flex-col gap-1.5">
<div className="text-sm text-primary/40">
{t("details.confidence")}
</div>
<div className="text-sm capitalize">
{(selectedEvent?.score || 0) * 100}%
</div>
</div>
<div className="flex flex-col gap-1.5">
<div className="text-sm text-primary/40">
{t("details.timestamp")}
</div>
<div className="text-sm">{formattedDate}</div>
</div>
<img
src={`${baseUrl}api/events/${selectedEvent?.eventId}/snapshot.jpg?bbox=1`}
/>
</DialogContent>
</Dialog>
<div className="scrollbar-container flex flex-wrap gap-2 overflow-y-scroll p-1">
{attemptImages.map((image: string) => (
<FaceAttempt
key={image}
image={image}
faceNames={faceNames}
threshold={config.face_recognition.recognition_threshold}
selected={selectedFaces.includes(image)}
onClick={(data, meta) => {
if (meta) {
onClickFace(image, meta);
} else {
setSelectedEvent(data);
}
}}
onRefresh={onRefresh}
/>
))}
</div>
</>
); );
} }
@ -352,7 +416,7 @@ type FaceAttemptProps = {
faceNames: string[]; faceNames: string[];
threshold: number; threshold: number;
selected: boolean; selected: boolean;
onClick: (meta: boolean) => void; onClick: (data: RecognizedFaceData, meta: boolean) => void;
onRefresh: () => void; onRefresh: () => void;
}; };
function FaceAttempt({ function FaceAttempt({
@ -364,14 +428,14 @@ function FaceAttempt({
onRefresh, onRefresh,
}: FaceAttemptProps) { }: FaceAttemptProps) {
const { t } = useTranslation(["views/faceLibrary"]); const { t } = useTranslation(["views/faceLibrary"]);
const data = useMemo(() => { const data = useMemo<RecognizedFaceData>(() => {
const parts = image.split("-"); const parts = image.split("-");
return { return {
timestamp: Number.parseFloat(parts[0]), timestamp: Number.parseFloat(parts[0]),
eventId: `${parts[0]}-${parts[1]}`, eventId: `${parts[0]}-${parts[1]}`,
name: parts[2], name: parts[2],
score: parts[3], score: Number.parseFloat(parts[3]),
}; };
}, [image]); }, [image]);
@ -380,7 +444,7 @@ function FaceAttempt({
const imgRef = useRef<HTMLImageElement | null>(null); const imgRef = useRef<HTMLImageElement | null>(null);
useContextMenu(imgRef, () => { useContextMenu(imgRef, () => {
onClick(true); onClick(data, true);
}); });
// api calls // api calls
@ -446,7 +510,7 @@ function FaceAttempt({
ref={imgRef} ref={imgRef}
className="size-44" className="size-44"
src={`${baseUrl}clips/faces/train/${image}`} src={`${baseUrl}clips/faces/train/${image}`}
onClick={(e) => onClick(e.metaKey || e.ctrlKey)} onClick={(e) => onClick(data, e.metaKey || e.ctrlKey)}
/> />
<div className="absolute bottom-1 right-1 z-10 rounded-lg bg-black/50 px-2 py-1 text-xs text-white"> <div className="absolute bottom-1 right-1 z-10 rounded-lg bg-black/50 px-2 py-1 text-xs text-white">
<TimeAgo className="text-white" time={data.timestamp * 1000} dense /> <TimeAgo className="text-white" time={data.timestamp * 1000} dense />
@ -458,12 +522,10 @@ function FaceAttempt({
<div className="capitalize">{data.name}</div> <div className="capitalize">{data.name}</div>
<div <div
className={cn( className={cn(
Number.parseFloat(data.score) >= threshold data.score >= threshold ? "text-success" : "text-danger",
? "text-success"
: "text-danger",
)} )}
> >
{Number.parseFloat(data.score) * 100}% {data.score * 100}%
</div> </div>
</div> </div>
<div className="flex flex-row items-start justify-end gap-5 md:gap-4"> <div className="flex flex-row items-start justify-end gap-5 md:gap-4">

6
web/src/types/face.ts Normal file
View File

@ -0,0 +1,6 @@
export type RecognizedFaceData = {
timestamp: number;
eventId: string;
name: string;
score: number;
};