ngx-face-api-js
Version:
Angular directives for face detection and face recognition in the browser. It is a wrapper for face-api.js, so it is not dependent on the browser implementation.
1,104 lines (1,082 loc) • 46.4 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/platform-browser'), require('rxjs'), require('face-api.js'), require('rxjs/operators'), require('@angular/cdk/portal'), require('@angular/core'), require('@angular/cdk/overlay')) :
typeof define === 'function' && define.amd ? define('ngx-face-api-js', ['exports', '@angular/platform-browser', 'rxjs', 'face-api.js', 'rxjs/operators', '@angular/cdk/portal', '@angular/core', '@angular/cdk/overlay'], factory) :
(factory((global['ngx-face-api-js'] = {}),global.ng.platformBrowser,global.rxjs,global['face-api'].js,global.rxjs.operators,global.ng.cdk.portal,global.ng.core,global.ng.cdk.overlay));
}(this, (function (exports,platformBrowser,rxjs,faceapi,operators,portal,core,overlay) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try {
step(generator.next(value));
}
catch (e) {
reject(e);
} }
function rejected(value) { try {
step(generator["throw"](value));
}
catch (e) {
reject(e);
} }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function () { if (t[0] & 1)
throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function () { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f)
throw new TypeError("Generator is already executing.");
while (_)
try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
return t;
if (y = 0, t)
op = [op[0] & 2, t.value];
switch (op[0]) {
case 0:
case 1:
t = op;
break;
case 4:
_.label++;
return { value: op[1], done: false };
case 5:
_.label++;
y = op[1];
op = [0];
continue;
case 7:
op = _.ops.pop();
_.trys.pop();
continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
_ = 0;
continue;
}
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) {
_.label = op[1];
break;
}
if (op[0] === 6 && _.label < t[1]) {
_.label = t[1];
t = op;
break;
}
if (t && _.label < t[2]) {
_.label = t[2];
_.ops.push(op);
break;
}
if (t[2])
_.ops.pop();
_.trys.pop();
continue;
}
op = body.call(thisArg, _);
}
catch (e) {
op = [6, e];
y = 0;
}
finally {
f = t = 0;
}
if (op[0] & 5)
throw op[1];
return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m)
return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
ar.push(r.value);
}
catch (error) {
e = { error: error };
}
finally {
try {
if (r && !r.done && (m = i["return"]))
m.call(i);
}
finally {
if (e)
throw e.error;
}
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DetectTask = /** @class */ (function () {
function DetectTask(option) {
var _this = this;
this.type = option.type;
this.tokens = option.tokens;
this.realtime = option.realtime || false;
this.target = new Promise(( /**
* @param {?} resolver
* @return {?}
*/function (resolver) { return (_this.targetResolver = resolver); }));
}
Object.defineProperty(DetectTask.prototype, "resolveTarget", {
get: /**
* @return {?}
*/ function () {
return this.targetResolver;
},
enumerable: true,
configurable: true
});
/**
* @private
* @param {?} patten
* @param {?} target
* @return {?}
*/
DetectTask.prototype.isMatchPattern = /**
* @private
* @param {?} patten
* @param {?} target
* @return {?}
*/
function (patten, target) {
return patten.every(( /**
* @param {?} item
* @return {?}
*/function (item) { return target.includes(item); }));
};
/**
* @template THIS
* @this {THIS}
* @param {...?} tokens
* @return {THIS}
*/
DetectTask.prototype.with = /**
* @template THIS
* @this {THIS}
* @param {...?} tokens
* @return {THIS}
*/
function () {
var tokens = [];
for (var _i = 0; _i < arguments.length; _i++) {
tokens[_i] = arguments[_i];
}
var _a;
(_a = ( /** @type {?} */(this)).tokens).push.apply(_a, __spread(tokens));
return ( /** @type {?} */(this));
};
/**
* @param {?=} option
* @return {?}
*/
DetectTask.prototype.detect = /**
* @param {?=} option
* @return {?}
*/
function (option) {
return __awaiter(this, void 0, void 0, function () {
var t, _a, _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
case 0:
if (!(this.type === 'all'))
return [3 /*break*/, 2];
_b = (_a = faceapi).detectAllFaces;
return [4 /*yield*/, this.target];
case 1:
t = _b.apply(_a, [_e.sent(), option || undefined]);
return [3 /*break*/, 4];
case 2:
_d = (_c = faceapi).detectSingleFace;
return [4 /*yield*/, this.target];
case 3:
t = _d.apply(_c, [_e.sent(), option || undefined]);
_e.label = 4;
case 4:
if (this.isMatchPattern(['expressions', 'landmarks', 'ageAndGender', 'descriptors'], this.tokens)) {
if (t instanceof faceapi.DetectSingleFaceTask) {
return [2 /*return*/, t
.withFaceLandmarks()
.withFaceExpressions()
.withAgeAndGender()
.withFaceDescriptor()
.run()];
}
else if (t instanceof faceapi.DetectAllFacesTask) {
return [2 /*return*/, t
.withFaceLandmarks()
.withFaceExpressions()
.withAgeAndGender()
.withFaceDescriptors()
.run()];
}
}
else if (this.isMatchPattern(['expressions', 'landmarks', 'descriptors'], this.tokens)) {
if (t instanceof faceapi.DetectSingleFaceTask) {
return [2 /*return*/, t
.withFaceLandmarks()
.withFaceExpressions()
.withFaceDescriptor()
.run()];
}
else if (t instanceof faceapi.DetectAllFacesTask) {
return [2 /*return*/, t
.withFaceLandmarks()
.withFaceExpressions()
.withFaceDescriptors()
.run()];
}
}
else if (this.isMatchPattern(['expressions', 'landmarks', 'ageAndGender'], this.tokens)) {
return [2 /*return*/, t
.withFaceLandmarks()
.withFaceExpressions()
.withAgeAndGender()
.run()];
}
else if (this.isMatchPattern(['expressions', 'landmarks'], this.tokens)) {
return [2 /*return*/, t
.withFaceLandmarks()
.withFaceExpressions()
.run()];
}
else if (this.isMatchPattern(['expressions', 'ageAndGender'], this.tokens)) {
return [2 /*return*/, t
.withFaceExpressions()
.withAgeAndGender()
.run()];
}
else if (this.isMatchPattern(['expressions'], this.tokens)) {
return [2 /*return*/, t.withFaceExpressions().run()];
}
else if (this.isMatchPattern(['landmarks', 'ageAndGender'], this.tokens)) {
return [2 /*return*/, t
.withFaceLandmarks()
.withAgeAndGender()
.run()];
}
else if (this.isMatchPattern(['landmarks'], this.tokens)) {
return [2 /*return*/, t.withFaceLandmarks().run()];
}
return [2 /*return*/, t.run()];
}
});
});
};
return DetectTask;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var FaceDetectionOptions = new core.InjectionToken('ngx-face-api-js.face-detection-options');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var ExpressionsFeatureToken = 'expressions';
/** @type {?} */
var LandmarksFeatureToken = 'landmarks';
/** @type {?} */
var DescriptorsFeatureToken = 'descriptors';
/** @type {?} */
var AgeAndGenderToken = 'ageAndGender';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var SsdMobilenetv1Model = 'SsdMobilenetv1Model';
/** @type {?} */
var MtcnnModel = 'MtcnnModel';
/** @type {?} */
var FaceExpressionModel = 'FaceExpressionModel';
/** @type {?} */
var FaceLandmarkModel = 'FaceLandmarkModel';
/** @type {?} */
var FaceRecognitionModel = 'FaceRecognitionModel';
/** @type {?} */
var TinyFaceDetectorModel = 'TinyFaceDetectorModel';
/** @type {?} */
var AgeAndGenderModel = 'AgeAndGenderModel';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var ModelsUrl = new core.InjectionToken('ngx-face-api-js.models-url');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var ModelLoaderService = /** @class */ (function () {
function ModelLoaderService(modelUrl) {
this.modelUrl = modelUrl;
this.loadedModels = [];
}
/**
* @private
* @param {?} tokens
* @return {?}
*/
ModelLoaderService.prototype.getReqiredModels = /**
* @private
* @param {?} tokens
* @return {?}
*/
function (tokens) {
var _a;
return [SsdMobilenetv1Model].concat(Object.entries((_a = {},
_a[ExpressionsFeatureToken] = [FaceExpressionModel, SsdMobilenetv1Model],
_a[LandmarksFeatureToken] = [FaceLandmarkModel, SsdMobilenetv1Model],
_a[DescriptorsFeatureToken] = [FaceRecognitionModel],
_a[AgeAndGenderToken] = [AgeAndGenderModel],
_a))
.map(( /**
* @param {?} __0
* @return {?}
*/function (_a) {
var _b = __read(_a, 2), key = _b[0], models = _b[1];
return tokens.includes(( /** @type {?} */(key))) ? models : [];
}))
.reduce(( /**
* @param {?} a
* @param {?} b
* @return {?}
*/function (a, b) { return a.concat(b); }))
.filter(( /**
* @param {?} v
* @param {?} i
* @param {?} arr
* @return {?}
*/function (v, i, arr) { return arr.indexOf(v) === i; })));
};
/**
* @private
* @param {?} model
* @return {?}
*/
ModelLoaderService.prototype.mapLoadFunction = /**
* @private
* @param {?} model
* @return {?}
*/
function (model) {
switch (model) {
case SsdMobilenetv1Model:
return faceapi.loadSsdMobilenetv1Model;
case MtcnnModel:
return faceapi.loadMtcnnModel;
case FaceExpressionModel:
return faceapi.loadFaceExpressionModel;
case FaceLandmarkModel:
return faceapi.loadFaceLandmarkModel;
case FaceRecognitionModel:
return faceapi.loadFaceRecognitionModel;
case TinyFaceDetectorModel:
return faceapi.loadTinyFaceDetectorModel;
case AgeAndGenderModel:
return faceapi.loadAgeGenderModel;
}
};
/**
* @param {?} model
* @return {?}
*/
ModelLoaderService.prototype.isLoaded = /**
* @param {?} model
* @return {?}
*/
function (model) {
return this.loadedModels.includes(model);
};
/**
* @param {...?} models
* @return {?}
*/
ModelLoaderService.prototype.load = /**
* @param {...?} models
* @return {?}
*/
function () {
var models = [];
for (var _i = 0; _i < arguments.length; _i++) {
models[_i] = arguments[_i];
}
return __awaiter(this, void 0, void 0, function () {
var loadTargetModels;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
loadTargetModels = models.filter(( /**
* @param {?} m
* @return {?}
*/function (m) { return _this.isLoaded(m) === false; }));
return [4 /*yield*/, Promise.all(loadTargetModels
.map(( /**
* @param {?} m
* @return {?}
*/function (m) { return _this.mapLoadFunction(m); }))
.map(( /**
* @param {?} load
* @return {?}
*/function (load) { return load(_this.modelUrl); })))];
case 1:
_a.sent();
if (loadTargetModels.length >= 0) {
this.loadedModels = loadTargetModels.concat(this.loadedModels);
}
return [2 /*return*/];
}
});
});
};
/**
* @param {?} tokens
* @return {?}
*/
ModelLoaderService.prototype.loadForFeature = /**
* @param {?} tokens
* @return {?}
*/
function (tokens) {
return __awaiter(this, void 0, void 0, function () {
var reqiredModels;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
reqiredModels = this.getReqiredModels(tokens);
console.log({ reqiredModels: reqiredModels });
return [4 /*yield*/, this.load.apply(this, __spread(reqiredModels))];
case 1:
_a.sent();
return [2 /*return*/];
}
});
});
};
ModelLoaderService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
ModelLoaderService.ctorParameters = function () {
return [
{ type: String, decorators: [{ type: core.Inject, args: [ModelsUrl,] }] }
];
};
return ModelLoaderService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var FaceDetectorService = /** @class */ (function () {
function FaceDetectorService(modelLoader, option) {
this.modelLoader = modelLoader;
this.option = option;
}
/**
* @param {?} task
* @return {?}
*/
FaceDetectorService.prototype.detect = /**
* @param {?} task
* @return {?}
*/
function (task) {
var _this = this;
if (task.realtime === true) {
return rxjs.of(task).pipe(operators.switchMap(( /**
* @param {?} t
* @return {?}
*/function (t) {
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, t.target];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
})), operators.switchMap(( /**
* @param {?} video
* @return {?}
*/function (video) { return rxjs.fromEvent(video, 'loadeddata'); })), operators.switchMap(( /**
* @return {?}
*/function () { return _this.modelLoader.loadForFeature(task.tokens); })), operators.switchMap(( /**
* @return {?}
*/function () { return rxjs.interval(300); })), operators.switchMap(( /**
* @return {?}
*/function () { return task.detect(_this.option); })), operators.shareReplay(1));
}
return rxjs.of(task).pipe(operators.switchMap(( /**
* @param {?} t
* @return {?}
*/function (t) {
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, t.target];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
})), operators.switchMap(( /**
* @param {?} image
* @return {?}
*/function (image) { return rxjs.fromEvent(image, 'load'); })), operators.switchMap(( /**
* @return {?}
*/function () {
return __awaiter(_this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.modelLoader.loadForFeature(task.tokens)];
case 1: return [2 /*return*/, _a.sent()];
}
});
});
})), operators.switchMap(( /**
* @return {?}
*/function () { return task.detect(_this.option); })), operators.shareReplay(1));
};
FaceDetectorService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
FaceDetectorService.ctorParameters = function () {
return [
{ type: ModelLoaderService },
{ type: undefined, decorators: [{ type: core.Optional }, { type: core.Inject, args: [FaceDetectionOptions,] }] }
];
};
return FaceDetectorService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DetectionResultComponent = /** @class */ (function () {
function DetectionResultComponent(task, el, renderer, faceDetector) {
this.task = task;
this.el = el;
this.renderer = renderer;
this.faceDetector = faceDetector;
this.subscription = new rxjs.Subscription();
this.resize$ = new rxjs.Subject();
}
Object.defineProperty(DetectionResultComponent.prototype, "canvas", {
get: /**
* @private
* @return {?}
*/ function () {
return this.canvasEl.nativeElement;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
DetectionResultComponent.prototype.onResize = /**
* @return {?}
*/
function () {
this.resize$.next('onResize');
};
/**
* @private
* @param {?} result
* @return {?}
*/
DetectionResultComponent.prototype.convertResultToArray = /**
* @private
* @param {?} result
* @return {?}
*/
function (result) {
if (Array.isArray(result)) {
return result;
}
return [result];
};
/**
* @return {?}
*/
DetectionResultComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
this.subscription.add(rxjs.combineLatest(this.faceDetector.detect(this.task), this.resize$.pipe(operators.startWith('init')))
.pipe(operators.map(( /**
* @param {?} __0
* @return {?}
*/function (_a) {
var _b = __read(_a, 1), result = _b[0];
return _this.convertResultToArray(result);
})))
.subscribe(( /**
* @param {?} result
* @return {?}
*/function (result) { return _this.draw(result); })));
};
/**
* @return {?}
*/
DetectionResultComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.subscription.unsubscribe();
};
/**
* @private
* @param {?} results
* @return {?}
*/
DetectionResultComponent.prototype.draw = /**
* @private
* @param {?} results
* @return {?}
*/
function (results) {
return __awaiter(this, void 0, void 0, function () {
var target, width, height, detectionsForSize, resizeResults;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.task.target];
case 1:
target = _a.sent();
width = target.width, height = target.height;
if (target instanceof HTMLVideoElement) {
height = target.videoHeight;
width = target.videoWidth;
}
detectionsForSize = faceapi.resizeResults(results.map(( /**
* @param {?} result
* @return {?}
*/function (result) {
return result instanceof faceapi.FaceDetection ? result : result.detection;
})), { width: width, height: height });
this.canvas.width = width;
this.canvas.height = height;
this.renderer.setStyle(this.canvas, 'width', width + "px");
this.renderer.setStyle(this.canvas, 'height', height + "px");
if (this.task.tokens.length >= 1) {
faceapi.draw.drawDetections(this.canvas, detectionsForSize);
resizeResults = faceapi.resizeResults(results, { width: width, height: height });
if (this.task.tokens.includes('expressions')) {
faceapi.draw.drawFaceExpressions(this.canvas, resizeResults.map(( /**
* @param {?} __0
* @return {?}
*/function (_a) {
var detection = _a.detection, expressions = _a.expressions;
return ({
position: detection.box,
expressions: expressions,
});
})));
}
if (this.task.tokens.includes('landmarks')) {
faceapi.draw.drawFaceLandmarks(this.canvas, resizeResults.map(( /**
* @param {?} __0
* @return {?}
*/function (_a) {
var landmarks = _a.landmarks;
return landmarks;
})));
}
if (this.task.tokens.includes('ageAndGender')) {
resizeResults.forEach(( /**
* @param {?} result
* @return {?}
*/function (result) {
var age = result.age, gender = result.gender, genderProbability = result.genderProbability;
/** @type {?} */
var text = new faceapi.draw.DrawTextField([
faceapi.round(age, 0) + " years",
gender + " (" + faceapi.round(genderProbability) + ")",
], result.detection.box.bottomLeft);
text.draw(_this.canvas);
}));
}
}
else {
faceapi.draw.drawDetections(this.canvas, detectionsForSize);
}
return [2 /*return*/];
}
});
});
};
DetectionResultComponent.decorators = [
{ type: core.Component, args: [{
template: "<canvas #canvas></canvas>\n",
styles: ["canvas{width:100%;height:100%}"]
}] }
];
/** @nocollapse */
DetectionResultComponent.ctorParameters = function () {
return [
{ type: DetectTask },
{ type: core.ElementRef },
{ type: core.Renderer2 },
{ type: FaceDetectorService }
];
};
DetectionResultComponent.propDecorators = {
canvasEl: [{ type: core.ViewChild, args: ['canvas',] }],
onResize: [{ type: core.HostListener, args: ['window:resize',] }]
};
return DetectionResultComponent;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
*/
var /**
* @abstract
*/ AbstractDetectDirective = /** @class */ (function () {
function AbstractDetectDirective(el, overlay$$1, injector) {
this.el = el;
this.overlay = overlay$$1;
this.injector = injector;
this.with = [];
}
/**
* @return {?}
*/
AbstractDetectDirective.prototype.ngOnInit = /**
* @return {?}
*/
function () {
this.task = new DetectTask({
type: this.type,
tokens: this.with,
realtime: this.stream,
});
};
Object.defineProperty(AbstractDetectDirective.prototype, "orverlayPositionStrategy", {
get: /**
* @private
* @return {?}
*/ function () {
return this.overlay
.position()
.flexibleConnectedTo(this.el)
.withPositions([
{
overlayX: 'start',
overlayY: 'top',
originX: 'start',
originY: 'top',
},
])
.withFlexibleDimensions(false)
.withLockedPosition(true);
},
enumerable: true,
configurable: true
});
/**
* @private
* @return {?}
*/
AbstractDetectDirective.prototype.createOverlay = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var scrollStrategy = this.overlay.scrollStrategies.reposition();
/** @type {?} */
var config = new overlay.OverlayConfig({
positionStrategy: this.orverlayPositionStrategy,
scrollStrategy: scrollStrategy,
hasBackdrop: false,
});
return this.overlay.create(config);
};
/**
* @private
* @return {?}
*/
AbstractDetectDirective.prototype.createInjector = /**
* @private
* @return {?}
*/
function () {
return core.Injector.create({
parent: this.injector,
providers: [
{
provide: DetectTask,
useValue: this.task,
},
],
});
};
/**
* @return {?}
*/
AbstractDetectDirective.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
this.task.resolveTarget(this.el.nativeElement);
/** @type {?} */
var overlayRef = this.createOverlay();
/** @type {?} */
var injector = this.createInjector();
/** @type {?} */
var portal$$1 = new portal.ComponentPortal(DetectionResultComponent, undefined, injector);
overlayRef.attach(portal$$1);
};
return AbstractDetectDirective;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DetectAllFacesImgDirective = /** @class */ (function (_super) {
__extends(DetectAllFacesImgDirective, _super);
function DetectAllFacesImgDirective(el, overlay$$1, injector) {
var _this = _super.call(this, el, overlay$$1, injector) || this;
_this.with = [];
_this.type = 'all';
_this.stream = false;
return _this;
}
DetectAllFacesImgDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'img[allFaces]',
exportAs: 'faces',
},] }
];
/** @nocollapse */
DetectAllFacesImgDirective.ctorParameters = function () {
return [
{ type: core.ElementRef },
{ type: overlay.Overlay },
{ type: core.Injector }
];
};
DetectAllFacesImgDirective.propDecorators = {
with: [{ type: core.Input }]
};
return DetectAllFacesImgDirective;
}(AbstractDetectDirective));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DetectSingleFaceImgDirective = /** @class */ (function (_super) {
__extends(DetectSingleFaceImgDirective, _super);
function DetectSingleFaceImgDirective(el, overlay$$1, injector) {
var _this = _super.call(this, el, overlay$$1, injector) || this;
_this.with = [];
_this.type = 'single';
_this.stream = false;
return _this;
}
/**
* @return {?}
*/
DetectSingleFaceImgDirective.prototype.ngOnInit = /**
* @return {?}
*/
function () {
this.task = new DetectTask({
type: this.type,
tokens: this.with,
realtime: this.stream,
});
};
DetectSingleFaceImgDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'img[singleFace]',
exportAs: 'face',
},] }
];
/** @nocollapse */
DetectSingleFaceImgDirective.ctorParameters = function () {
return [
{ type: core.ElementRef },
{ type: overlay.Overlay },
{ type: core.Injector }
];
};
DetectSingleFaceImgDirective.propDecorators = {
with: [{ type: core.Input }]
};
return DetectSingleFaceImgDirective;
}(AbstractDetectDirective));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DetectAllFacesVideoDirective = /** @class */ (function (_super) {
__extends(DetectAllFacesVideoDirective, _super);
function DetectAllFacesVideoDirective(el, overlay$$1, injector) {
var _this = _super.call(this, el, overlay$$1, injector) || this;
_this.with = [];
_this.type = 'all';
_this.stream = true;
return _this;
}
DetectAllFacesVideoDirective.decorators = [
{ type: core.Directive, args: [{
selector: 'video[allFaces]',
exportAs: 'faces',
},] }
];
/** @nocollapse */
DetectAllFacesVideoDirective.ctorParameters = function () {
return [
{ type: core.ElementRef },
{ type: overlay.Overlay },
{ type: core.Injector }
];
};
DetectAllFacesVideoDirective.propDecorators = {
with: [{ type: core.Input }]
};
return DetectAllFacesVideoDirective;
}(AbstractDetectDirective));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NgxFaceApiJsModule = /** @class */ (function () {
function NgxFaceApiJsModule() {
}
/**
* @param {?} options
* @return {?}
*/
NgxFaceApiJsModule.forRoot = /**
* @param {?} options
* @return {?}
*/
function (options) {
return {
ngModule: NgxFaceApiJsModule,
providers: __spread([
{
provide: ModelsUrl,
useValue: options.modelsUrl,
},
ModelLoaderService,
FaceDetectorService
], [
options.faceDetectionOptions
? {
provide: FaceDetectionOptions,
useValue: options.faceDetectionOptions,
}
: [],
]),
};
};
NgxFaceApiJsModule.decorators = [
{ type: core.NgModule, args: [{
declarations: [
DetectionResultComponent,
DetectAllFacesImgDirective,
DetectSingleFaceImgDirective,
DetectAllFacesVideoDirective,
],
imports: [platformBrowser.BrowserModule, overlay.OverlayModule, portal.PortalModule],
exports: [
DetectAllFacesImgDirective,
DetectSingleFaceImgDirective,
DetectAllFacesVideoDirective,
],
entryComponents: [DetectionResultComponent],
},] }
];
return NgxFaceApiJsModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
exports.DetectTask = DetectTask;
exports.FaceDetectionOptions = FaceDetectionOptions;
exports.ExpressionsFeatureToken = ExpressionsFeatureToken;
exports.LandmarksFeatureToken = LandmarksFeatureToken;
exports.DescriptorsFeatureToken = DescriptorsFeatureToken;
exports.AgeAndGenderToken = AgeAndGenderToken;
exports.SsdMobilenetv1Model = SsdMobilenetv1Model;
exports.MtcnnModel = MtcnnModel;
exports.FaceExpressionModel = FaceExpressionModel;
exports.FaceLandmarkModel = FaceLandmarkModel;
exports.FaceRecognitionModel = FaceRecognitionModel;
exports.TinyFaceDetectorModel = TinyFaceDetectorModel;
exports.AgeAndGenderModel = AgeAndGenderModel;
exports.ModelsUrl = ModelsUrl;
exports.FaceDetectorService = FaceDetectorService;
exports.ModelLoaderService = ModelLoaderService;
exports.NgxFaceApiJsModule = NgxFaceApiJsModule;
exports.ɵa = DetectionResultComponent;
exports.ɵc = AbstractDetectDirective;
exports.ɵb = DetectAllFacesImgDirective;
exports.ɵe = DetectAllFacesVideoDirective;
exports.ɵd = DetectSingleFaceImgDirective;
Object.defineProperty(exports, '__esModule', { value: true });
})));
//# sourceMappingURL=ngx-face-api-js.umd.js.map