How to convert CV_8UC3 Mat to CV_32FC3?

Is there a way to convert from CV_8UC3 Mat to CV_32FC3 Mat without direct access to the raw buffer? I tried Mat::convertTo(newImage, CV_32FC3, 1.0); but the colors turned out to be wrong. Thanks.

+6
source share
1 answer

The agreement is that for type CV_8UC3, pixel values ​​range from 0 to 255, and for type CV_32FC3, they range from 0.0 to 1.0. Thus, you need to use a scale factor of 1 / 255.0 instead of 1.0:

 Mat::convertTo(newImage, CV_32FC3, 1/255.0); 
+13
source

Source: https://habr.com/ru/post/886282/


All Articles