resizeResults.js 1.7 KB

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var classes_1 = require("./classes");
  4. var FaceDetection_1 = require("./classes/FaceDetection");
  5. var FaceLandmarks_1 = require("./classes/FaceLandmarks");
  6. var WithFaceDetection_1 = require("./factories/WithFaceDetection");
  7. var WithFaceLandmarks_1 = require("./factories/WithFaceLandmarks");
  8. function resizeResults(results, dimensions) {
  9. var _a = new classes_1.Dimensions(dimensions.width, dimensions.height), width = _a.width, height = _a.height;
  10. if (width <= 0 || height <= 0) {
  11. throw new Error("resizeResults - invalid dimensions: " + JSON.stringify({ width: width, height: height }));
  12. }
  13. if (Array.isArray(results)) {
  14. return results.map(function (obj) { return resizeResults(obj, { width: width, height: height }); });
  15. }
  16. if (WithFaceLandmarks_1.isWithFaceLandmarks(results)) {
  17. var resizedDetection = results.detection.forSize(width, height);
  18. var resizedLandmarks = results.unshiftedLandmarks.forSize(resizedDetection.box.width, resizedDetection.box.height);
  19. return WithFaceLandmarks_1.extendWithFaceLandmarks(WithFaceDetection_1.extendWithFaceDetection(results, resizedDetection), resizedLandmarks);
  20. }
  21. if (WithFaceDetection_1.isWithFaceDetection(results)) {
  22. return WithFaceDetection_1.extendWithFaceDetection(results, results.detection.forSize(width, height));
  23. }
  24. if (results instanceof FaceLandmarks_1.FaceLandmarks || results instanceof FaceDetection_1.FaceDetection) {
  25. return results.forSize(width, height);
  26. }
  27. return results;
  28. }
  29. exports.resizeResults = resizeResults;
  30. //# sourceMappingURL=resizeResults.js.map