如何捕获客户端的图片并使用烧瓶将其保存在服务器上?

时间:2017-03-08 06:05:22

标签: python opencv flask

from flask import Flask, Response
import cv2
class Camera(object):
  def __init__(self):
    self.cap = cv2.VideoCapture(0)

  def get_frame(self):
    ret, frame = self.cap.read()
    return open('stream.jpg', 'rb').read()


app = Flask(__name__)

def gen(camera):
  while True:
    frame = camera.get_frame()
    yield (b'--frame\r\n'
      b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')

@app.route('/')
def video_feed():
  return Response(gen(Camera()),
  mimetype='multipart/x-mixed-replace;boundary=frame') 

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

我想每秒捕获每一帧并将其保存到最多20张图像文件中我该怎么办?任何人都可以为此建议正确的代码吗?

0 个答案:

没有答案