'Continuously send data during Python For Loop when condition met in Flask
I can't seem to send a request containing text during video feed capture loop using OpenCv to the web app in order to show this text in a container.
While the video feed is displayed on the web app, during this loop, once a certain condition is met, I want to send a request containing text where this text will be displayed in the web app under the video feed and will frequently when condition is met as seen below.
def show_feed():
cap = cv2.VideoCapture(0)
frame_list = []
rand_val = random.randrange(1, 20) # Random value
while True:
_, frame = cap.read()
frame_list.append(frame)
if len(frame_list) == rand_val:
send_text = f"Frame {str(rand_val)}/{str(len(frame_list))" # "Frame 2/20"
### HERE ###
### send request to web app containg this text to web app displaying in text box
### HERE ###
time.sleep(5)
frame_list = []
yield(b'--frame\r\n'
b'Content-Type: image/jpeg\r\n\r\n' + frame.tobytes() + b'\r\n')
@app.route('/video_feed')
def index():
return render_template('index.html')
@app.route('/video_feed')
def video_feed():
return Response(show_feed(),
mimetype='multipart/x-mixed-replace; boundary=frame')
Where the html is as follows:
<!-- html stuff-->
<body>
<div class="video">
<img src="{{ url_for('video_feed') }}"/>
<div class="container">
<input type="text" id="textbox"/> <!-- display text here met output frame from python For Loop ->>
</body>
<!-- html stuff-->
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
