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
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 @@
gen_time=datetime.datetime.now(),
file_name=os.path.basename(image_filename),
year=datetime.datetime.now().year)
+ # IFM size
+ ifm_width = image_size[0]
+ ifm_height = image_size[1]
- 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)))
+ # 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()