face-api/build/resizeResults.js

27 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-08-20 02:10:42 +02:00
import { Dimensions } from './classes';
import { FaceDetection } from './classes/FaceDetection';
import { FaceLandmarks } from './classes/FaceLandmarks';
import { extendWithFaceDetection, isWithFaceDetection } from './factories/WithFaceDetection';
import { extendWithFaceLandmarks, isWithFaceLandmarks } from './factories/WithFaceLandmarks';
export function resizeResults(results, dimensions) {
const { width, height } = new Dimensions(dimensions.width, dimensions.height);
2020-08-18 14:04:33 +02:00
if (width <= 0 || height <= 0) {
throw new Error(`resizeResults - invalid dimensions: ${JSON.stringify({ width, height })}`);
}
if (Array.isArray(results)) {
return results.map(obj => resizeResults(obj, { width, height }));
}
2020-08-20 02:10:42 +02:00
if (isWithFaceLandmarks(results)) {
2020-08-18 14:04:33 +02:00
const resizedDetection = results.detection.forSize(width, height);
const resizedLandmarks = results.unshiftedLandmarks.forSize(resizedDetection.box.width, resizedDetection.box.height);
2020-08-20 02:10:42 +02:00
return extendWithFaceLandmarks(extendWithFaceDetection(results, resizedDetection), resizedLandmarks);
2020-08-18 14:04:33 +02:00
}
2020-08-20 02:10:42 +02:00
if (isWithFaceDetection(results)) {
return extendWithFaceDetection(results, results.detection.forSize(width, height));
2020-08-18 14:04:33 +02:00
}
2020-08-20 02:10:42 +02:00
if (results instanceof FaceLandmarks || results instanceof FaceDetection) {
2020-08-18 14:04:33 +02:00
return results.forSize(width, height);
}
return results;
}
//# sourceMappingURL=resizeResults.js.map