in models/01_YoloV5/01_Pytorch/processing_cpp/src/processor.cc [19:33]
vecf Processor::prepareImage(const vecu& image, bool keepAspectRatio ) {
// convert a raw RGB image to CHW. Make it square to keep aspect ration if required
vecf img;
if (keepAspectRatio) {
auto shape = image.shape();
unsigned long imgSize = shape[0];
if (shape[0] != shape[1]) imgSize = std::max(shape[0], shape[1]);
img = xt::zeros<float>({imgSize, imgSize, shape[2]});
xt::view(img, xt::range(0, shape[0]), xt::range(0, shape[1]), xt::all()) = image;
} else {
img = image;
} // else
img /= 255;
return xt::transpose(img, {2,0,1});
}