@vladmandic/face-api
Version:
FaceAPI: AI-powered Face Detection & Rotation Tracking, Face Description & Recognition, Age & Gender & Emotion Prediction for Browser and NodeJS using TensorFlow/JS
29 lines (23 loc) • 530 B
text/typescript
import { Point } from '../classes/index';
export function drawContour(
ctx: CanvasRenderingContext2D,
points: Point[],
isClosed = false,
) {
ctx.beginPath();
points.slice(1).forEach(({ x, y }, prevIdx) => {
const from = points[prevIdx];
ctx.moveTo(from.x, from.y);
ctx.lineTo(x, y);
});
if (isClosed) {
const from = points[points.length - 1];
const to = points[0];
if (!from || !to) {
return;
}
ctx.moveTo(from.x, from.y);
ctx.lineTo(to.x, to.y);
}
ctx.stroke();
}