USB相机的python快照

时间:2019-02-16 11:39:55

标签: python camera

我用python编写了此脚本,该脚本创建了一个网络服务器并显示了来自USB摄像机的流:

select student, count(*) as numyears
from t
group by student
order by numyears desc
limit 1;

现在是Camera类:

#!/usr/bin/env python
from importlib import import_module
import os
import cv2
from flask import Flask, render_template, Response
from camera import Camera
from apscheduler.schedulers.background import BackgroundScheduler

img_counter = 0

app = Flask(__name__)


 @app.route('/')
 def index(): 
    """Video streaming home page."""
    return render_template('index.html')


def gen(camera, flag):
    if flag > 0:        
        print("{} written!"+flag)
    global img_counter
    """Video streaming generator function."""
    while (flag>0):
       frame = camera.get_frame()
       yield (b'--frame\r\n'
           b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

@app.route('/video_feed/<flag>')
  def video_feed(flag):
  """Video streaming route. Put this in the src attribute of an img tag."""
  return Response(gen(Camera(), flag),
                mimetype='multipart/x-mixed-replace; boundary=frame')

if __name__ == '__main__':
    app.run(host='0.0.0.0', threaded=True)

我还有一个html页面,其中包含一个流媒体和一个用于拍摄快照的按钮。我希望,当我单击按钮时,可以保存快照。有可能的?在网页上保留流媒体内容?

谢谢

0 个答案:

没有答案