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:

m.copyTo(*ptr);

These cause an exception.

ptr=&m.getUMat(cv::ACCESS_RW);

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
function()
{
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

Comments

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());
  matImg.copyTo(*ptr_umatImg);
  std::cout << "ptr_umatImg=" << ptr_umatImg->cols << "x" << ptr_umatImg->rows << std::endl;

  cv::Mat matImg2;
  ptr_umatImg->copyTo(matImg2);

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

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

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 mat.u.data ?

dramaticlook gravatar imagedramaticlook ( 2016-02-18 04:48:30 -0500 )edit