UMat operators

How does one use basic matrix operators with cv::UMat, similar to those available for cv::Mat. For example using ~ for bitwise_not, or comparing 2 matrices with >.

I'm aware of getMat, but I assume that using that function would remove the advantages of using UMat.

Also are there any efficiency differences between the 2 options below?

  cv::UMat srcMat;
cv::Mat dstMat;
cv::cvtColor(srcMat, dstMat, CV_BGR2YUV);
uint8_t * data = dstMat.data;


or

  cv::UMat srcMat, dstMat;
cv::cvtColor(srcMat, dstMat, CV_BGR2YUV);

edit retag close merge delete

Sort by ยป oldest newest most voted

For the basic matrix operations, you should use the functions, such as bitwise_and, bitwise_not and so forth. The operators are not supported. There is no efficiency loss in using the functions.

As for the second question, I have no idea. You should do what I always do and try it in a loop of 1000 iterations and time it.

more

so regarding the 1st issue, I would run cv::bitwise_not(umat, umat), though I've understood its not recommended to overwrite a matrix with itself, is that incorrect? Also how would I compare 2 umat matrices, since they don't have any equivalent bitwise functions?

( 2017-01-09 23:57:05 -0500 )edit

I don't understand "Also how would I compare 2 umat matrices, since they don't have any equivalent bitwise functions?"

this code is OK

UMat x(256,256,CV_8UC1),y(256, 256, CV_8UC1);
UMat z;

bitwise_and(x,y,z);

( 2017-01-10 02:35:44 -0500 )edit

As in with cv::Mat one can do:

cv::Mat A = cv::Mat(1000, 1000, CV_8UC3), B = cv::Mat(1000, 1000, CV_8UC3);
cv::randu(A, Scalar::all(0), Scalar::all(255));
cv::randu(B, Scalar::all(0), Scalar::all(255));
cv::Mat C = A > B;


Is there any way to do the same with cv::UMat directly?

( 2017-01-10 02:47:55 -0500 )edit

yes it seems possible :

UMat ua, ub,uc;
Mat A = (Mat_<double>(3, 1) << 1, 2, 3) , B=(Mat_<double>(3, 1) << 3,2,1);
cout << A << endl << B << endl << A - B << endl;
cout << (A >B);
A.copyTo(ua);
B.copyTo(ub);
compare(ua, ub, uc, CMP_GT);

( 2017-01-10 08:17:19 -0500 )edit

haha, alright I was asking for a compare function, and there is indeed a compare function, I probably should have looked better

( 2017-01-10 08:19:55 -0500 )edit