Skip to content
Snippets Groups Projects
Commit a21eb531 authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

[preprocessor] fixed the exception catching when landmarks are not detected

parent c3c6328b
No related branches found
No related tags found
1 merge request!71Debug pulse based pad
...@@ -117,31 +117,45 @@ class LiPulseExtraction(Preprocessor): ...@@ -117,31 +117,45 @@ class LiPulseExtraction(Preprocessor):
pyplot.show() pyplot.show()
# detect landmarks # detect landmarks
try: ldms = detector(frame)
ldms = detector(frame)
except TypeError: if ldms is None:
logger.warning("Exception caught -> problems with landmarks") logger.warning("Landmarks not detected ...")
# looks like one video from replay mobile is upside down !
# looks like some videos from replay mobile are upside down !
rotated_shape = bob.ip.base.rotated_output_shape(frame, 180) rotated_shape = bob.ip.base.rotated_output_shape(frame, 180)
frame_rotated = numpy.ndarray(rotated_shape, dtype=numpy.float64) frame_rotated = numpy.ndarray(rotated_shape, dtype=numpy.float64)
from bob.ip.base import rotate from bob.ip.base import rotate
bob.ip.base.rotate(frame, frame_rotated, 180) bob.ip.base.rotate(frame, frame_rotated, 180)
frame_rotated = frame_rotated.astype(numpy.uint8) frame_rotated = frame_rotated.astype(numpy.uint8)
logger.warning("Rotating again ...") logger.warning("Rotating 180 degrees ...")
try:
ldms = detector(frame_rotated) # check the rotated frame
except TypeError: if self.debug:
from matplotlib import pyplot
pyplot.imshow(numpy.rollaxis(numpy.rollaxis(frame_rotated, 2),2))
pyplot.show()
ldms = detector(frame_rotated)
# if landmarks are still not detected, do nothing
if ldms is None:
ldms = previous_ldms ldms = previous_ldms
# so do nothing ... # so do nothing ...
logger.warning("No mask detected in frame {}".format(i)) logger.warning("No mask detected in frame {}".format(i))
face_color[i] = [0, 0, 0] face_color[i] = [0, 0, 0]
continue continue
frame = frame_rotated frame = frame_rotated
# landmarks have not been detected: use the one from previous frame # if landmarks are still not detected, use the one from previous frame (if any)
if ldms is None: if ldms is None:
ldms = previous_ldms if previous_ldms is None:
logger.warning("Frame {}: no landmarks detected, using the ones from previous frame".format(i)) logger.warning("No mask detected in frame {}".format(i))
face_color[i] = [0, 0, 0]
continue
else:
ldms = previous_ldms
logger.warning("Frame {}: no landmarks detected, using the ones from previous frame".format(i))
if self.debug: if self.debug:
from matplotlib import pyplot from matplotlib import pyplot
...@@ -153,9 +167,7 @@ class LiPulseExtraction(Preprocessor): ...@@ -153,9 +167,7 @@ class LiPulseExtraction(Preprocessor):
ldms = numpy.array(ldms) ldms = numpy.array(ldms)
mask_points, mask = kp66_to_mask(frame, ldms, self.indent, self.debug) mask_points, mask = kp66_to_mask(frame, ldms, self.indent, self.debug)
face_color[i] = compute_average_colors_mask(frame, mask, self.debug) face_color[i] = compute_average_colors_mask(frame, mask, self.debug)
logger.debug("Face color in frame {} = {}".format(i, face_color[i]))
previous_ldms = ldms previous_ldms = ldms
counter += 1 counter += 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment