【问题标题】:unable to load webcam/video in html无法在 html 中加载网络摄像头/视频
【发布时间】:2020-11-01 00:02:41
【问题描述】:

我正在使用一个基本的 html/javascript 脚本来加载网络摄像头组件。

<html>
  <head>
    <!-- Load the latest version of TensorFlow.js -->
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
    <script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/mobilenet"></script>
  </head>
  <body>
    <div id="console"></div>
    <!-- Add an image that we will use to test -->
    <video autoplay playsinline muted id="webcam" width="224" height="224"></video>
    <!-- Load index.js after the content of the page -->
    <script src="index.js"></script>
  </body>
</html>

const webcamElement = document.getElementById('webcam');

async function app() {
    console.log('Loading mobilenet..');
  
    // Load the model.
    net = await mobilenet.load();
    console.log('Successfully loaded model');
    const webcam = await tf.data.webcam(webcamElement);
    while (true) {
      const img = await webcam.capture();
      const result = await net.classify(img);
  
      document.getElementById('console').innerText = `
        prediction: ${result[0].className}\n
        probability: ${result[0].probability}
      `;
      img.dispose();
      await tf.nextFrame();
    }
  }

这似乎是根据其他答案加载网络摄像头的正确方法。然而,没有什么对我开放。也没有控制台日志。我正在 Firefox 上尝试这个。

【问题讨论】:

    标签: javascript html firefox webcam


    【解决方案1】:

    首先,只需在 html 文件部分包含脚本 webcam-easy.min.js

    尝试代替那个js,你会得到网络摄像头输出

    【讨论】:

      猜你喜欢
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多