我想访问相机。捕获图像并将其存储在数据库中。
models.py:
class student(models.Model):
Img = models.ImageField(upload_to='images/')
HTML页面:
<!DOCTYPE html>
<html>
<head>
<title> webcam </title>
</head>
<body>
<div class = "video-wrap">
<video id = "video" playsinline autoplay></video>
</div>
<div class = "controller">
<button id = "snap">Capture</button>
</div>
<canvas id = "canvas" width = "640" height = "480">
</canvas>
<script>
'use strict';
const video = document.getElementById('video');
const canvas = document.getElementById('canvas');
const snap = document.getElementById('snap');
const errorMsgElement = document.getElementById('span#ErrorMsg');
const constraints = {
audio:true,
video:{
width:1280,height:720
}};
async function init()
{
try
{
const stream = await navigator.mediaDevices.getUserMedia(constraints);
handleSuccess(stream);
}
catch(e)
{
errorMsgElement.innerHTML
=`navigator.getUserMedia.error:${e.toString()}`;
}
}
function handleSuccess(stream)
{
window.stream = stream;
video.srcObject = stream;
}
init();
var context = canvas.getContext('2d');
snap.addEventListener("click",function(){
context.drawImage(video, 0, 0, 640, 480);});
</script>
</body>
</html>
此HTML页面可以访问相机并可以捕获。但是我不知道如何访问模型。谁能帮忙
要在Django中捕获图像,您可以使用python图像库PILLOW(https://pypi.org/project/Pillow/)。易于使用