Created
June 26, 2022 11:15
-
-
Save shubham0204/b3023517a9ff08248d1f06296eb2d92a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import streamlit as st | |
import cv2 | |
import numpy as np | |
import requests | |
st.title( 'Mobile Camera Preview in Streamlit' ) | |
frame_window = st.image( [] ) | |
take_picture_button = st.button( 'Take Picture' ) | |
while True: | |
# Request the image from the server | |
response = requests.get(url="http://<network_ip_address>:<port>/photo.jpg") | |
imgNp = np.array(bytearray(response.content), dtype=np.uint8) | |
frame = cv2.imdecode(imgNp, cv2.IMREAD_UNCHANGED ) | |
# As OpenCV decodes images in BGR format, we'd convert it to the RGB format | |
frame = cv2.cvtColor( frame , cv2.COLOR_BGR2RGB ) | |
frame_window.image(frame) | |
if take_picture_button: | |
# Pass the frame to a model | |
# And show the output here... | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment