Пример #1
0
    def test_face_cropped_ok(self):
        """Detect faces from a folder of Kinect images.

        If this test fails it means that:
            - our face detection algorithm has improved and we detect faces in
            much more images than the beginning.
            Uncomment line 119, run test again and check output images!
            Update face_images array! :)
            or
            - our face detection algorithm is buggy and it does not recognize
            the same images as the beginning.
        """
        from lib.opencv import crop_face_from_image
        from os import listdir

        image_folder = "%s/headcrop_dataset/" % PROJECT_PATH
        images = [image for image in listdir(image_folder)
                  if not image.endswith('_result.jpg')]
        face_images = ['2.jpg', '3.jpg', '11.jpg', '12.jpg', '14.jpg',
                       '18.jpg', '20.jpg', '21.jpg']

        for image_file in images:
            image = Image.open("%s/%s" % (image_folder, image_file))
            cropped_head = crop_face_from_image(image)
            if cropped_head is not None:
                #cropped_head.save("%s/%s_result.jpg" % (image_folder, image_file))
                self.assertIn(image_file, face_images)
            else:
                self.assertNotIn(image_file, face_images)
Пример #2
0
def _crop_head_using_face_detection(last_image):
    """ Given the last image, try to detect any faces in it
        and crop the first one of them, if any. """
    image = base64_to_image(last_image['image'],
                            int(last_image['width']),
                            int(last_image['height']),
                            last_image['encoder_name'])
    return crop_face_from_image(image)
Пример #3
0
 def test_face_cropped_ok(self):
     from lib.opencv import crop_face_from_image
     from os import listdir
     image_folder = "/home/ami/AmI-Platform/headcrop_dataset"
     images = [ image for image in listdir(image_folder) if not image.endswith('_result.jpg')]
     
     for image_file in images:
         image = Image.open("%s/%s" % (image_folder,image_file))
         logging.debug("processing image %s" % image_file)
         cropped_head = crop_face_from_image(image)
         if cropped_head is not None:
             cropped_head.save("%s/%s_result.jpg" % (image_folder, image_file))
             print '.'