Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the dataype of a Mat class instance in OpenCV C++ Interface

Tags:

c++

image

opencv

How can i change the datatype used in storing the pixels in a Mat class instance?

For example after reading an image using the line below

Mat I = imread(file,0);

i obtain a grayscale image with pixels of type unsigned char. I want to change this to a double.

What's the best way to do the conversion? I wasn't able to find a function to do that.

Thanks in advance

like image 997
sct Avatar asked Jul 06 '10 16:07

sct


People also ask

How do I change my mat type?

To change your selection tap the mat settings icon in the upper left corner. Then tap Select Material Load Type and choose a new Type from the list. Tap OK to apply the change.

What is use of mat class in OpenCV?

The Mat class of OpenCV library is used to store the values of an image. It represents an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.

How is an OpenCV image stored in memory?

OpenCV has been around since 2001. In those days the library was built around a C interface and to store the image in the memory they used a C structure called IplImage. This is the one you'll see in most of the older tutorials and educational materials.

What is Mat CPP?

Mat is basically a class with two data parts : the matrix header (containing information such as the size of the matrix, the method used for storing, at which address is the matrix stored, and so on) and a pointer to the matrix containing the pixel values (taking any dimensionality depending on the method chosen for ...


1 Answers

It is very simple. See the documentation at OpenCV website.

Basically do

Mat double_I;
I.convertTo(double_I, CV_64F);
like image 170
Dat Chu Avatar answered Oct 05 '22 03:10

Dat Chu