C++ Frontend: How do you load a RGB image with OpenCV and convert it to float


(Marios Asp) #1

I have checked on how to use the new C++ Frontend.
It seems easy to use but I have a question on how to load RGB images and convert them to tensors in C++.

For example if you read an image with OpenCV, with cv::IMREAD_UNCHANGED then the data will be a CV_8UC3 (assuming this is RGB).

Now to convert this to floats you can use the function src.convertTo(dst, CV_32FC3), but it would not work when you try to input the data to your model.
There is a difference when using the python version to load the data because with torchvision.transforms.ToTensor() does that automatically.

Is there a way to do it the same way as it is done with the torchvision library? Or did anyone else found a way that works?


(Thomas V) #2

My tracing patch for maskrcnn-benchmark has an example.

Best regards

Thomas