Project import generated by Copybara.

GitOrigin-RevId: d4a11282d20fe4d2e137f9032cf349750030dcb9
This commit is contained in:
MediaPipe Team
2021-11-03 17:27:30 -07:00
committed by jqtang
parent 1faeaae7e5
commit d4bb35fe5a
72 changed files with 1089 additions and 336 deletions
+12 -5
View File
@@ -124,7 +124,10 @@ class Hands(SolutionBase):
'handlandmarkcpu__ThresholdingCalculator.threshold':
min_tracking_confidence,
},
outputs=['multi_hand_landmarks', 'multi_handedness'])
outputs=[
'multi_hand_landmarks', 'multi_hand_world_landmarks',
'multi_handedness'
])
def process(self, image: np.ndarray) -> NamedTuple:
"""Processes an RGB image and returns the hand landmarks and handedness of each detected hand.
@@ -137,10 +140,14 @@ class Hands(SolutionBase):
ValueError: If the input image is not three channel RGB.
Returns:
A NamedTuple object with two fields: a "multi_hand_landmarks" field that
contains the hand landmarks on each detected hand and a "multi_handedness"
field that contains the handedness (left v.s. right hand) of the detected
hand.
A NamedTuple object with the following fields:
1) a "multi_hand_landmarks" field that contains the hand landmarks on
each detected hand.
2) a "multi_hand_world_landmarks" field that contains the hand landmarks
on each detected hand in real-world 3D coordinates that are in meters
with the origin at the hand's approximate geometric center.
3) a "multi_handedness" field that contains the handedness (left v.s.
right hand) of the detected hand.
"""
return super().process(input_data={'image': image})
+9 -9
View File
@@ -34,20 +34,20 @@ from mediapipe.python.solutions import hands as mp_hands
TEST_IMAGE_PATH = 'mediapipe/python/solutions/testdata'
LITE_MODEL_DIFF_THRESHOLD = 25 # pixels
FULL_MODEL_DIFF_THRESHOLD = 20 # pixels
EXPECTED_HAND_COORDINATES_PREDICTION = [[[138, 343], [211, 330], [257, 286],
[289, 237], [322, 203], [219, 216],
[238, 138], [249, 90], [253, 51],
[177, 204], [184, 115], [187, 60],
[185, 19], [138, 208], [131, 127],
[124, 77], [117, 36], [106, 222],
[92, 159], [79, 124], [68, 93]],
[[580, 34], [504, 50], [459, 94],
EXPECTED_HAND_COORDINATES_PREDICTION = [[[580, 34], [504, 50], [459, 94],
[429, 146], [397, 182], [507, 167],
[479, 245], [469, 292], [464, 330],
[545, 180], [534, 265], [533, 319],
[536, 360], [581, 172], [587, 252],
[593, 304], [599, 346], [615, 168],
[628, 223], [638, 258], [648, 288]]]
[628, 223], [638, 258], [648, 288]],
[[138, 343], [211, 330], [257, 286],
[289, 237], [322, 203], [219, 216],
[238, 138], [249, 90], [253, 51],
[177, 204], [184, 115], [187, 60],
[185, 19], [138, 208], [131, 127],
[124, 77], [117, 36], [106, 222],
[92, 159], [79, 124], [68, 93]]]
class HandsTest(parameterized.TestCase):
+6
View File
@@ -80,6 +80,7 @@ class Holistic(SolutionBase):
smooth_landmarks=True,
enable_segmentation=False,
smooth_segmentation=True,
refine_face_landmarks=False,
min_detection_confidence=0.5,
min_tracking_confidence=0.5):
"""Initializes a MediaPipe Holistic object.
@@ -98,6 +99,10 @@ class Holistic(SolutionBase):
smooth_segmentation: Whether to filter segmentation across different input
images to reduce jitter. See details in
https://solutions.mediapipe.dev/holistic#smooth_segmentation.
refine_face_landmarks: Whether to further refine the landmark coordinates
around the eyes and lips, and output additional landmarks around the
irises. Default to False. See details in
https://solutions.mediapipe.dev/holistic#refine_face_landmarks.
min_detection_confidence: Minimum confidence value ([0.0, 1.0]) for person
detection to be considered successful. See details in
https://solutions.mediapipe.dev/holistic#min_detection_confidence.
@@ -114,6 +119,7 @@ class Holistic(SolutionBase):
'enable_segmentation': enable_segmentation,
'smooth_segmentation':
smooth_segmentation and not static_image_mode,
'refine_face_landmarks': refine_face_landmarks,
'use_prev_landmarks': not static_image_mode,
},
calculator_params={
+16 -10
View File
@@ -99,18 +99,23 @@ class PoseTest(parameterized.TestCase):
results = holistic.process(image)
self.assertIsNone(results.pose_landmarks)
@parameterized.named_parameters(('static_lite', True, 0, 3),
('static_full', True, 1, 3),
('static_heavy', True, 2, 3),
('video_lite', False, 0, 3),
('video_full', False, 1, 3),
('video_heavy', False, 2, 3))
def test_on_image(self, static_image_mode, model_complexity, num_frames):
@parameterized.named_parameters(('static_lite', True, 0, False, 3),
('static_full', True, 1, False, 3),
('static_heavy', True, 2, False, 3),
('video_lite', False, 0, False, 3),
('video_full', False, 1, False, 3),
('video_heavy', False, 2, False, 3),
('static_full_refine_face', True, 1, True, 3),
('video_full_refine_face', False, 1, True, 3))
def test_on_image(self, static_image_mode, model_complexity,
refine_face_landmarks, num_frames):
image_path = os.path.join(os.path.dirname(__file__),
'testdata/holistic.jpg')
image = cv2.imread(image_path)
with mp_holistic.Holistic(static_image_mode=static_image_mode,
model_complexity=model_complexity) as holistic:
with mp_holistic.Holistic(
static_image_mode=static_image_mode,
model_complexity=model_complexity,
refine_face_landmarks=refine_face_landmarks) as holistic:
for idx in range(num_frames):
results = holistic.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
self._annotate(image.copy(), results, idx)
@@ -129,7 +134,8 @@ class PoseTest(parameterized.TestCase):
EXPECTED_RIGHT_HAND_LANDMARKS,
HAND_DIFF_THRESHOLD)
# TODO: Verify the correctness of the face landmarks.
self.assertLen(results.face_landmarks.landmark, 468)
self.assertLen(results.face_landmarks.landmark,
478 if refine_face_landmarks else 468)
if __name__ == '__main__':