mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-02-11 05:35:25 +03:00
relative coordinates and colors
This commit is contained in:
parent
ce7191fa18
commit
8e788caec1
@ -191,6 +191,7 @@ export function PolygonCanvas({
|
|||||||
flattenedPoints={flattenPoints(polygon.points)}
|
flattenedPoints={flattenPoints(polygon.points)}
|
||||||
isActive={index === activePolygonIndex}
|
isActive={index === activePolygonIndex}
|
||||||
isFinished={polygon.isFinished}
|
isFinished={polygon.isFinished}
|
||||||
|
color={polygon.color}
|
||||||
handlePointDragMove={handlePointDragMove}
|
handlePointDragMove={handlePointDragMove}
|
||||||
handleGroupDragEnd={handleGroupDragEnd}
|
handleGroupDragEnd={handleGroupDragEnd}
|
||||||
handleMouseOverStartPoint={handleMouseOverStartPoint}
|
handleMouseOverStartPoint={handleMouseOverStartPoint}
|
||||||
|
|||||||
@ -53,6 +53,7 @@ export function PolygonControls({
|
|||||||
points: [],
|
points: [],
|
||||||
isFinished: false,
|
isFinished: false,
|
||||||
name: "new",
|
name: "new",
|
||||||
|
color: updatedPolygons[activePolygonIndex].color ?? [220, 0, 0],
|
||||||
};
|
};
|
||||||
setPolygons(updatedPolygons);
|
setPolygons(updatedPolygons);
|
||||||
}
|
}
|
||||||
@ -65,6 +66,7 @@ export function PolygonControls({
|
|||||||
points: [],
|
points: [],
|
||||||
isFinished: false,
|
isFinished: false,
|
||||||
name: zoneName,
|
name: zoneName,
|
||||||
|
color: [220, 0, 0],
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
setActivePolygonIndex(polygons.length);
|
setActivePolygonIndex(polygons.length);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { useState } from "react";
|
import { useCallback, useState } from "react";
|
||||||
import { Line, Circle, Group } from "react-konva";
|
import { Line, Circle, Group } from "react-konva";
|
||||||
import { minMax, dragBoundFunc } from "@/utils/canvasUtil";
|
import { minMax, dragBoundFunc } from "@/utils/canvasUtil";
|
||||||
import type { KonvaEventObject } from "konva/lib/Node";
|
import type { KonvaEventObject } from "konva/lib/Node";
|
||||||
@ -10,6 +10,7 @@ type PolygonDrawerProps = {
|
|||||||
flattenedPoints: number[];
|
flattenedPoints: number[];
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
isFinished: boolean;
|
isFinished: boolean;
|
||||||
|
color: number[];
|
||||||
handlePointDragMove: (e: KonvaEventObject<MouseEvent>) => void;
|
handlePointDragMove: (e: KonvaEventObject<MouseEvent>) => void;
|
||||||
handleGroupDragEnd: (e: KonvaEventObject<MouseEvent>) => void;
|
handleGroupDragEnd: (e: KonvaEventObject<MouseEvent>) => void;
|
||||||
handleMouseOverStartPoint: (e: KonvaEventObject<MouseEvent>) => void;
|
handleMouseOverStartPoint: (e: KonvaEventObject<MouseEvent>) => void;
|
||||||
@ -21,6 +22,7 @@ export default function PolygonDrawer({
|
|||||||
flattenedPoints,
|
flattenedPoints,
|
||||||
isActive,
|
isActive,
|
||||||
isFinished,
|
isFinished,
|
||||||
|
color,
|
||||||
handlePointDragMove,
|
handlePointDragMove,
|
||||||
handleGroupDragEnd,
|
handleGroupDragEnd,
|
||||||
handleMouseOverStartPoint,
|
handleMouseOverStartPoint,
|
||||||
@ -66,6 +68,17 @@ export default function PolygonDrawer({
|
|||||||
return { x, y };
|
return { x, y };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const colorString = useCallback(
|
||||||
|
(darkened: boolean) => {
|
||||||
|
if (color.length !== 3) {
|
||||||
|
return "rgb(220,0,0,0.5)";
|
||||||
|
}
|
||||||
|
|
||||||
|
return `rgb(${color[0]},${color[1]},${color[2]},${darkened ? "0.8" : "0.5"})`;
|
||||||
|
},
|
||||||
|
[color],
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Group
|
<Group
|
||||||
name="polygon"
|
name="polygon"
|
||||||
@ -78,10 +91,10 @@ export default function PolygonDrawer({
|
|||||||
>
|
>
|
||||||
<Line
|
<Line
|
||||||
points={flattenedPoints}
|
points={flattenedPoints}
|
||||||
stroke="#aa0000"
|
stroke={colorString(true)}
|
||||||
strokeWidth={3}
|
strokeWidth={3}
|
||||||
closed={isFinished}
|
closed={isFinished}
|
||||||
fill="rgb(220,0,0,0.5)"
|
fill={colorString(false)}
|
||||||
/>
|
/>
|
||||||
{points.map((point, index) => {
|
{points.map((point, index) => {
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
@ -104,7 +117,7 @@ export default function PolygonDrawer({
|
|||||||
x={x}
|
x={x}
|
||||||
y={y}
|
y={y}
|
||||||
radius={vertexRadius}
|
radius={vertexRadius}
|
||||||
fill="#dd0000"
|
fill={colorString(false)}
|
||||||
stroke="#cccccc"
|
stroke="#cccccc"
|
||||||
strokeWidth={2}
|
strokeWidth={2}
|
||||||
draggable={isActive}
|
draggable={isActive}
|
||||||
|
|||||||
@ -34,8 +34,8 @@ const parseCoordinates = (coordinatesString: string) => {
|
|||||||
const points = [];
|
const points = [];
|
||||||
|
|
||||||
for (let i = 0; i < coordinates.length; i += 2) {
|
for (let i = 0; i < coordinates.length; i += 2) {
|
||||||
const x = parseInt(coordinates[i], 10);
|
const x = parseFloat(coordinates[i]);
|
||||||
const y = parseInt(coordinates[i + 1], 10);
|
const y = parseFloat(coordinates[i + 1]);
|
||||||
points.push([x, y]);
|
points.push([x, y]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,12 +132,13 @@ export default function SettingsZones() {
|
|||||||
name,
|
name,
|
||||||
points: interpolatePoints(
|
points: interpolatePoints(
|
||||||
parseCoordinates(zoneData.coordinates),
|
parseCoordinates(zoneData.coordinates),
|
||||||
cameraConfig.detect.width,
|
1,
|
||||||
cameraConfig.detect.height,
|
1,
|
||||||
scaledWidth,
|
scaledWidth,
|
||||||
scaledHeight,
|
scaledHeight,
|
||||||
),
|
),
|
||||||
isFinished: true,
|
isFinished: true,
|
||||||
|
color: zoneData.color,
|
||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,4 +2,5 @@ export type Polygon = {
|
|||||||
name: string;
|
name: string;
|
||||||
points: number[][];
|
points: number[][];
|
||||||
isFinished: boolean;
|
isFinished: boolean;
|
||||||
|
color: number[];
|
||||||
};
|
};
|
||||||
|
|||||||
@ -200,6 +200,7 @@ export interface CameraConfig {
|
|||||||
filters: Record<string, unknown>;
|
filters: Record<string, unknown>;
|
||||||
inertia: number;
|
inertia: number;
|
||||||
objects: string[];
|
objects: string[];
|
||||||
|
color: number[];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user