SelimGilon commited on
Commit
ce2144b
·
1 Parent(s): f6efe9e

Upload 3 files

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. app.py +85 -0
  3. pose_landmarker_heavy.task +3 -0
  4. requirements.txt +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ pose_landmarker_heavy.task filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from mediapipe import solutions
3
+ from mediapipe.framework.formats import landmark_pb2
4
+ import numpy as np
5
+ import mediapipe as mp
6
+ from mediapipe.tasks import python
7
+ from mediapipe.tasks.python import vision
8
+
9
+
10
+
11
+ def draw_landmarks_on_image(rgb_image, detection_result):
12
+ pose_landmarks_list = detection_result.pose_landmarks
13
+ annotated_image = np.copy(rgb_image)
14
+
15
+ # Loop through the detected poses to visualize.
16
+ for idx in range(len(pose_landmarks_list)):
17
+ pose_landmarks = pose_landmarks_list[idx]
18
+
19
+ # Draw the pose landmarks.
20
+ pose_landmarks_proto = landmark_pb2.NormalizedLandmarkList()
21
+ pose_landmarks_proto.landmark.extend([
22
+ landmark_pb2.NormalizedLandmark(x=landmark.x, y=landmark.y, z=landmark.z) for landmark in pose_landmarks
23
+ ])
24
+ solutions.drawing_utils.draw_landmarks(
25
+ annotated_image,
26
+ pose_landmarks_proto,
27
+ solutions.pose.POSE_CONNECTIONS,
28
+ solutions.drawing_styles.get_default_pose_landmarks_style())
29
+ return annotated_image
30
+
31
+
32
+
33
+ def app(image):
34
+ try:
35
+ image_annotated = section(image)
36
+ pass
37
+ except Exception as e:
38
+ return gr.Error(f"An error occurred: {str(e)}")
39
+
40
+ return image_annotated
41
+
42
+ with gr.Blocks() as demo:
43
+ with gr.Row():
44
+ ## Input
45
+ image = gr.Image(label="Input Image")
46
+ ## Output
47
+ image_annotated = gr.Image(label="Output Image")
48
+ with gr.Row():
49
+ detection_results = gr.Text("Pose Landmarks")
50
+
51
+ section_btn = gr.Button("Identify keypoints")
52
+
53
+
54
+
55
+ def section(image):
56
+ base_options = python.BaseOptions(model_asset_path='pose_landmarker_heavy.task')
57
+ options = vision.PoseLandmarkerOptions(
58
+ base_options=base_options,
59
+ output_segmentation_masks=True)
60
+ detector = vision.PoseLandmarker.create_from_options(options)
61
+
62
+ # STEP 3: Load the input image.
63
+ # image = mp.Image.create_from_file(image)
64
+ # image = mp.Image(ImageFormat.SRGB, image)
65
+ # image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
66
+ # image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
67
+
68
+ # Create a MediaPipe image using the BGR image
69
+ # Using 1 as the image format for BGR (which is the integer representation for mediapipe::ImageFormat::SRGB)
70
+ print(type(image))
71
+ mediapipe_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=image)
72
+
73
+ # STEP 4: Detect pose landmarks from the input image.
74
+ detection_result = detector.detect(mediapipe_image)
75
+
76
+ # STEP 5: Process the detection result. In this case, visualize it.
77
+ annotated_image = draw_landmarks_on_image(image, detection_result)
78
+ # cv2.imshow(cv2.cvtColor(annotated_image, cv2.COLOR_RGB2BGR))
79
+ return annotated_image, detection_result
80
+
81
+
82
+ section_btn.click(section, image, [image_annotated, detection_results])
83
+
84
+ demo.launch(share=True)
85
+ # demo.queue(max_size=99).launch(debug=True)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
pose_landmarker_heavy.task ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:64437af838a65d18e5ba7a0d39b465540069bc8aae8308de3e318aad31fcbc7b
3
+ size 30664242
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio~=4.12.0
2
+ numpy~=1.26.2
3
+ mediapipe~=0.10.9