Inline 1
This commit is contained in:
parent
eef9bf1f26
commit
f7ba28d1fb
2 changed files with 28 additions and 40 deletions
|
@ -1,9 +1,13 @@
|
|||
import { openCache } from "@/next/blob-cache";
|
||||
import log from "@/next/log";
|
||||
import type { BlobOptions } from "types/image";
|
||||
import {
|
||||
DetectedFace,
|
||||
Face,
|
||||
MLSyncContext,
|
||||
MLSyncFileContext,
|
||||
type FaceCrop,
|
||||
type StoredFaceCrop,
|
||||
} from "types/machineLearning";
|
||||
import { imageBitmapToBlob } from "utils/image";
|
||||
import {
|
||||
|
@ -14,7 +18,6 @@ import {
|
|||
getOriginalImageBitmap,
|
||||
isDifferentOrOld,
|
||||
} from "utils/machineLearning";
|
||||
import { storeFaceCrop } from "utils/machineLearning/faceCrop";
|
||||
import mlIDbStorage from "utils/storage/mlIDbStorage";
|
||||
import ReaderService from "./readerService";
|
||||
|
||||
|
@ -225,21 +228,13 @@ class FaceService {
|
|||
face.detection,
|
||||
syncContext.config.faceCrop,
|
||||
);
|
||||
try {
|
||||
face.crop = await storeFaceCrop(
|
||||
face.id,
|
||||
faceCrop,
|
||||
syncContext.config.faceCrop.blobOptions,
|
||||
);
|
||||
} catch (e) {
|
||||
// TODO(MR): Temporarily ignoring errors about failing cache puts
|
||||
// when using a custom scheme in Electron. Needs an alternative
|
||||
// approach, perhaps OPFS.
|
||||
console.error(
|
||||
"Ignoring error when caching face crop, the face crop will not be available",
|
||||
e,
|
||||
);
|
||||
}
|
||||
|
||||
face.crop = await storeFaceCrop(
|
||||
face.id,
|
||||
faceCrop,
|
||||
syncContext.config.faceCrop.blobOptions,
|
||||
);
|
||||
|
||||
const blob = await imageBitmapToBlob(faceCrop.image);
|
||||
faceCrop.image.close();
|
||||
return blob;
|
||||
|
@ -310,3 +305,18 @@ class FaceService {
|
|||
}
|
||||
|
||||
export default new FaceService();
|
||||
|
||||
const storeFaceCrop = async (
|
||||
faceId: string,
|
||||
faceCrop: FaceCrop,
|
||||
blobOptions: BlobOptions,
|
||||
): Promise<StoredFaceCrop> => {
|
||||
const faceCropBlob = await imageBitmapToBlob(faceCrop.image, blobOptions);
|
||||
const faceCropUrl = `/${faceId}`;
|
||||
const faceCropCache = await openCache("face-crops");
|
||||
await faceCropCache.put(faceCropUrl, faceCropBlob);
|
||||
return {
|
||||
imageUrl: faceCropUrl,
|
||||
imageBox: faceCrop.imageBox,
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
import { openCache } from "@/next/blob-cache";
|
||||
import { BlobOptions } from "types/image";
|
||||
import {
|
||||
FaceAlignment,
|
||||
FaceCrop,
|
||||
FaceCropConfig,
|
||||
StoredFaceCrop,
|
||||
} from "types/machineLearning";
|
||||
import { cropWithRotation, imageBitmapToBlob } from "utils/image";
|
||||
import { FaceAlignment, FaceCrop, FaceCropConfig } from "types/machineLearning";
|
||||
import { cropWithRotation } from "utils/image";
|
||||
import { enlargeBox } from ".";
|
||||
import { Box } from "../../../thirdparty/face-api/classes";
|
||||
|
||||
|
@ -33,18 +26,3 @@ export function getFaceCrop(
|
|||
imageBox: paddedBox,
|
||||
};
|
||||
}
|
||||
|
||||
export async function storeFaceCrop(
|
||||
faceId: string,
|
||||
faceCrop: FaceCrop,
|
||||
blobOptions: BlobOptions,
|
||||
): Promise<StoredFaceCrop> {
|
||||
const faceCropBlob = await imageBitmapToBlob(faceCrop.image, blobOptions);
|
||||
const faceCropUrl = `/${faceId}`;
|
||||
const faceCropCache = await openCache("face-crops");
|
||||
await faceCropCache.put(faceCropUrl, faceCropBlob);
|
||||
return {
|
||||
imageUrl: faceCropUrl,
|
||||
imageBox: faceCrop.imageBox,
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue