Spaces:
Sleeping
Sleeping
Commit ·
6802e41
1
Parent(s): 25cf9f5
color parsing fix
Browse files- app.py +25 -7
- src/utils.py +0 -4
app.py
CHANGED
|
@@ -11,23 +11,31 @@ from src.utils import (
|
|
| 11 |
|
| 12 |
|
| 13 |
def hex_to_bgr(color_input):
|
| 14 |
-
"""Convert color to BGR tuple. Handles hex strings, rgb() strings, and tuples."""
|
| 15 |
try:
|
| 16 |
# If it's already a tuple, assume it's RGB and convert to BGR
|
| 17 |
-
if isinstance(color_input, (tuple, list)) and len(color_input)
|
| 18 |
-
r, g, b = color_input
|
| 19 |
-
return (b, g, r)
|
| 20 |
|
| 21 |
# If it's a string, try different formats
|
| 22 |
if isinstance(color_input, str):
|
| 23 |
color_input = color_input.strip()
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# Handle rgb(r, g, b) format
|
| 26 |
if color_input.startswith('rgb'):
|
| 27 |
color_input = color_input.replace('rgb(', '').replace(')', '').strip()
|
| 28 |
-
parts = [
|
| 29 |
-
if len(parts)
|
| 30 |
-
r, g, b = parts
|
| 31 |
return (b, g, r)
|
| 32 |
|
| 33 |
# Handle hex format #RRGGBB
|
|
@@ -81,8 +89,12 @@ def process_video(
|
|
| 81 |
output_video_path = output_dir / "output.mp4"
|
| 82 |
|
| 83 |
# Convert colors to BGR tuples
|
|
|
|
|
|
|
| 84 |
landmark_color_tuple = hex_to_bgr(landmark_color)
|
| 85 |
connection_color_tuple = hex_to_bgr(connection_color)
|
|
|
|
|
|
|
| 86 |
|
| 87 |
# Create drawing settings dictionary from interface input
|
| 88 |
drawing_settings = {
|
|
@@ -187,6 +199,12 @@ with gr.Blocks(title="Body Pose Estimation") as demo:
|
|
| 187 |
# Handle processing
|
| 188 |
def process_and_update(video, radius, land_color, conn_color, conn_thickness):
|
| 189 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 190 |
# Update status
|
| 191 |
gr.Info("Processing video... This may take a few minutes.")
|
| 192 |
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
def hex_to_bgr(color_input):
|
| 14 |
+
"""Convert color to BGR tuple. Handles hex strings, rgb() strings, rgba() strings, and tuples."""
|
| 15 |
try:
|
| 16 |
# If it's already a tuple, assume it's RGB and convert to BGR
|
| 17 |
+
if isinstance(color_input, (tuple, list)) and len(color_input) >= 3:
|
| 18 |
+
r, g, b = color_input[:3]
|
| 19 |
+
return (int(b), int(g), int(r))
|
| 20 |
|
| 21 |
# If it's a string, try different formats
|
| 22 |
if isinstance(color_input, str):
|
| 23 |
color_input = color_input.strip()
|
| 24 |
|
| 25 |
+
# Handle rgba(r, g, b, a) format
|
| 26 |
+
if color_input.startswith('rgba'):
|
| 27 |
+
color_input = color_input.replace('rgba(', '').replace(')', '').strip()
|
| 28 |
+
parts = [x.strip() for x in color_input.split(',')]
|
| 29 |
+
if len(parts) >= 3:
|
| 30 |
+
r, g, b = int(float(parts[0])), int(float(parts[1])), int(float(parts[2]))
|
| 31 |
+
return (b, g, r)
|
| 32 |
+
|
| 33 |
# Handle rgb(r, g, b) format
|
| 34 |
if color_input.startswith('rgb'):
|
| 35 |
color_input = color_input.replace('rgb(', '').replace(')', '').strip()
|
| 36 |
+
parts = [x.strip() for x in color_input.split(',')]
|
| 37 |
+
if len(parts) >= 3:
|
| 38 |
+
r, g, b = int(float(parts[0])), int(float(parts[1])), int(float(parts[2]))
|
| 39 |
return (b, g, r)
|
| 40 |
|
| 41 |
# Handle hex format #RRGGBB
|
|
|
|
| 89 |
output_video_path = output_dir / "output.mp4"
|
| 90 |
|
| 91 |
# Convert colors to BGR tuples
|
| 92 |
+
print(f"Raw landmark_color input: {landmark_color} (type: {type(landmark_color)})")
|
| 93 |
+
print(f"Raw connection_color input: {connection_color} (type: {type(connection_color)})")
|
| 94 |
landmark_color_tuple = hex_to_bgr(landmark_color)
|
| 95 |
connection_color_tuple = hex_to_bgr(connection_color)
|
| 96 |
+
print(f"Converted landmark_color: {landmark_color_tuple}")
|
| 97 |
+
print(f"Converted connection_color: {connection_color_tuple}")
|
| 98 |
|
| 99 |
# Create drawing settings dictionary from interface input
|
| 100 |
drawing_settings = {
|
|
|
|
| 199 |
# Handle processing
|
| 200 |
def process_and_update(video, radius, land_color, conn_color, conn_thickness):
|
| 201 |
try:
|
| 202 |
+
# Debug: Print what we receive from the UI
|
| 203 |
+
print(f"=== DEBUG: Values received from UI ===")
|
| 204 |
+
print(f"land_color: {land_color}")
|
| 205 |
+
print(f"conn_color: {conn_color}")
|
| 206 |
+
print(f"==========================================")
|
| 207 |
+
|
| 208 |
# Update status
|
| 209 |
gr.Info("Processing video... This may take a few minutes.")
|
| 210 |
|
src/utils.py
CHANGED
|
@@ -143,10 +143,6 @@ def process_body_pose_estimation(path_video, output_folder, drawing_settings):
|
|
| 143 |
path_video (str): Path to input video file.
|
| 144 |
output_folder (str): Folder to save annotated frames.
|
| 145 |
"""
|
| 146 |
-
config_path = os.path.join(
|
| 147 |
-
os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
|
| 148 |
-
"pose_estimation/config.yaml",
|
| 149 |
-
)
|
| 150 |
|
| 151 |
# Initialize device and models
|
| 152 |
device = infer_device()
|
|
|
|
| 143 |
path_video (str): Path to input video file.
|
| 144 |
output_folder (str): Folder to save annotated frames.
|
| 145 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
# Initialize device and models
|
| 148 |
device = infer_device()
|