I’m building an app to benchmark a process running on a webcam video-feed. Every refresh means I have to re-initialize the camera.(Depending on the camera can take up to 2-3 seconds of waiting). I make many changes fast, and was hoping to cut the 2-3 seconds for each refresh by caching the video capture.
Here is how I’m trying to implement caching.
import cv2
@st.cache()
def load_camera() -> cv2.VideoCapture:
CAMERA_FLAG = 0
camera = cv2.VideoCapture(CAMERA_FLAG)
return camera
camera = load_camera()
Change the decorator line to @st.cache(allow_output_mutation=True). Usually Streamlit tries to hash output values from functions (camera in this case), but hashing mutable objects is generally bad news, so setting this flag to True prevents Streamlit from doing this.
Thank you both for the response. I tried @andrewPoulton’s method and it worked. It seems less complicated so I went with that. I haven’t tried yours yet @Jonathan_Rhone
@conic so where you able to get a live feed from WebCam?
I have been looking around in the forums and mostly says, its not yet supported by Streamlit version. and recommends to try "Streamlit Components "