ake178178 commited on
Commit
cf570b4
·
verified ·
1 Parent(s): 1744f5a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+
5
+ # 定义一个打开摄像头并拍照的函数
6
+ def capture_image():
7
+ cap = cv2.VideoCapture(0)
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=None,
25
+ outputs="image",
26
+ live=True,
27
+ title="摄像头拍照",
28
+ description="点击按钮打开摄像头并拍照"
29
+ )
30
+
31
+ # 启动应用
32
+ demo.launch()