33from typing import Dict , Tuple
44from .tracking_data import TrackingData
55import mediapipe as mp
6+ from .colors import Palette
67
78class SVGGenerator :
89 """Generates SVG trajectories from body tracking data."""
@@ -13,14 +14,7 @@ def __init__(self, width: int = 1280, height: int = 720, show_legend: bool = Tru
1314 self .show_legend = show_legend
1415
1516 # Color scheme for different body regions
16- self .body_colors = {
17- 'face' : '#f87171' ,
18- 'left_arm' : '#fb923c' ,
19- 'right_arm' : '#facc15' ,
20- 'hips' : '#71717a' ,
21- 'left_leg' : '#06b6d4' ,
22- 'right_leg' : '#3b82f6'
23- }
17+ self .palette = Palette ()
2418
2519 # Hierarchical body structure mapping
2620 self .body_hierarchy = {
@@ -66,23 +60,6 @@ def __init__(self, width: int = 1280, height: int = 720, show_legend: bool = Tru
6660 32 : ["body" , "right leg" ]
6761 }
6862
69- def get_landmark_color (self , landmark_id : int ) -> str :
70- """Get color for a specific landmark based on body region."""
71- if landmark_id <= 10 :
72- return self .body_colors ['face' ]
73- elif landmark_id in [11 , 13 , 15 , 17 , 19 , 21 ]:
74- return self .body_colors ['left_arm' ]
75- elif landmark_id in [12 , 14 , 16 , 18 , 20 , 22 ]:
76- return self .body_colors ['right_arm' ]
77- elif landmark_id in [23 , 24 ]:
78- return self .body_colors ['hips' ]
79- elif landmark_id in [25 , 27 , 29 , 31 ]:
80- return self .body_colors ['left_leg' ]
81- elif landmark_id in [26 , 28 , 30 , 32 ]:
82- return self .body_colors ['right_leg' ]
83- else :
84- return '#888888' # Gray fallback
85-
8663 def normalize_to_svg_coords (self , x : float , y : float ) -> Tuple [float , float ]:
8764 """
8865 Convert normalized coordinates (0-1) to SVG coordinates.
@@ -187,7 +164,7 @@ def generate(self, tracking_data: TrackingData) -> ET.ElementTree:
187164 path_data += f" L { x :.2f} { y :.2f} "
188165
189166 path_elem .set ('d' , path_data )
190- path_elem .set ('stroke' , self .get_landmark_color (landmark_id ))
167+ path_elem .set ('stroke' , self .palette . get_landmark_color (landmark_id ))
191168 path_elem .set ('stroke-width' , '1' )
192169 path_elem .set ('fill' , 'none' )
193170 path_elem .set ('opacity' , '0.7' )
@@ -230,12 +207,12 @@ def add_legend(self, svg_root: ET.Element) -> None:
230207
231208 # Legend entries
232209 legend_items = [
233- ('Face' , self .body_colors [ 'face' ] ),
234- ('Left Arm' , self .body_colors [ 'left_arm' ] ),
235- ('Right Arm' , self .body_colors [ 'right_arm' ] ),
236- ('Hips' , self .body_colors [ 'hips' ] ),
237- ('Left Leg' , self .body_colors [ 'left_leg' ] ),
238- ('Right Leg' , self .body_colors [ 'right_leg' ] )
210+ ('Face' , self .palette . get_body_region_color ( 'face' ) ),
211+ ('Left Arm' , self .palette . get_body_region_color ( 'left_arm' ) ),
212+ ('Right Arm' , self .palette . get_body_region_color ( 'right_arm' ) ),
213+ ('Hips' , self .palette . get_body_region_color ( 'hips' ) ),
214+ ('Left Leg' , self .palette . get_body_region_color ( 'left_leg' ) ),
215+ ('Right Leg' , self .palette . get_body_region_color ( 'right_leg' ) )
239216 ]
240217
241218 for i , (label , color ) in enumerate (legend_items ):
0 commit comments