Spaces:
Running on Zero
Running on Zero
refactor: update app.py to optimize facial expression inference pipeline performance
Browse files
app.py
CHANGED
|
@@ -14,9 +14,13 @@ def detect_emotion(image):
|
|
| 14 |
Hàm xử lý ảnh đầu vào, gọi model RMN và trả về ảnh đã vẽ bounding box.
|
| 15 |
"""
|
| 16 |
if image is None:
|
| 17 |
-
return None
|
| 18 |
|
| 19 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 21 |
|
| 22 |
# Dự đoán cảm xúc
|
|
|
|
| 14 |
Hàm xử lý ảnh đầu vào, gọi model RMN và trả về ảnh đã vẽ bounding box.
|
| 15 |
"""
|
| 16 |
if image is None:
|
| 17 |
+
return None, "Please upload an image first."
|
| 18 |
|
| 19 |
+
# Xử lý kênh màu: ảnh từ webcam thường có 4 kênh (RGBA), cần chuyển về 3 kênh (RGB)
|
| 20 |
+
if len(image.shape) == 3 and image.shape[2] == 4:
|
| 21 |
+
image = image[:, :, :3]
|
| 22 |
+
|
| 23 |
+
# Chuyển đổi từ RGB sang OpenCV BGR để tương thích với RMN
|
| 24 |
image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 25 |
|
| 26 |
# Dự đoán cảm xúc
|