This commit is contained in:
Manav Rathi 2024-05-14 13:11:20 +05:30
parent 373273d368
commit b97988e04a
No known key found for this signature in database
4 changed files with 17 additions and 18 deletions

View file

@ -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<FaceCropMethod>;

View file

@ -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,
});
}

View file

@ -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;

View file

@ -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<number, Array<Face>>) {
const allFaces = [...allFacesMap.values()].flat();