Create a tier indicating the position of 2 points of the hand.
Predict the position of points S0 and S9 of an hand relatively to sights of a face.

Create a tier indicating the position of 2 points of the hand.
Predict the position of points S0 and S9 of an hand relatively to sights of a face.
Create a new instance.
def __init__(self, pos_predictor_version: int=WhereVowelPositionsPredictor.DEFAULT_VERSION, angle_predictor_version: int=WhereAnglesPredictor.DEFAULT_VERSION, cue_rules: CuedSpeechCueingRules=CuedSpeechCueingRules()):
"""Create a new instance.
:param cue_rules: (CuedSpeechKeys) Rules and codes for vowel positions and hand shapes
"""
if isinstance(cue_rules, CuedSpeechCueingRules) is False:
raise sppasTypeError('cue_rules', 'CuedSpeechCueingRules')
self.__fps = 50
self.__pos_predictor = sppasWherePositionsPredictor(pos_predictor_version)
self.__angle_predictor = sppasWhereAnglesPredictor(angle_predictor_version)
self.__cued = None
self.__gentargets = TargetProbabilitiesEstimator()
self.set_cue_rules(cue_rules)
Return the list of version numbers of the vowel positions generator system.
def get_wherepositionpredictor_versions(self) -> list:
"""Return the list of version numbers of the vowel positions generator system."""
return self.__pos_predictor.version_numbers()
Return the list of version numbers of the angles generation system.
def get_whereanglepredictor_versions(self) -> list:
"""Return the list of version numbers of the angles generation system."""
return self.__angle_predictor.version_numbers()
Return the version number of the vowel positions prediction system.
def get_wherepositionpredictor_version(self) -> int:
"""Return the version number of the vowel positions prediction system."""
return self.__pos_predictor.get_version_number()
Return the version number of the angle prediction system.
def get_whereanglepredictor_version(self) -> int:
"""Return the version number of the angle prediction system."""
return self.__angle_predictor.get_version_number()
Change the vowel position predictor version number.
def set_wherepositionpredictor_version(self, version_number: int) -> None:
"""Change the vowel position predictor version number.
:param version_number: (int) One of the supported versions.
:raises: sppasKeyError: if invalid version number
"""
self.__pos_predictor.set_version_number(version_number)
Change the angle predictor version number.
def set_whereanglepredictor_version(self, version_number: int) -> None:
"""Change the angle predictor version number.
:param version_number: (int) One of the supported versions.
:raises: sppasKeyError: if invalid version number
"""
self.__angle_predictor.set_version_number(version_number)
Set new rules.
def set_cue_rules(self, cue_rules: CuedSpeechCueingRules) -> None:
"""Set new rules.
:param cue_rules: (CuedSpeechCueingRules) Rules and codes for vowel positions and hand shapes
:raises: sppasTypeError: given parameter is not CuedSpeechCueingRules
"""
if isinstance(cue_rules, CuedSpeechCueingRules) is False:
raise sppasTypeError('cue_rules', 'CuedSpeechCueingRules')
self.__cued = cue_rules
self.__gentargets.set_cue_rules(cue_rules)
Return True if the hand angle must be corrected by the one of the face.
def get_angle_use_face(self) -> bool:
"""Return True if the hand angle must be corrected by the one of the face."""
return self.__angle_predictor.get_use_face()
The angle of the hand is corrected by the one of the face or not.
def set_angle_use_face(self, value: bool) -> None:
"""The angle of the hand is corrected by the one of the face or not.
:param value: (bool) True if the angle of the hand has to be corrected.
"""
self.__angle_predictor.set_use_face(value)
Prodict where to cue, hand angle and hand size from face sights.
def predict_where(self, file_sights, tier_pos_transitions, tier_shapes_transitions):
"""Prodict where to cue, hand angle and hand size from face sights.
:param file_sights: (str) Filename with 68 sights of a face for each image of a video
:param tier_pos_transitions: (sppasTier) Predicted hand position transitions
:param tier_shapes_transitions: (sppasTier) Predicted hand shapes transitions
:return: (sppasTranscription)
"""
face_sights = self._load_sights(file_sights, kid_index=0)
self.__set_fps(face_sights)
tier_sizes = sppasFaceHeightGenerator(face_sights).face_height(fps=self.__fps)
self.__pos_predictor.set_sights(face_sights)
tier_pos_coords = self.__pos_predictor.vowels_coords(self.__cued.get_vowels_codes(), smooth_len=self.__fps // 5)
tier_pos_probas = self.__gentargets.positions_discretization(tier_pos_coords, tier_pos_transitions)
tier_shp_probas = self.__gentargets.shapes_discretization(tier_pos_coords, tier_shapes_transitions)
tier_target_coords = self.__gentargets.hands_to_target_coords(tier_pos_probas, tier_pos_coords)
tier_angles = self.__angle_predictor.hand_angles(tier_pos_probas, face_sights)
trs = sppasTranscription('WhereToCue')
trs.append(tier_pos_coords)
trs.append(tier_shp_probas)
trs.append(tier_pos_probas)
trs.append(tier_angles)
trs.append(tier_sizes)
trs.append(tier_target_coords)
return trs
Load a filename and store the sights of a given kid.
The returned data is a list of tuples with:
def _load_sights(self, filename: str, kid_index: int=0) -> list:
"""Load a filename and store the sights of a given kid.
The returned data is a list of tuples with:
- at index 0: midpoint time value
- at index 1: radius time value
- at index 2: the 68 sights of a face
:param filename: (str) Filename of the XRA/CSV with sights
:param kid_index: (int) index of the kid to get sights
:raises: sppasWhereCuedSightsValueError: there are sights but there are not of the expected size
:raises: Exception:
:return: (list)
"""
data = sppasSightsVideoReader(filename)
cur_sights = self.__get_current_sights(data, kid_index)
data_sights = list()
for (i, kids_sights) in enumerate(data.sights):
midpoint = data.midpoints[i]
if midpoint is None:
raise Exception('No time point value at index {:d}.'.format(i))
if 0 < len(kids_sights) <= kid_index + 1:
s = kids_sights[kid_index]
if s is not None:
cur_sights = s
else:
logging.warning('No estimated sights at frame number {:d} for kid {:d}.'.format(i + 1, kid_index))
else:
logging.warning('No estimated sights at frame number {:d} for kid {:d}.'.format(i + 1, kid_index))
data_sights.append((midpoint, data.radius[i], cur_sights))
return data_sights
Fix the video frames-per-seconds value.
def __set_fps(self, data_sights: list) -> None:
"""Fix the video frames-per-seconds value."""
if len(data_sights) == 0:
self.__fps = 50
else:
first_midpoint = data_sights[0][0]
self.__fps = int(1.0 / first_midpoint)
logging.debug(f'Video fps={self.__fps}')
Return the sights at given index.
def __get_current_sights(self, data: sppasSightsVideoReader, kid_index: int) -> sppasSights:
"""Return the sights at given index.
:param data: (sppasSightsVideoReader) Video reader with sights
:param kid_index: (int) index of the kid to get sights
:raises: sppasWhereCuedSightsValueError: there are sights but there are not of the expected size
:raises: Exception:
"""
cur_sights = sppasSights()
for (i, kids_sights) in enumerate(data.sights):
if 0 < len(kids_sights) <= kid_index + 1:
cur_sights = kids_sights[kid_index]
if cur_sights is not None:
break
return cur_sights