Ask Your Question
0

Operators for cv::UMat

asked 2017-03-14 10:56:17 -0500

iko79 gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-03-14 11:04:03 -0500

berak gravatar image

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

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

edit flag offensive delete link more

Comments

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";
    add(x, 2.0, x);
    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

LBerger gravatar imageLBerger ( 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);

Eduardo gravatar imageEduardo ( 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?

LBerger gravatar imageLBerger ( 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.

Eduardo gravatar imageEduardo ( 2017-03-14 12:59:34 -0500 )edit
LBerger gravatar imageLBerger ( 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?

iko79 gravatar imageiko79 ( 2017-03-15 05:56:25 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-03-14 10:56:17 -0500

Seen: 2,230 times

Last updated: Mar 14 '17