问题使OpenCV流与Raspberry Pi Zero上的烧瓶合作2 W

发布于 2025-01-25 05:55:50 字数 1153 浏览 3 评论 0原文

我试图使用烧瓶在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

jJeQQOZ5 2025-02-01 05:55:50

一个可能的原因是内部调试器与重新加载器冲突。建议在没有重新加载的情况下实现调试:

app.run(host="192.168.7.80", port="5000", debug=True, use_reloader=False)

One probable cause is the internal debugger conflicting with the reloader. Suggest enabling debug without the reloader:

app.run(host="192.168.7.80", port="5000", debug=True, use_reloader=False)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文