javascript - 如何将视频(使用 opencv-python)从 python 函数返回到 html?
问题描述
我正在尝试通过 eel 库将视频从 Python 返回到 Html 应用程序。这是我的脚本。
cam_read/web/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Web cam reader</title>
<style>
h1{
color: green;
text-align: center;
}
.webcam{
margin: 50px;
font-size: 150px;
text-align: center;
}
button{
display: block;
margin: 0 auto;
}
</style>
</head>
<body>
<h1>Web cam reader</h1>
<div class="webcam"></div>
<button>Read webcam</button>
<script type="text/javascript" src="../eel.js"></script>
<script src="./script.js"></script>
</body>
</html>
cam_read/web/script.js
// Onclick of the button
document.querySelector("button").onclick = function () {
// Call python's random_python function
eel.webcam()(function(cam){
// Update the div with a random number returned by python
document.querySelector(".webcam").innerHTML = cam;
})
}
cam_read/main.py
import cv2
eel.init("web")
# Exposing the webcam function to javascript
@eel.expose
def webcam():
vid=cv2.VideoCapture(0)
while True:
ret, cam = vid.read()
'''Code to return cam'''
# Start the index.html file
eel.start("/index.html",size=(300,450))
以及如何将网络摄像头返回给 script.js 请帮助我实现这个目标。
解决方案
推荐阅读
- .htaccess - Htaccess 减少虚假长路径
- testing - 我们可以从参数集中填充 QueryString 参数和值吗?
- php - 如何使用 PHP 获取内部数组值?
- sql - 如何组合多个选择以从多个表中获取数据
- migration - 当我在包管理器控制台中的 VS 2017 中运行更新数据库时出错
- html - 如何更改我的标题和边框块在小屏幕和大屏幕上的响应
- jquery - 如果 Object 不存在,则推送到 JSON 数组
- java - git clone 在 docker 文件中不起作用
- python - 创建另一个数据集的列之间差异的新数据集
- c# - 在 aspnet core 2.1 中生成 Swashbuckle 实现笔记