Changing dataype of instance of class Mat in OpenCV C ++ interface

How can I change the data type used to store pixels in an instance of the Mat class?

For example, after reading the image using the line below

Mat i = imread (file, 0);

I get a halftone image with pixels of type unsigned char. I want to change this to double.

What is the best way to do the conversion? I could not find a function for this.

Thanks in advance

+4
source share
1 answer

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

Basically do

Mat double_I;
I.convertTo(double_I, CV_64F);
+17
source

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


All Articles