[Atlas200] Use Mindx v2 interface (C++) to complete letterbox, padding operation after scaling with equal aspect ratio

Introduction to letterbox

In deep learning, image size is important for model training and inference. In order to maintain the aspect ratio of the input image and avoid distortion caused by scaling, the image is usually cropped or embedded (padding). Among them, letterbox is a commonly used embedding operation, and its main idea is to add a black border around the image so that the size of the image is consistent with the expected input size of the model. In this way, the input image can be scaled to the expected input size of the model without breaking the aspect ratio of the image. Therefore, letterbox can effectively improve the training and inference performance of the model while maintaining the visual quality of the image. In the training phase, letterbox can also avoid the problem of batch sample size inconsistency caused by image size inconsistency. In practical applications, letterbox is usually used in deep learning tasks such as target detection and face recognition.

Complete letterbox using python

This code is to preprocess the input image, the specific steps are as follows:

1. According to the number of channels of the input image, create a blank image padding_image with the same size as the model input.

2. Calculate the scaling ratio between the original image and the model input size, and scale the original image according to this ratio

Guess you like

Origin blog.csdn.net/hh1357102/article/details/130811544