gpt4 book ai didi

javascript - Clmtrackr 无法使用响应式 html5 摄像头视频

转载 作者:行者123 更新时间:2023-11-28 04:15:41 24 4
gpt4 key购买 nike

我使用clmtrackr来跟踪我的脸部,但是当我将视频标签的宽度设置为100%时,它无法跟踪脸部。我尝试将canvas标签的宽度设置为与video标签的宽度相同,但仍然无法工作。

<div style="text-align:center;">
<div style="border: 1px solid #ccc; display:inline-block; position:relative;">
<video id="inputVideo" width="100%" height="auto" autoplay></video>
<canvas id="canvas" width="100%" height="auto" style="position:absolute; top:0; left:0;"></canvas>
</div>
</div>

<script src="clmtrackr.min.js"></script>
<script type="text/javascript">
// Put event listeners into place
window.addEventListener("DOMContentLoaded", function() {
// Grab elements, create settings, etc.
var canvas = document.getElementById("canvas"),
context = canvas.getContext("2d"),
video = document.getElementById("inputVideo"),
videoObj = { "video": true },
videoFace = document.getElementById("video-face"),
errBack = function(error) {
console.log("Video capture error: ", error.code);
};
if(navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
// Not adding `{ audio: true }` since we only want video now
navigator.mediaDevices.getUserMedia({ video: true }).then(function(stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
});
} else if(navigator.getUserMedia) { // Standard
navigator.getUserMedia(videoObj, function(stream) {
video.src = stream;
video.play();
}, errBack);
} else if(navigator.webkitGetUserMedia) { // WebKit-prefixed
navigator.webkitGetUserMedia(videoObj, function(stream){
video.src = window.webkitURL.createObjectURL(stream);
video.play();
}, errBack);
}
var ctracker = new clm.tracker();
ctracker.init();
ctracker.start(video);

function positionLoop() {
requestAnimationFrame(positionLoop);
var positions = ctracker.getCurrentPosition();
}
positionLoop();
function drawLoop() {
requestAnimationFrame(drawLoop);
context.clearRect(0, 0, canvas.width, canvas.height);
ctracker.draw(canvas);
}
drawLoop();
});
</script>

为什么视频的宽度必须设置为640,高度设置为480才能追踪人脸?如何使用响应式 width='100%' 和 height='auto' 来修复它?

最佳答案

您的网络摄像头分辨率应为640x480,并且您正在尝试拍摄更高分辨率的帧(宽度='100%')。我遇到了同样的问题,并通过减少视频元素的宽度-高度属性来修复它。

关于javascript - Clmtrackr 无法使用响应式 html5 摄像头视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45882268/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com