# Operators for cv::UMat

I noticed that there are some code incompatibilities between cv::Mat and cv::UMat -- right now I'm stuck with some missing operators. I found functions for element-wise operations with other matrices, but what is the best way to e.g. just scale the values of a UMat by a float/double or to add a fixed value to all elements?

edit retag close merge delete

Sort by ยป oldest newest most voted

sadly, there are no overloaded +-*/ operators for UMat available.

you'll have to use equivalent functions, like multiply(), scaleAdd() , etc.

more

1

Yes but I have got strange result with Mat or UMat :

    Mat x(1, 2, CV_8UC1, Scalar::all(3)),y;
cout<<x<<"\n";
cout << x << "\n";
multiply(x, 2.1, y, 1, CV_32F);
cout << y << "\n";
multiply(x, 2.1, x, 1, CV_32F);
cout << x << "\n";

[  3,   3]
[  5,   5]     -> 3+2=5 Yes
[10.5, 10.5] -> 5*2.1 = 10.5 Yes
[430.5, 430.5] -> 5* 2.1 = ?


with UMat it is

[  3,   3]
[  5,   5] Yes
[10.5, 10.5]  Yes
[3.7807033e-42, 0] ?


I should be tired

( 2017-03-14 11:38:33 -0500 )edit
1

Maybe multiply cannot work with inplace input / output variable?

multiply(x, 2.1, **x**, 1, CV_32F);

( 2017-03-14 11:48:33 -0500 )edit
1

I 'm agree but it should be in doc. But multiply(x, 2.1, x); is good so...and multiply(x, x, x); too but not multiply(x, x, x,1,CV_32FC1); Problem is with type conversion?

( 2017-03-14 11:54:45 -0500 )edit
1

Maybe when dst is created with the wanted ouput type, it (x) is only garbage as there should be no recopy if inplace operation was not expected? Corresponding source code is here.

( 2017-03-14 12:59:34 -0500 )edit
( 2017-03-14 13:16:11 -0500 )edit

Thanks for your input. I get correct results using the following: x = x.mul( 2.1 );, I don't know however if this adds overhead. Is there extra copying taking place due to the assignement operator?

( 2017-03-15 05:56:25 -0500 )edit

Official site

GitHub

Wiki

Documentation