我正在使用网络摄像头每10秒捕获一次图像,而实际上并未显示网络摄像头。它可以工作,但是有2个主要问题正在处理,将不胜感激。
我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<title>WebCam Test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.25/webcam.min.js"></script>
</head>
<body>
<!--I need to disable the webcam from displaying on the frontend-->
<div id="webcam" style="visibility: hidden"></div>
<script type="text/javascript">
$(function() {
Webcam.set({
width: 600,
height: 460,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach( '#webcam' );
setInterval(function()
{
// On every interval, I need to detect if the Webcam is still active before trying to capture an image.
// Because if the webcam is not active or if I disabled it from the beginning, its leads to this recurrent error: "webcam.js error: webcam is not loaded"
captureWebCam();
}, 10000);
function captureWebCam() {
Webcam.snap( function(data_uri) {
Webcam.upload( data_uri, 'store_image.php', function(code, text) {
//Uploaded Successfully
} );
} );
}
});
</script>
</body>
</html>