Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert an image to a float image in opencv?

I have this code:

  Mat image00=imread("C:\\Working Dir\\Tests\\TestBlending\\layer0000.jpg");
  Mat image0;
  image00.convertTo(image0,CV_32FC3);

But after converting my image to float, the image is blank (all values are zero).

What is wrong with this code and how can I fix it?

like image 362
mans Avatar asked Oct 14 '25 07:10

mans


1 Answers

Try these:

1) image00.convertTo(image0, CV_32FC3, 1/255.0);

Mat Image type CV_8UC3, value is from 0 to 255. While CV_32FC3 is between 0.0 and 1.0, hence you have to scale it. If I am not wrong, you receive all zero values as the image consist of mainly BGR values under 125? If it still doesn't work, try this:

2)

//CvType
 image00.convertTo(image0, CvType.CV_32FC3, 1/255.0); //with or without scaling, try both

Should solve your problem(:

like image 93
rockinfresh Avatar answered Oct 16 '25 21:10

rockinfresh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!