"use client"; import { motion } from "framer-motion"; import { useState } from "react"; import { COLORS, VizFrame } from "./common"; type Mode = "xyxy" | "xywh" | "norm"; export function BboxFormats({ width = 720, height = 420, }: { width?: number; height?: number; }) { const W = width; const H = height; const [mode, setMode] = useState("xyxy"); const box = { x1: 220, y1: 130, x2: 470, y2: 320 }; const w = box.x2 - box.x1; const h = box.y2 - box.y1; const cx = box.x1 + w / 2; const cy = box.y1 + h / 2; const fmt = (v: number) => v.toFixed(0); const fmtN = (v: number) => v.toFixed(3); return (
{mode === "xyxy" ? ( (x1={fmt(box.x1)}, y1={fmt(box.y1)}) (x2={fmt(box.x2)}, y2={fmt(box.y2)}) ) : null} {mode === "xywh" ? ( w={fmt(w)} h={fmt(h)} cx,cy = ({fmt(cx)}, {fmt(cy)}) ) : null} {mode === "norm" ? ( cx/W = {fmtN(cx / W)} · cy/H = {fmtN(cy / H)} · w/W = {fmtN(w / W)} · h/H = {fmtN(h / H)} YOLO format · resolution-independent ) : null}
{(["xyxy", "xywh", "norm"] as Mode[]).map((m) => ( ))}
); }