【问题标题】:How to build a barcode reader in js with camera?如何用相机在js中构建条形码阅读器?
【发布时间】:2017-11-09 19:41:25
【问题描述】:

我是 js 和 jquery 的初学者,所以我需要你的帮助。感谢我手机上的摄像头,我想在 js 中构建一个条形码阅读器。 目前我这样做:

  <video id="video" width="640" height="480" autoplay></video>
    <button id="snap">Snap Photo</button>
    <canvas id="canvas" width="640" height="480"></canvas>
     <script type="text/javascript">
     // Grab elements, create settings, etc.
     var video = document.getElementById('video');

     // Get access to the camera!
     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();
  });
  // Elements for taking the snapshot
  var canvas = document.getElementById('canvas');
  var context = canvas.getContext('2d');
  var video = document.getElementById('video');

  // Trigger photo take
  document.getElementById("scan").addEventListener("click", function() {
	context.drawImage(video, 0, 0, 640, 480);
  });
}

但它不起作用所以我很迷茫x) 提前感谢您的帮助! (对不起我的英语:D)

【问题讨论】:

  • 我觉得对你有用https://atandrastoth.co.uk/main/pages/plugins/codereader/
  • 谢谢,我会看看这个!

标签: javascript jquery html web-applications camera


【解决方案1】:

您可以使用zbar C/C++ 库,并使用Emscripten 将其转换为WebAssembly(所有主流浏览器都支持)。

Emscripten 是一个基于 LLVM/Clang 的编译器,可将 C 和 C++ 源代码编译为 WebAssembly,主要用于在 Web 浏览器中执行。

这是我刚刚发布的一个示例应用:

【讨论】:

    【解决方案2】:

    为什么不使用一些库,例如。

    【讨论】:

    • 嗨 true_gler 我正在测试服务,但它显示以下错误:sw.js:14 Uncaught TypeError: workbox.expiration.Plugin is not a constructor serviceWorker.js:97 在服务工作者注册期间出错:TypeError : 无法使用脚本 ('qr.maslick.tech/sw.js') 为范围 ('qr.maslick.tech/') 注册 ServiceWorker:ServiceWorker 脚本评估失败 Promise.catch (async) (anonymous) @ serviceWorker.js:51 load (async) (anonymous) @ serviceWorker.js:34(匿名)@main.76916fec.chunk.js:1barcode.js:9 条码扫描器已初始化
    猜你喜欢
    • 2012-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-25
    • 1970-01-01
    • 2011-02-22
    • 1970-01-01
    • 2012-02-18
    相关资源
    最近更新 更多