From 79d4154ee071d0e7ef2d1eecdde149d488bb9d8b Mon Sep 17 00:00:00 2001 From: Isabella Gottardi Date: Wed, 20 Oct 2021 15:52:32 +0100 Subject: MLECO-2458 and MLECO-2476 [Fix] VWW IFM quant step * Changed image->cc conversion to be similar with preprocessing of img_class and vww models: images are scaled maintaing the aspect ration and then the centre crop of the correct size is taken. * VWW applies input quantization info to the int8 image (prior converted to [0,1] float range). * Changed adult_blur to a image without person. * Fix menu print when selecting a specific ifm to run (Select message was displayed after typing something) Change-Id: Ie6cde7ab4835ea842667b87397458a5d32131df3 --- scripts/py/gen_rgb_cpp.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'scripts/py') diff --git a/scripts/py/gen_rgb_cpp.py b/scripts/py/gen_rgb_cpp.py index 957d2d0..c53fbd7 100644 --- a/scripts/py/gen_rgb_cpp.py +++ b/scripts/py/gen_rgb_cpp.py @@ -70,12 +70,23 @@ def write_individual_img_cc_file(image_filename, cc_filename, header_template_fi gen_time=datetime.datetime.now(), file_name=os.path.basename(image_filename), year=datetime.datetime.now().year) - - original_image.thumbnail(image_size) - delta_w = abs(image_size[0] - original_image.size[0]) - delta_h = abs(image_size[1] - original_image.size[1]) - resized_image = Image.new('RGB', args.image_size, (255, 255, 255, 0)) - resized_image.paste(original_image, (int(delta_w / 2), int(delta_h / 2))) + # IFM size + ifm_width = image_size[0] + ifm_height = image_size[1] + + # Aspect ratio resize + scale_ratio = (float)(max(ifm_width, ifm_height)) / (float)(min(original_image.size[0], original_image.size[1])) + resized_width = (int)(original_image.size[0] * scale_ratio) + resized_height = (int)(original_image.size[1] * scale_ratio) + resized_image = original_image.resize([resized_width,resized_height], Image.BILINEAR) + + # Crop the center of the image + resized_image = resized_image.crop(( + (resized_width - ifm_width) / 2, # left + (resized_height - ifm_height) / 2, # top + (resized_width + ifm_width) / 2, # right + (resized_height + ifm_height) / 2 # bottom + )) # Convert the image and write it to the cc file rgb_data = np.array(resized_image, dtype=np.uint8).flatten() -- cgit v1.2.1