Skip to content

NVR with realtime local object detection for IP cameras

Fix Bad Resize For Camera Snapshot (#6797)

Nicolas Mowen0a8249d6fb11
diff --git a/frigate/http.py b/frigate/http.py
index 44706f2c2f..9c55d68c43 100644
--- a/frigate/http.py
+++ b/frigate/http.py
@@ -1118,6 +1118,15 @@ def latest_frame(camera_name):
height = int(request.args.get("h", str(frame.shape[0])))
width = int(height * frame.shape[1] / frame.shape[0])
+ if not frame:
+ return "Unable to get valid frame from {}".format(camera_name), 500
+
+ if height < 1 or width < 1:
+ return (
+ "Invalid height / width requested :: {} / {}".format(height, width),
+ 400,
+ )
+
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
ret, jpg = cv2.imencode(
diff --git a/web/src/components/CameraImage.jsx b/web/src/components/CameraImage.jsx
index 98754e5065..ce4e4bef79 100644
--- a/web/src/components/CameraImage.jsx
+++ b/web/src/components/CameraImage.jsx
@@ -28,13 +28,18 @@ export default function CameraImage({ camera, onload, searchParams = '', stretch
const scaledHeight = useMemo(() => {
const scaledHeight = Math.floor(availableWidth / aspectRatio);
- return stretch ? scaledHeight : Math.min(scaledHeight, height);
+ const finalHeight = stretch ? scaledHeight : Math.min(scaledHeight, height);
+
+ if (finalHeight > 0) {
+ return finalHeight;
+ }
+
+ return 100;
}, [availableWidth, aspectRatio, height, stretch]);
- const scaledWidth = useMemo(() => Math.ceil(scaledHeight * aspectRatio - scrollBarWidth), [
- scaledHeight,
- aspectRatio,
- scrollBarWidth,
- ]);
+ const scaledWidth = useMemo(
+ () => Math.ceil(scaledHeight * aspectRatio - scrollBarWidth),
+ [scaledHeight, aspectRatio, scrollBarWidth]
+ );
const img = useMemo(() => new Image(), []);
img.onload = useCallback(
@@ -58,18 +63,16 @@ export default function CameraImage({ camera, onload, searchParams = '', stretch
return (
<div className="relative w-full" ref={containerRef}>
- {
- (enabled) ?
- <canvas data-testid="cameraimage-canvas" height={scaledHeight} ref={canvasRef} width={scaledWidth} />
- : <div class="text-center pt-6">Camera is disabled in config, no stream or snapshot available!</div>
- }
- {
- (!hasLoaded && enabled) ? (
- <div className="absolute inset-0 flex justify-center" style={`height: ${scaledHeight}px`}>
- <ActivityIndicator />
- </div>
- ) : null
- }
- </div >
+ {enabled ? (
+ <canvas data-testid="cameraimage-canvas" height={scaledHeight} ref={canvasRef} width={scaledWidth} />
+ ) : (
+ <div class="text-center pt-6">Camera is disabled in config, no stream or snapshot available!</div>
+ )}
+ {!hasLoaded && enabled ? (
+ <div className="absolute inset-0 flex justify-center" style={`height: ${scaledHeight}px`}>
+ <ActivityIndicator />
+ </div>
+ ) : null}
+ </div>
);
}