fix annotation photo

This commit is contained in:
Armen Rohalov
2025-05-01 22:19:57 +03:00
parent 805b9ace57
commit af729ed7ad
2 changed files with 7 additions and 5 deletions
@@ -161,6 +161,8 @@ function CanvasEditor({
y1: Math.min(currentDetection.y1, currentDetection.y2),
x2: Math.max(currentDetection.x1, currentDetection.x2),
y2: Math.max(currentDetection.y1, currentDetection.y2),
kw: width / containerRef.current.offsetWidth,
kh: height / containerRef.current.offsetHeight
};
const newDetections = [...localDetections, normalizedDetection];
+4 -4
View File
@@ -52,10 +52,10 @@ export const createAnnotationImage = (videoRef, detections, containerRef) => {
ctx.fillStyle = bgColor;
ctx.strokeStyle = borderColor;
const x = Math.max(0, detection.x1 || 0);
const y = Math.max(0, detection.y1 || 0);
const width = Math.max(1, (detection.x2 || 0) - (detection.x1 || 0));
const height = Math.max(1, (detection.y2 || 0) - (detection.y1 || 0));
const x = Math.max(0, detection.x1 || 0) * detection.kw;
const y = Math.max(0, detection.y1 || 0) * detection.kh;
const width = Math.max(1, (detection.x2 || 0) - (detection.x1 || 0)) * detection.kw;
const height = Math.max(1, (detection.y2 || 0) - (detection.y1 || 0)) * detection.kh;
ctx.fillRect(x, y, width, height);
ctx.lineWidth = 2;