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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog