![](/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.