face-api/build/draw/drawDetections.js

19 lines
874 B
JavaScript
Raw Normal View History

2020-08-20 02:10:42 +02:00
import { Box } from '../classes';
import { FaceDetection } from '../classes/FaceDetection';
import { isWithFaceDetection } from '../factories/WithFaceDetection';
import { round } from '../utils';
import { DrawBox } from './DrawBox';
export function drawDetections(canvasArg, detections) {
2020-08-18 14:04:33 +02:00
const detectionsArray = Array.isArray(detections) ? detections : [detections];
detectionsArray.forEach(det => {
2020-08-20 02:10:42 +02:00
const score = det instanceof FaceDetection
2020-08-18 14:04:33 +02:00
? det.score
2020-08-20 02:10:42 +02:00
: (isWithFaceDetection(det) ? det.detection.score : undefined);
const box = det instanceof FaceDetection
2020-08-18 14:04:33 +02:00
? det.box
2020-08-20 02:10:42 +02:00
: (isWithFaceDetection(det) ? det.detection.box : new Box(det));
const label = score ? `${round(score)}` : undefined;
new DrawBox(box, { label }).draw(canvasArg);
2020-08-18 14:04:33 +02:00
});
}
//# sourceMappingURL=drawDetections.js.map