Thanks for putting in the work to create something like this!
I do have two things to say about it:
The camera works extremely slow. Sometimes it doesn’t work at all (it freezes). And I try it with the fastest wifi, newest MacBook Pro/iPhone. So I think there is something wrong with the way the component is build
It is very important that the component uses the smartphones back camera in stead of the front camera. In that way it can be used as a code scanner.
This component is set to update every 1s by default, but if you build your own app you can make it update faster by doing camera_input_live(debounce=100) (which will make it update every 100ms instead of every 1000ms. Can you figure out a way to reproduce the camera freezing entirely (other than pressing the pause button)? I haven’t seen that happen yet, but it’s definitely possible. To be clear, I’m not intending this to be the optimal QR Code reader app, I mostly wanted to make a replacement to st.camera_input that allows you to get the images back right away, rather than having to press “save”, so that you, and others, can use it to build interesting apps.
Adding the ability to switch to back camera is a great idea. I’ll see if I can figure out a way to add that option.
Even though I try to do this “camera_input_live(debounce=100)”, it still seems lagging.
And about the back camera: Would be really great if we could use the back camera as the standard camera, so without having to manually switch to back camera!
Great camera live input, I’m developing an automatic catalog for a library and it looks like a good starting!
Two questions: Is there a way to freeze the image automatically when the QR is already recognized? I see there’s some code in ini.py (startLabel=start_label and stopLabel=stop_label) but I dont know how to make them work, maybe something like this?
if data:
st.write(data)
camera_input_live(stopLabel)
or even increasing the debounce
if data:
st.write(data)
camera_input_live(debounce=50000)
Well I have tried a lot of things but nothing seems to work for me.
About the rest:
update every 100ms
–just fine, its a QR code reader, not Netflix
smartphones back camera
–Great idea! looking forward to it!
Right now if you pass show_controls=True it will show a stop button, but it won’t be called automatically.
Here’s one way to do it using st.session_state to keep track of whether a QR code has been found, and to save the image once one is found. You could also add a “reset” button that clears those items from session state.
import cv2
import numpy as np
import streamlit as st
from camera_input_live import camera_input_live
"# Streamlit camera input live Demo"
"## Try holding a qr code in front of your webcam"
if "found_qr" not in st.session_state:
st.session_state.found_qr = False
if "qr_code_image" not in st.session_state:
st.session_state.qr_code_image = None
if not st.session_state["found_qr"]:
image = camera_input_live()
else:
image = st.session_state.qr_code_image
if image is not None:
st.image(image)
bytes_data = image.getvalue()
cv2_img = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
detector = cv2.QRCodeDetector()
data, bbox, straight_qrcode = detector.detectAndDecode(cv2_img)
if data:
st.session_state["found_qr"] = True
st.session_state["qr_code_image"] = image
st.write("# Found QR code")
st.write(data)
with st.expander("Show details"):
st.write("BBox:", bbox)
st.write("Straight QR code:", straight_qrcode)
Works great! When I’ve got the QR it stops and let me fill a st form (library stuff).
One more question: Is there a way to hide the “start/stop” button?
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.