Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,11 @@ import gradio as gr
|
|
| 2 |
import cv2
|
| 3 |
from gradio_webrtc import WebRTC
|
| 4 |
import os
|
| 5 |
-
import mediapipe as mp
|
| 6 |
-
from mediapipe.tasks import python
|
| 7 |
-
from mediapipe.tasks.python import vision, BaseOptions
|
| 8 |
-
from mediapipe import solutions
|
| 9 |
-
from mediapipe.framework.formats import landmark_pb2
|
| 10 |
import numpy as np
|
| 11 |
import cv2
|
| 12 |
from PIL import Image
|
|
@@ -14,43 +14,45 @@ from PIL import Image
|
|
| 14 |
MODEL_PATH = r"pose_landmarker_lite.task"
|
| 15 |
|
| 16 |
# Drawing landmarks
|
| 17 |
-
def draw_landmarks_on_image(rgb_image, detection_result):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
|
| 33 |
|
| 34 |
-
base_options = python.BaseOptions(delegate=0,model_asset_path=MODEL_PATH)
|
| 35 |
-
options = vision.PoseLandmarkerOptions(
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
detector = vision.PoseLandmarker.create_from_options(options)
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
def detection(image, conf_threshold=0.3):
|
| 43 |
frame = cv2.flip(image, 1)
|
| 44 |
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 45 |
-
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# # Pose detection
|
| 48 |
-
detection_result = detector.detect(mp_image)
|
| 49 |
|
| 50 |
-
|
| 51 |
-
annotated_image = draw_landmarks_on_image(mp_image.numpy_view(), detection_result)
|
| 52 |
|
| 53 |
-
return
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Blocks() as demo:
|
|
@@ -69,4 +71,4 @@ with gr.Blocks() as demo:
|
|
| 69 |
)
|
| 70 |
|
| 71 |
if __name__ == "__main__":
|
| 72 |
-
demo.launch()
|
|
|
|
| 2 |
import cv2
|
| 3 |
from gradio_webrtc import WebRTC
|
| 4 |
import os
|
| 5 |
+
# import mediapipe as mp
|
| 6 |
+
# from mediapipe.tasks import python
|
| 7 |
+
# from mediapipe.tasks.python import vision, BaseOptions
|
| 8 |
+
# from mediapipe import solutions
|
| 9 |
+
# from mediapipe.framework.formats import landmark_pb2
|
| 10 |
import numpy as np
|
| 11 |
import cv2
|
| 12 |
from PIL import Image
|
|
|
|
| 14 |
MODEL_PATH = r"pose_landmarker_lite.task"
|
| 15 |
|
| 16 |
# Drawing landmarks
|
| 17 |
+
# def draw_landmarks_on_image(rgb_image, detection_result):
|
| 18 |
+
# pose_landmarks_list = detection_result.pose_landmarks
|
| 19 |
+
# annotated_image = np.copy(rgb_image)
|
| 20 |
|
| 21 |
+
# for pose_landmarks in pose_landmarks_list:
|
| 22 |
+
# pose_landmarks_proto = landmark_pb2.NormalizedLandmarkList()
|
| 23 |
+
# pose_landmarks_proto.landmark.extend([
|
| 24 |
+
# landmark_pb2.NormalizedLandmark(x=landmark.x, y=landmark.y, z=landmark.z) for landmark in pose_landmarks
|
| 25 |
+
# ])
|
| 26 |
+
# solutions.drawing_utils.draw_landmarks(
|
| 27 |
+
# annotated_image,
|
| 28 |
+
# pose_landmarks_proto,
|
| 29 |
+
# solutions.pose.POSE_CONNECTIONS,
|
| 30 |
+
# solutions.drawing_styles.get_default_pose_landmarks_style())
|
| 31 |
+
# return annotated_image
|
| 32 |
|
| 33 |
|
| 34 |
+
# base_options = python.BaseOptions(delegate=0,model_asset_path=MODEL_PATH)
|
| 35 |
+
# options = vision.PoseLandmarkerOptions(
|
| 36 |
+
# base_options=base_options,
|
| 37 |
+
# output_segmentation_masks=True)
|
| 38 |
+
# detector = vision.PoseLandmarker.create_from_options(options)
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
def detection(image, conf_threshold=0.3):
|
| 43 |
frame = cv2.flip(image, 1)
|
| 44 |
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 45 |
+
|
| 46 |
+
rgb_frame=cv2.circle(rgb_frame,(90,90),(255,0,0),20)
|
| 47 |
+
# mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=rgb_frame)
|
| 48 |
|
| 49 |
# # Pose detection
|
| 50 |
+
# detection_result = detector.detect(mp_image)
|
| 51 |
|
| 52 |
+
# # Draw landmarks
|
| 53 |
+
# annotated_image = draw_landmarks_on_image(mp_image.numpy_view(), detection_result)
|
| 54 |
|
| 55 |
+
return rgb_frame
|
| 56 |
|
| 57 |
|
| 58 |
with gr.Blocks() as demo:
|
|
|
|
| 71 |
)
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|
| 74 |
+
demo.launch(share=True)
|