From b97988e04a6033cb2d777b7742fe51afdd955b2d Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 14 May 2024 13:11:20 +0530 Subject: [PATCH] Move --- .../machineLearning/arcfaceCropService.ts | 2 +- web/apps/photos/src/services/ml/geom.ts | 14 ++++++++++++++ web/apps/photos/src/utils/image/index.ts | 3 +-- .../photos/src/utils/machineLearning/index.ts | 16 +--------------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/web/apps/photos/src/services/machineLearning/arcfaceCropService.ts b/web/apps/photos/src/services/machineLearning/arcfaceCropService.ts index 65d33bb215..77ec03b6b2 100644 --- a/web/apps/photos/src/services/machineLearning/arcfaceCropService.ts +++ b/web/apps/photos/src/services/machineLearning/arcfaceCropService.ts @@ -10,7 +10,7 @@ import { } from "services/ml/types"; import { cropWithRotation } from "utils/image"; import { getArcfaceAlignment } from "utils/machineLearning/faceAlign"; -import { enlargeBox } from "utils/machineLearning/index"; +import { enlargeBox } from "services/ml/geom"; class ArcFaceCropService implements FaceCropService { public method: Versioned; diff --git a/web/apps/photos/src/services/ml/geom.ts b/web/apps/photos/src/services/ml/geom.ts index 1cf51963cf..556e2b309d 100644 --- a/web/apps/photos/src/services/ml/geom.ts +++ b/web/apps/photos/src/services/ml/geom.ts @@ -76,3 +76,17 @@ export class Box implements IRect { return new Box({ x, y, width, height }); } } + +export function enlargeBox(box: Box, factor: number = 1.5) { + const center = new Point(box.x + box.width / 2, box.y + box.height / 2); + + const size = new Point(box.width, box.height); + const newHalfSize = new Point((factor * size.x) / 2, (factor * size.y) / 2); + + return boxFromBoundingBox({ + left: center.x - newHalfSize.x, + top: center.y - newHalfSize.y, + right: center.x + newHalfSize.x, + bottom: center.y + newHalfSize.y, + }); +} diff --git a/web/apps/photos/src/utils/image/index.ts b/web/apps/photos/src/utils/image/index.ts index 39263ab308..bdaf64d735 100644 --- a/web/apps/photos/src/utils/image/index.ts +++ b/web/apps/photos/src/utils/image/index.ts @@ -1,9 +1,8 @@ // these utils only work in env where OffscreenCanvas is available import { Matrix, inverse } from "ml-matrix"; -import { Box, Dimensions } from "services/ml/geom"; +import { Box, Dimensions, enlargeBox } from "services/ml/geom"; import { FaceAlignment } from "services/ml/types"; -import { enlargeBox } from "utils/machineLearning"; export function normalizePixelBetween0And1(pixelValue: number) { return pixelValue / 255.0; diff --git a/web/apps/photos/src/utils/machineLearning/index.ts b/web/apps/photos/src/utils/machineLearning/index.ts index 987eabc00e..1891a18719 100644 --- a/web/apps/photos/src/utils/machineLearning/index.ts +++ b/web/apps/photos/src/utils/machineLearning/index.ts @@ -4,7 +4,7 @@ import log from "@/next/log"; import PQueue from "p-queue"; import DownloadManager from "services/download"; import { getLocalFiles } from "services/fileService"; -import { Box, Dimensions, Point, boxFromBoundingBox } from "services/ml/geom"; +import { Dimensions } from "services/ml/geom"; import { DetectedFace, Face, @@ -18,20 +18,6 @@ import { getRenderableImage } from "utils/file"; import { clamp, warpAffineFloat32List } from "utils/image"; import mlIDbStorage from "utils/storage/mlIDbStorage"; -export function enlargeBox(box: Box, factor: number = 1.5) { - const center = new Point(box.x + box.width / 2, box.y + box.height / 2); - - const size = new Point(box.width, box.height); - const newHalfSize = new Point((factor * size.x) / 2, (factor * size.y) / 2); - - return boxFromBoundingBox({ - left: center.x - newHalfSize.x, - top: center.y - newHalfSize.y, - right: center.x + newHalfSize.x, - bottom: center.y + newHalfSize.y, - }); -} - export function getAllFacesFromMap(allFacesMap: Map>) { const allFaces = [...allFacesMap.values()].flat();