def fill_person_info(cls, person_id):
        if person_id in cls.standards:
            return

        signatures = FileAccess.get_files_of_person(person_id)
        normalized = [
            Normalizer.crop_make_binary_image(signature)
            for signature in signatures
        ]
        average_height = round(mean([image.shape[0] for image in normalized]))
        average_width = round(mean([image.shape[1] for image in normalized]))
        scaled_to_standard_dimensions_signatures =\
            [Normalizer.resize(average_width, average_height, img) for img in normalized]

        def get_black_pixel_no(pic):
            count = 0
            for i in range(pic.shape[0]):
                for j in range(pic.shape[1]):
                    if pic[i, j] == 0:
                        count += 1
            return count

        number_of_black_pixels = \
            [get_black_pixel_no(pic) for pic in scaled_to_standard_dimensions_signatures]
        max_no_black_pixels = max(number_of_black_pixels)
        min_no_black_pixels = min(number_of_black_pixels)

        cls.standards[person_id] = \
            SignatureStandard(average_height, average_width, min_no_black_pixels, max_no_black_pixels)
Ejemplo n.º 2
0
 def is_signature_real(cls, signature_image_name: str) -> bool:
     person_id = signature_image_name[-7:-4]
     standards_specifier = SignatureStandardsSpecifier(person_id=person_id)
     standards = standards_specifier.get_standards()
     pic = Normalizer.resize(
         standards.width, standards.height,
         cls.__get_normalized_image(signature_image_name))
     number_of_pixels = Detector.__count_black_pixels(pic)
     return standards.pixel_low_bound < number_of_pixels < standards.pixel_high_bound