移除cv,请使用@yizhi/cv包

This commit is contained in:
2025-03-17 12:24:30 +08:00
parent b48d2daffb
commit 6bf7db1f4c
22 changed files with 72 additions and 355 deletions

View File

@ -1,5 +1,4 @@
import { writeFileSync } from "fs";
import { cv } from "../../cv";
import cv from "@yizhi/cv";
import { ImageCropOption, ImageSource, Model } from "../common/model";
import { convertImage } from "../common/processors";
import { FaceAlignmentResult, FacePoint } from "./common";
@ -39,10 +38,10 @@ export class PFLD extends Model {
private async doPredict(image: cv.Mat, option?: PFLDPredictOption) {
const input = this.input;
if (option?.crop) image = image.crop(option.crop.sx, option.crop.sy, option.crop.sw, option.crop.sh);
const ratioWidth = image.width / input.shape[3];
const ratioHeight = image.height / input.shape[2];
image = image.resize(input.shape[3], input.shape[2]);
if (option?.crop) image = cv.crop(image, option.crop);
const ratioWidth = image.cols / input.shape[3];
const ratioHeight = image.rows / input.shape[2];
image = cv.resize(image, input.shape[3], input.shape[2]);
const nchwImageData = convertImage(image.data, { sourceImageFormat: "bgr", targetColorFormat: "bgr", targetShapeFormat: "nchw", targetNormalize: { mean: [0], std: [255] } })
@ -59,8 +58,8 @@ export class PFLD extends Model {
const points: FacePoint[] = [];
for (let i = 0; i < pointsBuffer.length; i += 2) {
const x = pointsBuffer[i] * image.width * ratioWidth;
const y = pointsBuffer[i + 1] * image.height * ratioHeight;
const x = pointsBuffer[i] * image.cols * ratioWidth;
const y = pointsBuffer[i + 1] * image.rows * ratioHeight;
points.push({ x, y });
}