ich verzweifle gerade an einem simplen Problem und sehe die Lösung nicht. vielleicht kann mir hier jemand weiterhelfen:
Ich habe eine ganz simple Flask app. Vor dem app.run starte ich einen Thread, welcher mir Videodaten generiert.
Code: Alles auswählen
if __name__ == "__main__":
api_vars = {"qrcode":"", "frame": ""}
t = Thread(target=gen_frames)
t.setDaemon(True)
t.start()
while True:
print(api_vars)
app.run(debug=True, host='0.0.0.0', port=5000)
Jetzt wollte ich den Code in einem Weblink abholen. Dazu habe ich zunächst eine weitere Funktion geschrieben:
Code: Alles auswählen
def gen_frames():
global api_vars
pipeline = """libcamerasrc ! video/x-raw, width=640, height=480, framerate=30/1 ! videoconvert ! videoscale ! clockoverlay time-format="%D %H:%M:%S" ! appsink"""
camera = cv2.VideoCapture(pipeline, cv2.CAP_GSTREAMER)
while True:
api_vars["qrcode"] = "Hallo"
api_vars["frame"] = [1,2,3,4]
@app.route('/video_feed')
def video_feed():
global api_vars
while True:
print(api_vars)
time.sleep(1)
also kurz:
Code: Alles auswählen
camera => api_vars = {"qrcode":"", "Hallo" ""}
#camera => api_vars = {"qrcode":"", "frame": [1,2,3,4]}
Es hilft auch nichts global nach camera zu setzen. Weiß jemand, ob OpenCV irgendwas mit den globalen Variablen anstellt? Wie würdet ihr das Problem angehen?