对不起,我的英语能力。我想在我的Raspberry中使用Python3中的Flask将视频从Logitech C250网络摄像头流式传输到网络服务器页面。现在,当我从笔记本电脑访问时,我可以从网页上看到视频。但是我的页面会永远加载。当我的Android手机尝试访问该页面时,它什么也没有显示。请帮帮我。这是代码: main.py:
from flask import Flask, render_template, Response
from camera import VideoCamera
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\r\n')
@app.route('/')
def index():
return Response(gen(VideoCamera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)
camera.py:
import cv2
class VideoCamera(object):
def __init__(self):
self.video = cv2.VideoCapture(0)
def __del__(self):
self.video.release()
def get_frame(self):
success, image = self.video.read()
ret, jpeg = cv2.imencode('.jpg', image)
return jpeg.tobytes()