Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,7 @@ import mediapipe as mp
|
|
6 |
# 初始化 MediaPipe Hands
|
7 |
mp_hands = mp.solutions.hands
|
8 |
mp_drawing = mp.solutions.drawing_utils
|
9 |
-
hands = mp_hands.Hands(min_detection_confidence=0.
|
10 |
|
11 |
# WebRTC 配置
|
12 |
rtc_configuration = {
|
@@ -22,6 +22,9 @@ def detection(image, conf_threshold=0.5):
|
|
22 |
# 将图像从 BGR 转换为 RGB(MediaPipe 需要 RGB 格式)
|
23 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
24 |
|
|
|
|
|
|
|
25 |
# 使用 MediaPipe Hands 处理图像
|
26 |
results = hands.process(image_rgb)
|
27 |
|
@@ -70,4 +73,4 @@ with gr.Blocks(css=css) as demo:
|
|
70 |
)
|
71 |
|
72 |
if __name__ == "__main__":
|
73 |
-
demo.launch()
|
|
|
6 |
# 初始化 MediaPipe Hands
|
7 |
mp_hands = mp.solutions.hands
|
8 |
mp_drawing = mp.solutions.drawing_utils
|
9 |
+
hands = mp_hands.Hands(min_detection_confidence=0.3, min_tracking_confidence=0.3) # 降低置信度提升速度
|
10 |
|
11 |
# WebRTC 配置
|
12 |
rtc_configuration = {
|
|
|
22 |
# 将图像从 BGR 转换为 RGB(MediaPipe 需要 RGB 格式)
|
23 |
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
24 |
|
25 |
+
# 将图像大小缩小到一个较小的尺寸,降低计算负担
|
26 |
+
image = cv2.resize(image, (640, 480))
|
27 |
+
|
28 |
# 使用 MediaPipe Hands 处理图像
|
29 |
results = hands.process(image_rgb)
|
30 |
|
|
|
73 |
)
|
74 |
|
75 |
if __name__ == "__main__":
|
76 |
+
demo.launch()
|