ytry / main.py
Anm5's picture
Create main.py
40b2cec verified
Raw History Blame Contribute Delete
1.23 kB
def run(image: np.ndarray, model_complexity: int, enable_segmentation: bool,
min_detection_confidence: float, background_color: str) -> np.ndarray:
with mp_pose.Pose(
static_image_mode=True,
model_complexity=model_complexity,
enable_segmentation=enable_segmentation,
min_detection_confidence=min_detection_confidence,
) as pose:
results = pose.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
res = image.copy()
if enable_segmentation and results.segmentation_mask is not None:
mask = results.segmentation_mask
if background_color == 'white':
bg_color = (255, 255, 255)
elif background_color == 'black':
bg_color = (0, 0, 0)
elif background_color == 'green':
bg_color = (0, 255, 0)
else:
raise ValueError("Invalid background color")
res[mask <= 0.1] = bg_color
if results.pose_landmarks:
mp_drawing.draw_landmarks(
res, results.pose_landmarks, mp_pose.POSE_CONNECTIONS,
landmark_drawing_spec=mp_drawing_styles.get_default_pose_landmarks_style()
)
return res
# Adapt your existing pose classification code as needed.