yootd 0.2.4 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/video-player/index.js +48 -5
- package/package.json +1 -1
@@ -13,9 +13,11 @@ import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useRef,
|
|
13
13
|
import { EndPoint } from 'yootd-webrtc-sdk';
|
14
14
|
import { useBem } from "../hooks/useBem";
|
15
15
|
import "./index.scss";
|
16
|
+
import { useQuery } from '@tanstack/react-query';
|
16
17
|
import { throttle } from 'lodash';
|
17
18
|
import { Spin } from "./..";
|
18
19
|
import { useOSS } from "../hooks/useOSS";
|
20
|
+
import { useRequest } from "../hooks/useRequest";
|
19
21
|
import controlBottomBg from "./assets/control-background.png";
|
20
22
|
var PROGRESS_BAR_HEIGHT = 63;
|
21
23
|
var MIN_SCORE = 0.5; // minimum score
|
@@ -60,6 +62,7 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
60
62
|
var poseCanvasRef = useRef(null);
|
61
63
|
var detectAllFacesRef = useRef();
|
62
64
|
var getAdjacentPairsRef = useRef();
|
65
|
+
var request = useRequest();
|
63
66
|
var _useState = useState(null),
|
64
67
|
_useState2 = _slicedToArray(_useState, 2),
|
65
68
|
poseDetector = _useState2[0],
|
@@ -163,6 +166,13 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
163
166
|
_useState46 = _slicedToArray(_useState45, 2),
|
164
167
|
features = _useState46[0],
|
165
168
|
setFeatures = _useState46[1];
|
169
|
+
var _useQuery = useQuery({
|
170
|
+
queryKey: ['config'],
|
171
|
+
queryFn: function queryFn() {
|
172
|
+
return request.get('/v1/education/analysis/analyse/instance/config');
|
173
|
+
}
|
174
|
+
}),
|
175
|
+
configData = _useQuery.data;
|
166
176
|
useImperativeHandle(ref, function () {
|
167
177
|
return {
|
168
178
|
play: function play() {
|
@@ -371,8 +381,32 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
371
381
|
var _iterator = _createForOfIteratorHelper(detections),
|
372
382
|
_step;
|
373
383
|
try {
|
374
|
-
|
384
|
+
var _loop = function _loop() {
|
375
385
|
var person = _step.value;
|
386
|
+
var emotionConfigMap = {
|
387
|
+
neutral: 'calm',
|
388
|
+
happy: 'happy',
|
389
|
+
sad: 'depressed',
|
390
|
+
angry: 'angry',
|
391
|
+
fearful: 'dread',
|
392
|
+
disgusted: 'detest',
|
393
|
+
surprised: 'surprised'
|
394
|
+
};
|
395
|
+
var expression = Object.entries(person.expressions).sort(function (a, b) {
|
396
|
+
return b[1] - a[1];
|
397
|
+
});
|
398
|
+
if ((configData === null || configData === void 0 ? void 0 : configData.content) != null && configData.content.length > 0) {
|
399
|
+
var _configData$content$f;
|
400
|
+
var threshold = (_configData$content$f = configData.content.find(function (item) {
|
401
|
+
return item.configKey === emotionConfigMap[expression[0][0]];
|
402
|
+
})) === null || _configData$content$f === void 0 ? void 0 : _configData$content$f.threshold;
|
403
|
+
if (threshold != null) {
|
404
|
+
if (Math.round(100 * expression[0][1]) < threshold) {
|
405
|
+
return 1; // continue
|
406
|
+
}
|
407
|
+
}
|
408
|
+
}
|
409
|
+
|
376
410
|
// draw box around each face
|
377
411
|
ctx.lineWidth = 3;
|
378
412
|
ctx.strokeStyle = '#7aff00';
|
@@ -383,9 +417,6 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
383
417
|
ctx.stroke();
|
384
418
|
ctx.globalAlpha = 1;
|
385
419
|
// draw text labels
|
386
|
-
var expression = Object.entries(person.expressions).sort(function (a, b) {
|
387
|
-
return b[1] - a[1];
|
388
|
-
});
|
389
420
|
ctx.fillStyle = 'black';
|
390
421
|
// if (faceFeature.character) {
|
391
422
|
// ctx.fillText(
|
@@ -419,6 +450,15 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
419
450
|
male: '男',
|
420
451
|
female: '女'
|
421
452
|
};
|
453
|
+
/* neutral: 'calm',
|
454
|
+
happy: 'happy',
|
455
|
+
sad: 'depressed',
|
456
|
+
angry: 'angry',
|
457
|
+
fearful: 'dread',
|
458
|
+
disgusted: 'detest',
|
459
|
+
surprised: 'surprised',
|
460
|
+
*/
|
461
|
+
|
422
462
|
var emotionMap = {
|
423
463
|
neutral: '平静',
|
424
464
|
happy: '开心',
|
@@ -460,13 +500,16 @@ export var VideoPlayer = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
460
500
|
ctx.fill();
|
461
501
|
}
|
462
502
|
}
|
503
|
+
};
|
504
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
505
|
+
if (_loop()) continue;
|
463
506
|
}
|
464
507
|
} catch (err) {
|
465
508
|
_iterator.e(err);
|
466
509
|
} finally {
|
467
510
|
_iterator.f();
|
468
511
|
}
|
469
|
-
}, []);
|
512
|
+
}, [configData]);
|
470
513
|
var detectFaces = useCallback(function () {
|
471
514
|
return new Promise(function (resolve, reject) {
|
472
515
|
if (videoRef.current != null && detectAllFacesRef.current != null && options != null && faceApiInitialized) {
|