File size: 471 Bytes
254560c
bb7ec90
254560c
 
bb7ec90
 
 
 
 
254560c
bb7ec90
 
 
 
 
 
 
254560c
 
bb7ec90
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)