单摄像头推网页
需求:
电脑摄像头
index.html
app.py
Pycharm平台
index.html
<html>
<head>
<title>Video Streaming Demonstration</title>
</head>
<body>
<h1>Video Streaming Demonstration</h1>
<img src="{
{ url_for('video_feed') }}" height="500">
</body>
</html>
app.py
import cv2
from flask import Flask, render_template, Response
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
def gen():
vid = cv2.VideoCapture(0)
while True:
return_value, frame = vid.read()
image = cv2.imencode('.jpg', frame)[1].tobytes()
yield (b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + image + b'\r\n')
@app.route('/video_feed')
def video_feed():
return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run()
显示界面