<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>demo</title>
<script src="./build/tracking-min.js"></script>
<script src="./build/data/face-min.js"></script>
<style>
video,
canvas {
position: absolute;
}
</style>
</head>
<body>
<div class="demo-container">
<video id="video" width="320" height="240" preload autoplay loop muted></video>
<canvas id="canvas" width="320" height="240"></canvas>
</div>
<script>
window.onload = function () {
// 视频显示
var video = document.getElementById('video');
// 绘图
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
var tracker = new tracking.ObjectTracker('face');
// 设置识别的放大比例
tracker.setInitialScale(4);
// 设置步长
tracker.setStepSize(2);
// 边缘密度
tracker.setEdgesDensity(0.1);
// 启动摄像头,并且识别视频内容
tracking.track('#video', tracker, {
camera: true
});
tracker.on('track', function (event) {
context.clearRect(0, 0, canvas.width, canvas.height);
// 绘制
event.data.forEach(function (rect) {
context.strokeStyle = '#a64ceb';
context.strokeRect(rect.x, rect.y, rect.width, rect.height);
});
});
};
</script>
</body>
</html>
tracking.js示例 - 浏览器中检测摄像头中的人脸
最新推荐文章于 2023-10-20 17:29:11 发布
该博客演示了如何利用tracking.js库进行实时人脸识别。通过加载'face-min.js'数据,设置跟踪参数并启动摄像头,实现对视频中人脸的检测和绘制。在网页上,视频和canvas元素用于显示和处理捕捉到的人脸。
摘要由CSDN通过智能技术生成