Spaces:
Runtime error
Runtime error
Commit ·
44d36fa
1
Parent(s): e323f4d
Upload 3 files
Browse files- app.py +86 -0
- mvp.jpg +0 -0
- requirements.txt +90 -0
app.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
from mediapipe import solutions
|
| 4 |
+
from mediapipe.framework.formats import landmark_pb2
|
| 5 |
+
import numpy as np
|
| 6 |
+
import mediapipe as mp
|
| 7 |
+
from mediapipe.tasks import python
|
| 8 |
+
from mediapipe.tasks.python import vision
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def draw_landmarks_on_image(rgb_image, detection_result):
|
| 13 |
+
pose_landmarks_list = detection_result.pose_landmarks
|
| 14 |
+
annotated_image = np.copy(rgb_image)
|
| 15 |
+
|
| 16 |
+
# Loop through the detected poses to visualize.
|
| 17 |
+
for idx in range(len(pose_landmarks_list)):
|
| 18 |
+
pose_landmarks = pose_landmarks_list[idx]
|
| 19 |
+
|
| 20 |
+
# Draw the pose landmarks.
|
| 21 |
+
pose_landmarks_proto = landmark_pb2.NormalizedLandmarkList()
|
| 22 |
+
pose_landmarks_proto.landmark.extend([
|
| 23 |
+
landmark_pb2.NormalizedLandmark(x=landmark.x, y=landmark.y, z=landmark.z) for landmark in pose_landmarks
|
| 24 |
+
])
|
| 25 |
+
solutions.drawing_utils.draw_landmarks(
|
| 26 |
+
annotated_image,
|
| 27 |
+
pose_landmarks_proto,
|
| 28 |
+
solutions.pose.POSE_CONNECTIONS,
|
| 29 |
+
solutions.drawing_styles.get_default_pose_landmarks_style())
|
| 30 |
+
return annotated_image
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def app(image):
|
| 35 |
+
try:
|
| 36 |
+
image_annotated = section(image)
|
| 37 |
+
pass
|
| 38 |
+
except Exception as e:
|
| 39 |
+
return gr.Error(f"An error occurred: {str(e)}")
|
| 40 |
+
|
| 41 |
+
return image_annotated
|
| 42 |
+
|
| 43 |
+
with gr.Blocks() as demo:
|
| 44 |
+
with gr.Row():
|
| 45 |
+
## Input
|
| 46 |
+
image = gr.Image(label="Input Image")
|
| 47 |
+
## Output
|
| 48 |
+
image_annotated = gr.Image(label="Output Image")
|
| 49 |
+
with gr.Row():
|
| 50 |
+
detection_results = gr.Text("Pose Landmarks")
|
| 51 |
+
|
| 52 |
+
section_btn = gr.Button("Identify keypoints")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def section(image):
|
| 57 |
+
base_options = python.BaseOptions(model_asset_path='pose_landmarker_heavy.task')
|
| 58 |
+
options = vision.PoseLandmarkerOptions(
|
| 59 |
+
base_options=base_options,
|
| 60 |
+
output_segmentation_masks=True)
|
| 61 |
+
detector = vision.PoseLandmarker.create_from_options(options)
|
| 62 |
+
|
| 63 |
+
# STEP 3: Load the input image.
|
| 64 |
+
# image = mp.Image.create_from_file(image)
|
| 65 |
+
# image = mp.Image(ImageFormat.SRGB, image)
|
| 66 |
+
# image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 67 |
+
# image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
| 68 |
+
|
| 69 |
+
# Create a MediaPipe image using the BGR image
|
| 70 |
+
# Using 1 as the image format for BGR (which is the integer representation for mediapipe::ImageFormat::SRGB)
|
| 71 |
+
print(type(image))
|
| 72 |
+
mediapipe_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=image)
|
| 73 |
+
|
| 74 |
+
# STEP 4: Detect pose landmarks from the input image.
|
| 75 |
+
detection_result = detector.detect(mediapipe_image)
|
| 76 |
+
|
| 77 |
+
# STEP 5: Process the detection result. In this case, visualize it.
|
| 78 |
+
annotated_image = draw_landmarks_on_image(image, detection_result)
|
| 79 |
+
# cv2.imshow(cv2.cvtColor(annotated_image, cv2.COLOR_RGB2BGR))
|
| 80 |
+
return annotated_image, detection_result
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
section_btn.click(section, image, [image_annotated, detection_results])
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
demo.queue(max_size=99).launch(debug=True)
|
mvp.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
aiofiles==0.8.0
|
| 2 |
+
anyio==3.6.1
|
| 3 |
+
argcomplete==2.0.0
|
| 4 |
+
backports.cached-property==1.0.2
|
| 5 |
+
boto3==1.24.31
|
| 6 |
+
botocore==1.27.31
|
| 7 |
+
certifi==2022.9.24
|
| 8 |
+
charset-normalizer==2.1.0
|
| 9 |
+
click==8.1.3
|
| 10 |
+
cycler==0.11.0
|
| 11 |
+
dacite==1.6.0
|
| 12 |
+
Deprecated==1.2.13
|
| 13 |
+
dill==0.3.5.1
|
| 14 |
+
dnspython==2.2.1
|
| 15 |
+
eventlet==0.33.1
|
| 16 |
+
fiftyone==0.16.5
|
| 17 |
+
fiftyone-brain==0.8.2
|
| 18 |
+
fiftyone-db==0.3.0
|
| 19 |
+
fonttools==4.34.4
|
| 20 |
+
future==0.18.2
|
| 21 |
+
glob2==0.7
|
| 22 |
+
graphql-core==3.1.7
|
| 23 |
+
greenlet==1.1.2
|
| 24 |
+
h11==0.12.0
|
| 25 |
+
h2==4.1.0
|
| 26 |
+
hpack==4.0.0
|
| 27 |
+
httpcore==0.15.0
|
| 28 |
+
httpx==0.23.0
|
| 29 |
+
hypercorn==0.13.2
|
| 30 |
+
hyperframe==6.0.1
|
| 31 |
+
idna==3.3
|
| 32 |
+
imageio==2.19.5
|
| 33 |
+
Jinja2==3.1.2
|
| 34 |
+
jmespath==1.0.1
|
| 35 |
+
joblib==1.1.0
|
| 36 |
+
kaleido==0.2.1
|
| 37 |
+
kiwisolver==1.4.4
|
| 38 |
+
MarkupSafe==2.1.1
|
| 39 |
+
matplotlib==3.5.2
|
| 40 |
+
mongoengine==0.20.0
|
| 41 |
+
motor==2.5.1
|
| 42 |
+
ndjson==0.3.1
|
| 43 |
+
networkx==2.8.4
|
| 44 |
+
numpy==1.23.1
|
| 45 |
+
opencv-python-headless==4.6.0.66
|
| 46 |
+
packaging==21.3
|
| 47 |
+
pandas==1.4.3
|
| 48 |
+
patool==1.12
|
| 49 |
+
Pillow==9.2.0
|
| 50 |
+
plotly==4.14.3
|
| 51 |
+
pprintpp==0.4.0
|
| 52 |
+
priority==2.0.0
|
| 53 |
+
psutil==5.9.1
|
| 54 |
+
Pygments==2.12.0
|
| 55 |
+
pymongo==3.12.3
|
| 56 |
+
pyparsing==3.0.9
|
| 57 |
+
python-dateutil==2.8.2
|
| 58 |
+
python-multipart==0.0.5
|
| 59 |
+
pytz==2022.1
|
| 60 |
+
pytz-deprecation-shim==0.1.0.post0
|
| 61 |
+
PyWavelets==1.3.0
|
| 62 |
+
PyYAML==6.0
|
| 63 |
+
requests==2.28.1
|
| 64 |
+
retrying==1.3.3
|
| 65 |
+
rfc3986==1.5.0
|
| 66 |
+
s3transfer==0.6.0
|
| 67 |
+
scikit-image==0.19.3
|
| 68 |
+
scikit-learn==1.1.1
|
| 69 |
+
scipy==1.8.1
|
| 70 |
+
sentinel==0.3.0
|
| 71 |
+
six==1.16.0
|
| 72 |
+
sniffio==1.2.0
|
| 73 |
+
sortedcontainers==2.4.0
|
| 74 |
+
sse-starlette==0.10.3
|
| 75 |
+
sseclient-py==1.7.2
|
| 76 |
+
starlette==0.16.0
|
| 77 |
+
strawberry-graphql==0.96.0
|
| 78 |
+
tabulate==0.8.10
|
| 79 |
+
threadpoolctl==3.1.0
|
| 80 |
+
tifffile==2022.5.4
|
| 81 |
+
toml==0.10.2
|
| 82 |
+
typing_extensions==4.3.0
|
| 83 |
+
tzdata==2022.1
|
| 84 |
+
tzlocal==4.2
|
| 85 |
+
universal-analytics-python3==1.1.1
|
| 86 |
+
urllib3==1.26.10
|
| 87 |
+
voxel51-eta==0.7.1
|
| 88 |
+
wrapt==1.14.1
|
| 89 |
+
wsproto==1.1.0
|
| 90 |
+
xmltodict==0.13.0
|