Ask Your Question

OpenCV 3.1 UMat assignment

asked 2016-02-17 13:39:39 -0500

I am trying to implement a performance upgrade to the project of my company. The project depends on OpenCV and recently I have successfully upgraded to OpenCV 3.1 to use UMat. Though I cant find a complete tutorial on it except basic operations. So I am stuck at the following:

   Mat m (width, height, type, someData, step);
    cv::UMat * ptr = new cv::UMat (width, height, type);
    //dont ask me why the hell we are using a pointer to the smart mat object (my project leader insists)

This doesnt work

  ptr->setTo (m);

Neither does this:


These cause an exception.


And this one results with a two dimensional mat with 0 rows and 0 cols... Also another case is:

some global cv::UMat gloMat; //initialized
cv::UMat mat;
gloMat.copyTo(mat); //doesnt work!!! same result 2 dims 0 rows 0 cols

gloMat.getMat(cv::ACCESS_READ).copyTo (mat.getMat(cv::ACCESS_WRITE)); // this doesnt work as well !!!
return mat;

Need help. Thanks in advance!!!!

edit retag flag offensive close merge delete


The following code works with me:

  cv::Mat matImg = cv::imread("img.png");

  cv::UMat *ptr_umatImg = new cv::UMat(matImg.rows, matImg.cols, matImg.type());
  std::cout << "ptr_umatImg=" << ptr_umatImg->cols << "x" << ptr_umatImg->rows << std::endl;

  cv::Mat matImg2;

  cv::imshow("matImg2", matImg2);

It should be new cv::UMat (height, width, type); (the order is rows, cols, type).

Eduardo gravatar imageEduardo ( 2016-02-18 04:10:35 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-18 04:48:30 -0500

updated 2016-02-18 04:54:56 -0500

Thanks for highlighting the error. What do you think about the case UMat * or UMat being a global variable? Also how can i access the data of a UMat? Is it supposed to be in ?

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-02-17 13:39:39 -0500

Seen: 753 times

Last updated: Feb 17 '16