resizeResults.js 1.5 KB

123456789101112131415161718192021222324252627
  1. import { Dimensions } from './classes';
  2. import { FaceDetection } from './classes/FaceDetection';
  3. import { FaceLandmarks } from './classes/FaceLandmarks';
  4. import { extendWithFaceDetection, isWithFaceDetection } from './factories/WithFaceDetection';
  5. import { extendWithFaceLandmarks, isWithFaceLandmarks } from './factories/WithFaceLandmarks';
  6. export function resizeResults(results, dimensions) {
  7. var _a = new Dimensions(dimensions.width, dimensions.height), width = _a.width, height = _a.height;
  8. if (width <= 0 || height <= 0) {
  9. throw new Error("resizeResults - invalid dimensions: " + JSON.stringify({ width: width, height: height }));
  10. }
  11. if (Array.isArray(results)) {
  12. return results.map(function (obj) { return resizeResults(obj, { width: width, height: height }); });
  13. }
  14. if (isWithFaceLandmarks(results)) {
  15. var resizedDetection = results.detection.forSize(width, height);
  16. var resizedLandmarks = results.unshiftedLandmarks.forSize(resizedDetection.box.width, resizedDetection.box.height);
  17. return extendWithFaceLandmarks(extendWithFaceDetection(results, resizedDetection), resizedLandmarks);
  18. }
  19. if (isWithFaceDetection(results)) {
  20. return extendWithFaceDetection(results, results.detection.forSize(width, height));
  21. }
  22. if (results instanceof FaceLandmarks || results instanceof FaceDetection) {
  23. return results.forSize(width, height);
  24. }
  25. return results;
  26. }
  27. //# sourceMappingURL=resizeResults.js.map