return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - navigator.mediaDevices.getUserMedia impossible to get the camera to focus - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - navigator.mediaDevices.getUserMedia impossible to get the camera to focus - Stack Overflow

programmeradmin4浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

There 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.

发布评论

评论列表(0)

  1. 暂无评论