Convert uchar Mat to float Mat in OpenCV?

If you meant c++ then you have

#include<opencv2/opencv.hpp>
using namespace cv;
Mat img;
img.create(2,2,CV_8UC1);
Mat img2;
img.convertTo(img2, CV_32FC1); // or CV_32F works (too)

details in opencv2refman.pdf.

UPDATE:

CV_32FC1 is for 1-channel (C1, i.e. grey image) float valued (32F) pixels

CV_8UC1 is for 1-channel (C1, i.e. grey image) unsigned char (8UC) valued ones.

UPDATE 2:
According to Arthur Tacca, only CV_32F is correct (or presumably CV_8U), since convertTo should not change the number of channels. It sounds logical right? Nevertheless, when I have checked opencv reference manual, I could not find any info about this, but I agree with him.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)