This commit is contained in:
Manav Rathi 2024-05-14 11:09:12 +05:30
parent 0c8549a840
commit fc1957be49
No known key found for this signature in database
3 changed files with 14 additions and 14 deletions

View file

@ -1,6 +1,12 @@
import { workerBridge } from "@/next/worker/worker-bridge"; import { workerBridge } from "@/next/worker/worker-bridge";
import { euclidean } from "hdbscan"; import { euclidean } from "hdbscan";
import { Box, Point, boxFromBoundingBox } from "services/ml/geom"; import {
Box,
Dimensions,
Point,
boxFromBoundingBox,
newBox,
} from "services/ml/geom";
import { import {
FaceDetection, FaceDetection,
FaceDetectionMethod, FaceDetectionMethod,
@ -14,13 +20,11 @@ import {
scale, scale,
translate, translate,
} from "transformation-matrix"; } from "transformation-matrix";
import { Dimensions } from "services/ml/geom";
import { import {
clamp, clamp,
getPixelBilinear, getPixelBilinear,
normalizePixelBetween0And1, normalizePixelBetween0And1,
} from "utils/image"; } from "utils/image";
import { newBox } from "utils/machineLearning";
class YoloFaceDetectionService implements FaceDetectionService { class YoloFaceDetectionService implements FaceDetectionService {
public method: Versioned<FaceDetectionMethod>; public method: Versioned<FaceDetectionMethod>;

View file

@ -21,8 +21,8 @@ export class Point {
} }
export interface Dimensions { export interface Dimensions {
width: number; width: number;
height: number; height: number;
} }
export interface IBoundingBox { export interface IBoundingBox {
@ -39,6 +39,10 @@ export interface IRect {
height: number; height: number;
} }
export function newBox(x: number, y: number, width: number, height: number) {
return new Box({ x, y, width, height });
}
export const boxFromBoundingBox = ({ export const boxFromBoundingBox = ({
left, left,
top, top,

View file

@ -18,20 +18,12 @@ import { getRenderableImage } from "utils/file";
import { clamp, warpAffineFloat32List } from "utils/image"; import { clamp, warpAffineFloat32List } from "utils/image";
import mlIDbStorage from "utils/storage/mlIDbStorage"; import mlIDbStorage from "utils/storage/mlIDbStorage";
export function newBox(x: number, y: number, width: number, height: number) {
return new Box({ x, y, width, height });
}
function getBoxCenterPt(topLeft: Point, bottomRight: Point): Point { function getBoxCenterPt(topLeft: Point, bottomRight: Point): Point {
return topLeft.add(bottomRight.sub(topLeft).div(new Point(2, 2))); return topLeft.add(bottomRight.sub(topLeft).div(new Point(2, 2)));
} }
function getBoxCenter(box: Box): Point {
return getBoxCenterPt(box.topLeft, box.bottomRight);
}
export function enlargeBox(box: Box, factor: number = 1.5) { export function enlargeBox(box: Box, factor: number = 1.5) {
const center = getBoxCenter(box); const center = getBoxCenterPt(box.topLeft, box.bottomRight);
const size = new Point(box.width, box.height); const size = new Point(box.width, box.height);
const newHalfSize = new Point((factor * size.x) / 2, (factor * size.y) / 2); const newHalfSize = new Point((factor * size.x) / 2, (factor * size.y) / 2);