Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe converting a Mat to itself with different type?

Tags:

c++

opencv

Suppose I want to use a Mat as float. The following code can be compiled without error. However, is it safe doing this?

Mat im = imread('test.jpg', CV_LOAD_IMAGE_GRAYSCALE);
im.convertTo(im, CV_32F1);

I want to do this because it's written more compact, otherwise I need to create a temporary Mat.

The documentation of Mat::convertTo() doesn't give much information about the memory usage of the function.

like image 818
nn0p Avatar asked Jan 31 '26 11:01

nn0p


1 Answers

Mat::convertTo function should be safe to use when using inplace calls (i.e. same input and output Mat objects).

According to OpenCV DevZone, this function did have a bug when using inplace calls, but it was fixed a few years ago.

like image 148
ibezito Avatar answered Feb 03 '26 05:02

ibezito



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!