1616"""MediaPipe Hands."""
1717
1818import enum
19- from typing import NamedTuple
19+ from typing import NamedTuple , Optional , Tuple
2020
2121import numpy as np
2222
@@ -168,7 +168,8 @@ def __init__(self,
168168 static_image_mode = False ,
169169 max_num_hands = 2 ,
170170 min_detection_confidence = 0.7 ,
171- min_tracking_confidence = 0.5 ):
171+ min_tracking_confidence = 0.5 ,
172+ outputs : Optional [Tuple [str ]] = ('multi_hand_landmarks' , 'multi_handedness' )):
172173 """Initializes a MediaPipe Hand object.
173174
174175 Args:
@@ -193,6 +194,9 @@ def __init__(self,
193194 robustness of the solution, at the expense of a higher latency. Ignored
194195 if "static_image_mode" is True, where hand detection simply runs on
195196 every image. Default to 0.5.
197+ outputs: A tuple of the graph output stream names to observe. If the tuple
198+ is empty, all the output streams listed in the graph config will be
199+ automatically observed by default.
196200 """
197201 super ().__init__ (
198202 binary_graph_path = BINARYPB_FILE_PATH ,
@@ -206,7 +210,7 @@ def __init__(self,
206210 'handlandmarkcpu__ThresholdingCalculator.threshold' :
207211 min_tracking_confidence ,
208212 },
209- outputs = [ 'multi_hand_landmarks' , 'multi_handedness' ])
213+ outputs = list ( outputs ) if outputs else [ ])
210214
211215 def process (self , image : np .ndarray ) -> NamedTuple :
212216 """Processes an RGB image and returns the hand landmarks and handedness of each detected hand.
@@ -219,10 +223,13 @@ def process(self, image: np.ndarray) -> NamedTuple:
219223 ValueError: If the input image is not three channel RGB.
220224
221225 Returns:
222- A NamedTuple object with two fields: a "multi_hand_landmarks" field that
223- contains the hand landmarks on each detected hand and a "multi_handedness"
224- field that contains the handedness (left v.s. right hand) of the detected
225- hand.
226+ A NamedTuple object with fields corresponding to the set of outputs passed to the
227+ constructor. Fields may include:
228+ "multi_hand_landmarks" The hand landmarks on each detected hand
229+ "multi_handedness" The handedness (left v.s. right hand) of the detected hand
230+ "palm_detections" The detected palms
231+ "hand_rects" Regions of interest calculated based on landmarks
232+ "hand_rects_from_palm_detections" Regions of interest calculated based on palm detections
226233 """
227234
228235 return super ().process (input_data = {'image' : image })
0 commit comments