| import cv2 | |
| import streamlit as st | |
| def take_picture(): | |
| """ | |
| 使用 OpenCV 拍摄一张照片并返回图像数据。 | |
| """ | |
| cap = cv2.VideoCapture(0) # 打开默认摄像头 | |
| ret, frame = cap.read() | |
| cap.release() | |
| return frame | |
| def show_picture(img): | |
| """ | |
| 在 Streamlit 中显示图像。 | |
| """ | |
| st.image(img, channels="BGR") | |
| if __name__ == "__main__": | |
| if st.button("拍照"): | |
| img = take_picture() | |
| show_picture(img) |