Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,9 @@ from PIL import Image
|
|
| 6 |
import cv2
|
| 7 |
import mediapipe as mp
|
| 8 |
|
|
|
|
| 9 |
mp_pose = mp.solutions.pose
|
| 10 |
-
|
| 11 |
|
| 12 |
# Load sample product data
|
| 13 |
product_data = pd.DataFrame({
|
|
@@ -18,14 +19,13 @@ product_data = pd.DataFrame({
|
|
| 18 |
})
|
| 19 |
|
| 20 |
def get_keypoints(image):
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
return keypoints
|
| 29 |
|
| 30 |
def process_image(image, product):
|
| 31 |
# Convert the uploaded image to a PIL image
|
|
|
|
| 6 |
import cv2
|
| 7 |
import mediapipe as mp
|
| 8 |
|
| 9 |
+
# Initialize Mediapipe Pose
|
| 10 |
mp_pose = mp.solutions.pose
|
| 11 |
+
pose = mp_pose.Pose(static_image_mode=True, model_complexity=2)
|
| 12 |
|
| 13 |
# Load sample product data
|
| 14 |
product_data = pd.DataFrame({
|
|
|
|
| 19 |
})
|
| 20 |
|
| 21 |
def get_keypoints(image):
|
| 22 |
+
results = pose.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
|
| 23 |
+
if not results.pose_landmarks:
|
| 24 |
+
return None
|
| 25 |
+
keypoints = {}
|
| 26 |
+
for idx, lm in enumerate(results.pose_landmarks.landmark):
|
| 27 |
+
keypoints[idx] = (int(lm.x * image.shape[1]), int(lm.y * image.shape[0]))
|
| 28 |
+
return keypoints
|
|
|
|
| 29 |
|
| 30 |
def process_image(image, product):
|
| 31 |
# Convert the uploaded image to a PIL image
|