问题使OpenCV流与Raspberry Pi Zero上的烧瓶合作2 W
我试图使用烧瓶在Raspberry Pi Zero 2 W上运行OpenCV视频流。
代码如下:
from flask import Flask, render_template, Response
import cv2
import time
# Initialize the Flask App
app = Flask(__name__)
def gen_frames():
camera = cv2.VideoCapture(0)
while True:
success, frame = camera.read()
if not success:
break
else:
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') #concat frame one by one and display results
time.sleep(0.01)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/video_feed')
def video_feed():
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundry=frame')
if __name__ == "__main__":
app.run(host="192.168.7.80", port="5000")
我正在运行Raspian版本10(Buster),OpenCV版本3.2.0,Python版本3.7.3和Blask版本1.0.2。
发生的问题是,当我运行上述代码(使用正确的索引。如果我在Windows计算机上运行相同的代码(版本不同[Python 3.9.6,OpenCV 4.5.5和Blask 2.1.1],它会正确显示。
我在RPI上运行的版本是否存在问题这是不同的
吗
?
I am attempting to get an OpenCV video stream running on my Raspberry Pi Zero 2 W using Flask.
The code is as follows:
from flask import Flask, render_template, Response
import cv2
import time
# Initialize the Flask App
app = Flask(__name__)
def gen_frames():
camera = cv2.VideoCapture(0)
while True:
success, frame = camera.read()
if not success:
break
else:
ret, buffer = cv2.imencode('.jpg', frame)
frame = buffer.tobytes()
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n') #concat frame one by one and display results
time.sleep(0.01)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/video_feed')
def video_feed():
return Response(gen_frames(), mimetype='multipart/x-mixed-replace; boundry=frame')
if __name__ == "__main__":
app.run(host="192.168.7.80", port="5000")
I'm running Raspian Version 10 (Buster), OpenCV version 3.2.0, Python version 3.7.3, and Flask version 1.0.2.
The issue that is occuring is that when I run the above code (with the proper index.html) the page displays, but the image does not. If I run the same code on a Windows machine (versions are different [Python 3.9.6, OpenCV 4.5.5, and Flask 2.1.1] it displays properly.
Is there an issue with the versions I am running on the rPi or is it something different?
Thanks in advance.
-- Mike
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个可能的原因是内部调试器与重新加载器冲突。建议在没有重新加载的情况下实现调试:
One probable cause is the internal debugger conflicting with the reloader. Suggest enabling debug without the reloader: