Skip to content

Commit 5e16638

Browse files
committed
feat: add CameraOverlay bounding box for live camera feed
1 parent 4c6f6f7 commit 5e16638

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

src/components/CameraOverlay.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React, { useRef, useEffect } from 'react';
2+
3+
interface Props {
4+
active: boolean;
5+
}
6+
7+
export default function CameraOverlay({ active }: Props) {
8+
const canvasRef = useRef<HTMLCanvasElement>(null);
9+
10+
useEffect(() => {
11+
const canvas = canvasRef.current;
12+
if (!canvas) return;
13+
const ctx = canvas.getContext('2d');
14+
if (!ctx) return;
15+
16+
ctx.clearRect(0, 0, canvas.width, canvas.height);
17+
if (!active) return;
18+
19+
const w = canvas.width;
20+
const h = canvas.height;
21+
const x = w * 0.1;
22+
const y = h * 0.15;
23+
const bw = w * 0.8;
24+
const bh = h * 0.7;
25+
26+
ctx.strokeStyle = 'rgba(0, 255, 180, 0.75)';
27+
ctx.lineWidth = 2;
28+
ctx.setLineDash([8, 4]);
29+
ctx.strokeRect(x, y, bw, bh);
30+
31+
ctx.fillStyle = 'rgba(0, 255, 180, 0.15)';
32+
ctx.fillRect(x, y, bw, bh);
33+
}, [active]);
34+
35+
return (
36+
<canvas
37+
ref={canvasRef}
38+
width={640}
39+
height={480}
40+
className="absolute inset-0 w-full h-full z-30 pointer-events-none"
41+
/>
42+
);
43+
}

src/pages/ScannerPage.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
Upload,
1111
} from "lucide-react";
1212
import StatusTerminal from "../components/StatusTerminal";
13+
import CameraOverlay from "../components/CameraOverlay";
1314
import { api, isAuthenticated } from "../lib/api";
1415
import { FishFreshnessInference } from "../fusionInference.js";
1516
import type { ScanResult } from "../lib/types";
@@ -470,6 +471,9 @@ export default function ScannerPage() {
470471
/>
471472
)}
472473

474+
{/* Camera Overlay Bounding Box */}
475+
<CameraOverlay active={scanPhase === "idle"} />
476+
473477
{/* Grid overlay */}
474478
<div
475479
className="absolute inset-0 opacity-[0.2] mix-blend-screen pointer-events-none z-10"

0 commit comments

Comments
 (0)