Spaces:
Runtime error
Runtime error
File size: 698 Bytes
cf570b4 9d95991 cf570b4 9d95991 cf570b4 9d95991 cf570b4 9d95991 cf570b4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import gradio as gr
from PIL import Image
import cv2
def capture_image():
# 打开摄像头
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
if ret:
# 将BGR图像转换为RGB图像
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# 转换为Pillow图像
img = Image.fromarray(frame)
cap.release()
return img
else:
cap.release()
return "无法打开摄像头"
# 创建gradio接口
with gr.Blocks() as demo:
webcam_image = gr.Image(label="摄像头拍摄的图片")
capture_button = gr.Button("拍照")
capture_button.click(capture_image, outputs=webcam_image)
# 启动gradio界面
demo.launch()
|