Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert CV_8UC3 Mat to CV_32FC3?

Tags:

opencv

Is there a way to convert from CV_8UC3 Mat to CV_32FC3 Mat without directly accessing the raw buffer? I tried Mat::convertTo(newImage, CV_32FC3, 1.0); but the colors end up wrong. Thanks.

like image 626
myuser7k23 Avatar asked Apr 20 '11 01:04

myuser7k23


1 Answers

The convention is, that for the type CV_8UC3 the pixels values range from 0 to 255, and for type CV_32FC3 from 0.0 to 1.0. Thus you need to use a scaling factor of 1/255.0 instead of 1.0:

Mat::convertTo(newImage, CV_32FC3, 1/255.0);
like image 90
Martin Avatar answered Oct 14 '22 01:10

Martin