Dears,
I have an application whose output appears outside of Streamlit (images with the camera on). The last line of the code is
cv2.imshow (‘Display’, img)
I would like to put images from this camera within Streamlit.
Thanks,
Luís Carlos
Dears,
I have an application whose output appears outside of Streamlit (images with the camera on). The last line of the code is
cv2.imshow (‘Display’, img)
I would like to put images from this camera within Streamlit.
Thanks,
Luís Carlos
Hi @LuisCarlosEiras -
You should be able to use st.image
to display your images. Do you have a code example you can share?
Best,
Randy
Randy,
Thank you for your attention.
But, the st.image did not work in this case.
The image to be shown is at the same time an image of the camera and a processing of it.
The complete code is in
https://github.com/LuisCarlosEiras/comoficarinvisivel
and waiting for a solution in
https://share.streamlit.io/luiscarloseiras/comoficarinvisivel/main/invisivelst.py
(“Como ficar invisível” is “How to stay invisible”…)
Thanks,
Luís Carlos
2 things.
cv2.VideoCapture(0)
uses the web camera on the server, not the client (browser). So this will never work on StreamLit Sharing.
Do not use infinite loops in StreamLit. Please read on how Streamlit works. Basically, each time you interact with something in the UI, the whole code re-runs.
If you really want to do this only using StreamLit for some reason, you can try something like this on your laptop:
import streamlit as st
import cv2 as cv2
st.title('Streamlit OpenCV Camera Test')
MAX_FRAMES = st.slider("Select number of frames to render:", min_value=60, max_value=600, value=300, step=30)
run = st.button("Click to render server camera")
if run:
capture = cv2.VideoCapture(0)
img_display = st.empty()
for i in range(MAX_FRAMES):
ret, img = capture.read()
img_display.image(img, channels='BGR')
capture.release()
st.markdown("Render complete")
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.