I am using 2 differnt radio options for performing different tasks. I want to capture image form one and then do some operation later in the option 2. When I try to change the radio option to 2 after storing a frame in my_image (in the option 1), there comes an error in thre streamlit NameError: name 'my_image' is not defined. I was thinking that it can be done by storing the variable my_image in cache but I don't know how to do this. Is there any other way to do this.
import streamlit as st
import cv2
def Camera():
frames1 = st.empty()
button1 = st.button('DONE', key=0)
while cap.isOpened():
frames1.image(cap.read()[1], channels="BGR")
if button1:
my_image = cap.read()[1]
cap.release()
break
return my_image
option = st.sidebar.radio('Choose the option', [1, 2])
if option == 1:
cap = cv2.VideoCapture(0)
my_image = Camera()
st.image(my_image, channels="BGR")
if option == 2:
st.image(my_image, channels='BGR')