![](/img/trans.png)
[英]Unable to take photo from webcam using HTML5 and getUserMedia() in Google Chrome on first page load
[英]unable to load webcam/video in html
我正在使用一个基本的 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 上尝试这个。
首先,只需在 html 文件的部分中包含脚本webcam-easy.min.js 。
并尝试代替那个 js,您将获得网络摄像头输出
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.