任何人都知道如何提高fps,因为我从正常的opencv中获得了30 fps。如果我可以使其达到10或5 fps,那就太好了。因此,当我移动位置时,不会延迟显示摄像机图像的时间。因此视频将接近实时图像检测。
from flask import Flask, render_template, Response
import cv2
app = Flask(__name__)
camera = cv2.VideoCapture(0)
fps = camera.get(cv2.CAP_PROP_FPS)
@app.route('/')
def index():
"""Load template to index"""
return render_template('index.html')
def load():
"""Load Image from Camera"""
while True:
success, frame = camera.read()
# resize to 800x600, 640x480
frame_width_fx = 640
frame_height_fy = 480
frame = cv2.resize(frame, (frame_width_fx, frame_height_fy))
print(fps)
cv2.imwrite('read.jpg', frame)
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + open('read.jpg', 'rb').read() + b'\r\n')
@app.route('/video_feed')
def video_feed():
return Response(load(), mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.debug = True
app.threaded = True
app.run(use_reloader=False)