ake178178 commited on
Commit
36e8a41
·
verified ·
1 Parent(s): ebed514

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -1,14 +1,18 @@
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="摄像头拍照",
 
1
  import gradio as gr
2
  from PIL import Image
3
+ import numpy as np
4
 
5
+ # 定义一个从视频帧中获取图像的函数
6
+ def capture_image(video):
7
+ # 获取视频的第一帧
8
+ frame = video[0]
9
+ image = Image.fromarray(frame)
10
  return image
11
 
12
+ # 使用 Gradio 创建界面,使用摄像头捕捉视频
13
  demo = gr.Interface(
14
  fn=capture_image,
15
+ inputs=gr.Video(source="webcam"),
16
  outputs="image",
17
  live=True,
18
  title="摄像头拍照",