|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我用flask写了个实时获取摄像头的,他会推一个图片流到html的img然后我想要点击按钮flask就把这个img里的图片下载下来
百度找不到方法,在这里请教一下各位大佬
flask:- import cv2
- from cv2 import imdecode
- from flask import Flask, render_template, Response
- import time
- # from pyzbar import pyzbar
- # import numpy as np
- from pyzbar.pyzbar import decode
- from PIL import Image
- app = Flask(__name__)
- @app.route('/')
- def index():
- return render_template(r'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')
- print(image)
-
- # cv2.imwrite("./1.png", image)
- time.sleep(10)
- @app.route('/sm')
- def video_feed():
- return Response(gen(), mimetype='multipart/x-mixed-replace; boundary=frame')
- if __name__ == '__main__':
- app.run(host='0.0.0.0', port=80, debug = True)
复制代码
html:
- <html>
- <head>
- <title>Video Streaming Demonstration</title>
- <style>
- #btn_snap {
- margin: 0 auto;
- border: 1px solid #f0f0f0;
- background: #5CACEE;
- color: #FFF;
- width: 100px;
- height: 36px;
- line-height: 36px;
- border-radius: 8px;
- text-align: center;
- cursor: pointer;
- cursor: pointer;
- /*禁止选择*/
- -webkit-touch-callout: none;
- /* iOS Safari */
- -webkit-user-select: none;
- /* Chrome/Safari/Opera */
- -khtml-user-select: none;
- /* Konqueror */
- -moz-user-select: none;
- /* Firefox */
- -ms-user-select: none;
- /* Internet Explorer/Edge */
- user-select: none;
- /* Non-prefixed version, currently not supported by any browser */
- }
- </style>
- </head>
- <body>
- <h1>Video Streaming Demonstration</h1>
- <img src="{{ url_for('video_feed') }}" height="500">
- <!-- 12313 -->
- <div id="btn_snap" onclick="myfunction()">拍照</div>
-
- </body>
- </html>
复制代码 |
|