admin管理员组文章数量:1379408
Im running out of ideas. i have been trying to get the getUserMedia dynamically to select macro camera or atleast focus. Im making barcode(ean) reader and if i put barcode close to camera then I don't get any focusing.
async function startCamera() {
try {
if (videoStream) {
videoStream.getTracks().forEach(track => track.stop());
}
videoStream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: {exact: "environment"},
focusMode: {ideal: "continuous"}
}
});
const $videoElement = $("#camera-feed");
$videoElement[0].srcObject = videoStream;
$videoElement.on("loadedmetadata", function () {
this.play();
$(".scanning-line").fadeIn(300).addClass("scan-active");
$videoElement.css({ opacity: 1, transform: "scale(1)" }).fadeIn();
startScanner();
});
} catch (err) {
$(".scanning-line").fadeOut(300);
}
}
I tried using AI help but It does not give any good ideas to try, most of them I have tried and failed.
Im running out of ideas. i have been trying to get the getUserMedia dynamically to select macro camera or atleast focus. Im making barcode(ean) reader and if i put barcode close to camera then I don't get any focusing.
async function startCamera() {
try {
if (videoStream) {
videoStream.getTracks().forEach(track => track.stop());
}
videoStream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: {exact: "environment"},
focusMode: {ideal: "continuous"}
}
});
const $videoElement = $("#camera-feed");
$videoElement[0].srcObject = videoStream;
$videoElement.on("loadedmetadata", function () {
this.play();
$(".scanning-line").fadeIn(300).addClass("scan-active");
$videoElement.css({ opacity: 1, transform: "scale(1)" }).fadeIn();
startScanner();
});
} catch (err) {
$(".scanning-line").fadeOut(300);
}
}
I tried using AI help but It does not give any good ideas to try, most of them I have tried and failed.
Share Improve this question asked Mar 19 at 18:56 DexxDexx 196 bronze badges 1- I can't imagine there's a consistent API that allows you to control the camera on such a low-level (to change focus). – Spectric Commented Mar 19 at 23:33
1 Answer
Reset to default 0There is no way to get camera to focus or use macro camera, but what did work was setting the zoom value to 3. It uses the main camera but "seems" like a macro camera.
本文标签: javascriptnavigatormediaDevicesgetUserMedia impossible to get the camera to focusStack Overflow
版权声明:本文标题:javascript - navigator.mediaDevices.getUserMedia impossible to get the camera to focus - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744437166a2606240.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论