ComputeFaceDescriptorsTasks.js 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var WithFaceDescriptor_1 = require("../factories/WithFaceDescriptor");
  5. var ComposableTask_1 = require("./ComposableTask");
  6. var extractFacesAndComputeResults_1 = require("./extractFacesAndComputeResults");
  7. var nets_1 = require("./nets");
  8. var PredictAgeAndGenderTask_1 = require("./PredictAgeAndGenderTask");
  9. var PredictFaceExpressionsTask_1 = require("./PredictFaceExpressionsTask");
  10. var ComputeFaceDescriptorsTaskBase = /** @class */ (function (_super) {
  11. tslib_1.__extends(ComputeFaceDescriptorsTaskBase, _super);
  12. function ComputeFaceDescriptorsTaskBase(parentTask, input) {
  13. var _this = _super.call(this) || this;
  14. _this.parentTask = parentTask;
  15. _this.input = input;
  16. return _this;
  17. }
  18. return ComputeFaceDescriptorsTaskBase;
  19. }(ComposableTask_1.ComposableTask));
  20. exports.ComputeFaceDescriptorsTaskBase = ComputeFaceDescriptorsTaskBase;
  21. var ComputeAllFaceDescriptorsTask = /** @class */ (function (_super) {
  22. tslib_1.__extends(ComputeAllFaceDescriptorsTask, _super);
  23. function ComputeAllFaceDescriptorsTask() {
  24. return _super !== null && _super.apply(this, arguments) || this;
  25. }
  26. ComputeAllFaceDescriptorsTask.prototype.run = function () {
  27. return tslib_1.__awaiter(this, void 0, void 0, function () {
  28. var parentResults, descriptors;
  29. return tslib_1.__generator(this, function (_a) {
  30. switch (_a.label) {
  31. case 0: return [4 /*yield*/, this.parentTask];
  32. case 1:
  33. parentResults = _a.sent();
  34. return [4 /*yield*/, extractFacesAndComputeResults_1.extractAllFacesAndComputeResults(parentResults, this.input, function (faces) { return Promise.all(faces.map(function (face) {
  35. return nets_1.nets.faceRecognitionNet.computeFaceDescriptor(face);
  36. })); }, null, function (parentResult) { return parentResult.landmarks.align(null, { useDlibAlignment: true }); })];
  37. case 2:
  38. descriptors = _a.sent();
  39. return [2 /*return*/, descriptors.map(function (descriptor, i) { return WithFaceDescriptor_1.extendWithFaceDescriptor(parentResults[i], descriptor); })];
  40. }
  41. });
  42. });
  43. };
  44. ComputeAllFaceDescriptorsTask.prototype.withFaceExpressions = function () {
  45. return new PredictFaceExpressionsTask_1.PredictAllFaceExpressionsWithFaceAlignmentTask(this, this.input);
  46. };
  47. ComputeAllFaceDescriptorsTask.prototype.withAgeAndGender = function () {
  48. return new PredictAgeAndGenderTask_1.PredictAllAgeAndGenderWithFaceAlignmentTask(this, this.input);
  49. };
  50. return ComputeAllFaceDescriptorsTask;
  51. }(ComputeFaceDescriptorsTaskBase));
  52. exports.ComputeAllFaceDescriptorsTask = ComputeAllFaceDescriptorsTask;
  53. var ComputeSingleFaceDescriptorTask = /** @class */ (function (_super) {
  54. tslib_1.__extends(ComputeSingleFaceDescriptorTask, _super);
  55. function ComputeSingleFaceDescriptorTask() {
  56. return _super !== null && _super.apply(this, arguments) || this;
  57. }
  58. ComputeSingleFaceDescriptorTask.prototype.run = function () {
  59. return tslib_1.__awaiter(this, void 0, void 0, function () {
  60. var parentResult, descriptor;
  61. return tslib_1.__generator(this, function (_a) {
  62. switch (_a.label) {
  63. case 0: return [4 /*yield*/, this.parentTask];
  64. case 1:
  65. parentResult = _a.sent();
  66. if (!parentResult) {
  67. return [2 /*return*/];
  68. }
  69. return [4 /*yield*/, extractFacesAndComputeResults_1.extractSingleFaceAndComputeResult(parentResult, this.input, function (face) { return nets_1.nets.faceRecognitionNet.computeFaceDescriptor(face); }, null, function (parentResult) { return parentResult.landmarks.align(null, { useDlibAlignment: true }); })];
  70. case 2:
  71. descriptor = _a.sent();
  72. return [2 /*return*/, WithFaceDescriptor_1.extendWithFaceDescriptor(parentResult, descriptor)];
  73. }
  74. });
  75. });
  76. };
  77. ComputeSingleFaceDescriptorTask.prototype.withFaceExpressions = function () {
  78. return new PredictFaceExpressionsTask_1.PredictSingleFaceExpressionsWithFaceAlignmentTask(this, this.input);
  79. };
  80. ComputeSingleFaceDescriptorTask.prototype.withAgeAndGender = function () {
  81. return new PredictAgeAndGenderTask_1.PredictSingleAgeAndGenderWithFaceAlignmentTask(this, this.input);
  82. };
  83. return ComputeSingleFaceDescriptorTask;
  84. }(ComputeFaceDescriptorsTaskBase));
  85. exports.ComputeSingleFaceDescriptorTask = ComputeSingleFaceDescriptorTask;
  86. //# sourceMappingURL=ComputeFaceDescriptorsTasks.js.map