Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,32 +1,19 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
import numpy as np
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
def capture_image():
|
| 7 |
-
|
| 8 |
-
if not cap.isOpened():
|
| 9 |
-
return "无法打开摄像头"
|
| 10 |
-
|
| 11 |
-
ret, frame = cap.read()
|
| 12 |
-
cap.release()
|
| 13 |
-
if not ret:
|
| 14 |
-
return "无法读取摄像头内容"
|
| 15 |
-
|
| 16 |
-
# 将图像从BGR转换为RGB
|
| 17 |
-
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 18 |
-
|
| 19 |
-
return frame_rgb
|
| 20 |
|
| 21 |
-
# 使用 Gradio
|
| 22 |
demo = gr.Interface(
|
| 23 |
-
fn=capture_image,
|
| 24 |
-
inputs=
|
| 25 |
outputs="image",
|
| 26 |
live=True,
|
| 27 |
title="摄像头拍照",
|
| 28 |
-
description="
|
| 29 |
)
|
| 30 |
|
| 31 |
-
#
|
| 32 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
|
|
|
| 3 |
|
| 4 |
+
# 定义一个函数来处理拍照
|
| 5 |
+
def capture_image(image):
|
| 6 |
+
return image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# 使用 Gradio 创建一个摄像头界面
|
| 9 |
demo = gr.Interface(
|
| 10 |
+
fn=capture_image,
|
| 11 |
+
inputs=gr.Image(source="webcam", tool="editor"),
|
| 12 |
outputs="image",
|
| 13 |
live=True,
|
| 14 |
title="摄像头拍照",
|
| 15 |
+
description="使用摄像头进行拍照"
|
| 16 |
)
|
| 17 |
|
| 18 |
+
# 启动 Gradio 应用
|
| 19 |
demo.launch()
|