Download camera.py from ake178178/StreamlitCameraObjectDectect: direct link, hf CLI and curl.
- Browser
- Download file 471 Bytes
-
https://huggingface.co/spaces/ake178178/StreamlitCameraObjectDectect/resolve/079dc087c44fbdf51647dafc215a2a8df1f2acad/camera.py
- Command line
-
hf download hf://spaces/ake178178/StreamlitCameraObjectDectect@079dc087c44fbdf51647dafc215a2a8df1f2acad/camera.py
-
curl -L -o camera.py https://huggingface.co/spaces/ake178178/StreamlitCameraObjectDectect/resolve/079dc087c44fbdf51647dafc215a2a8df1f2acad/camera.py
471 Bytes
| 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) |