我正在尝试创建一个用 django 编写的人脸检测 Web 应用程序。该应用程序是这样工作的。
- 用户导航到该 url
- 相机在客户端计算机上启动
- 然后将每一帧发送到服务器进行人脸检测
- 然后将处理后的帧显示在网页上
我知道我无法使用 opencv VideoCapture,因为它只能在服务器端工作。当我在网上阅读时,人们要求我使用 javascript,特别是 webRTC 在客户端启动直播。所以我找到了这个tutorial https://www.kirupa.com/html5/accessing_your_webcam_in_html5.htm它解释了如何使用 javascript 在客户端计算机上启动网络摄像头。
现在我的问题是如何将客户端计算机上的 javascript 中的每个帧发送到服务器端的 opencv python ?
所有这一切都应该实时发生。所以我无法保存实时视频,然后在保存的视频上运行 python 代码。
有些网站要求我使用 AJAX 将数据发送到服务器端,但我不确定如何定位要在 javascript 代码中发送的每个帧。
这是我到目前为止的代码
通过 webRTC 进行客户端摄像头访问
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="stuff, to, help, search, engines, not" name="keywords">
<meta content="What this page is about." name="description">
<meta content="Display Webcam Stream" name="title">
<title>Display Webcam Stream</title>
<style>
#container {
margin: 0px auto;
width: 500px;
height: 375px;
border: 10px #333 solid;
}
#videoElement {
width: 500px;
height: 375px;
background-color: #666;
}
</style>
</head>
<body>
<div id="container">
<video autoplay="true" id="videoElement">
</video>
</div>
<script>
var video = document.querySelector("#videoElement");
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({
video: true
})
.then(function(stream) {
video.srcObject = stream;
// myJson = JSON.stringify(stream)
})
.catch(function(err0r) {
console.log("Something went wrong!");
});
}
console.log(video)
</script>
</body>
</html>
在这段代码中,我如何从网络摄像头访问每个帧。我试图打印的内容video
with console.log
但这没有帮助。
DJANGO 视图.py
def index(request):
return render(request, 'cwrtc/index.html', {})
我使用 django 通道是因为我想,要从客户端发送和接收数据,我可能必须使用网络套接字。我使用 python 是因为我计划向应用程序添加更多功能,使用 python 编码比任何其他语言都更容易。
是否可以将视频流从 javascript 发送到 python?
提前致谢