doudan1123 2019-02-27 04:36
浏览 472

使用网络摄像头扫描二维码,从网络摄像头获取图像

I have this code that scans and decode qr image with the help of this source code https://github.com/khanamiryan/php-qrcode-detector-decoder, it scans the image file from your documents..but I want to scan the qr using my webcam.

the qr code scanner script is this

  <?php
if ($_SERVER['REQUEST_METHOD'] != "POST"){
    header("location:take-attendance.php");
    die();
}

require "vendor/autoload.php";

$qrcode = new Zxing\QrReader($_FILES['qrimage']['tmp_name']);
$text = $qrcode->text();

var_dump($text);

?>

then my webcam that take snapshot goes like this

 <form action="decode.php" method="post" enctype="multipart/form-data">
<script src="webcam.js"></script> <!--source code script from github for webcam config-->

    <div id="my_camera" style="width:320px; height:240px;"></div>
    <div id="my_result"></div>

    <script type=text/javascript>
        Webcam.attach( '#my_camera' );

        function take_snapshot() {
            Webcam.snap( function(data_uri) {
                document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/>';
            } );
        }
    </script>

    <a href="javascript:void(take_snapshot())">Take Snapshot</a>

so I click the take snapshot the image will appear as an img src and I want that image to be fetch if I click scan so that means I need to replace this code

$qrcode = new Zxing\QrReader($_FILES['qrimage']['tmp_name']);

with the file name that is been generated when I click that snapshot which is this

<img src="'+data_uri+'"/>

but the thing is I don't know the format on how to write the code, this is my idea but it doesn't work though

$qrcode = new Zxing\QrReader($_FILES['data_uri']);

thanks in advance

  • 写回答

1条回答 默认 最新

  • douhaodang0403 2019-02-27 04:46
    关注

    You don't send anything in your form.

    Snapshot generated in base64 format, so you can only send it as string to server and decode to image.

    But much simpler is use JS QR Decoder like this https://github.com/colcodev/qrcode-decoder-js

    qrcode.decode(data_uri)
    

    And then if you need send result to server via simple input

    Webcam.attach( '#my_camera' );
    
    function take_snapshot() {
        Webcam.snap(function(data_uri) {
            document.getElementById('my_result').innerHTML = '<img src="'+data_uri+'"/> - '+qrcode.decode(data_uri);
        });
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算