Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

UMAT refcount error with setUseOpenCL(false)

Currently I'm rewritting some code from Mat to UMat that will hopefully run both with or without OpenCL depending on the OpenCL flag. Now I'm getting a refcount error I don't quite understand. It only shows up if setUseOpenCL is set to false.

(Since the images I work with are around 196Megapixel-RGB-images I do prefer avoiding deep copies as much as possible and I would like to understand why in the code below I'm not allowed to write into the orginal UMat.)

By the way: is there an easy way to simply convert any image (gray, bgr, bgra) to gray or even directly to CV_32FC1 or do I always have to manually check if the image is bgra or bgr or gray and then do a conversion?


main()
{
   ocl::setUseOpenCL(false); //myFoo() crashes only if this is set to false.
  myFoo(myimg, outImg);
}

void myFoo(InputArray img_ext, OutputArray img_Out)
{
    UMat gray; //if I use Mat instead of UMat it doesnt crash.
    img_ext.copyTo(gray); //using getUMat() also crashes.

   cvtColor(gray, gray, COLOR_BGR2GRAY); //doesn't crash

UMat gray2; 
gray.convertTo(gray2, CV_32FC1); //this doesnt crash

gray.convertTo(gray, CV_32FC1); //crashes with error message: OpenCV Error: Assertion failed (u->refcount == 0) in cv::StdMatAllocator::deallocate

UMAT refcount error with setUseOpenCL(false)

Currently I'm rewritting some code from Mat to UMat that will hopefully run both with or without OpenCL depending on the OpenCL flag. Now I'm getting a refcount error I don't quite understand. It only shows up if setUseOpenCL is set to false.

(Since the images I work with are around 196Megapixel-RGB-images I do prefer avoiding deep copies as much as possible and I would like to understand why in the code below I'm not allowed to write into the orginal UMat.)

By the way: is there an easy way to simply convert any image (gray, bgr, bgra) to gray or even directly to CV_32FC1 or do I always have to manually check if the image is bgra or bgr or gray and then do a conversion?


main()
{
   ocl::setUseOpenCL(false); //myFoo() crashes only if this is set to false.
  myFoo(myimg, outImg);
}

//in this function the line convertTo() crashes if the input UMat is the same as the output UMat and setUseOpenCL is set to false
void myFoo(InputArray img_ext, OutputArray img_Out)
{
    UMat gray; //if I use Mat instead of UMat it doesnt crash.
    img_ext.copyTo(gray); //using getUMat() also crashes.

   cvtColor(gray, gray, COLOR_BGR2GRAY); //doesn't crash

UMat gray2; 
gray.convertTo(gray2, CV_32FC1); //this doesnt crash

gray.convertTo(gray, CV_32FC1); //crashes with error message: OpenCV Error: Assertion failed (u->refcount == 0) in cv::StdMatAllocator::deallocate

UMAT refcount error with setUseOpenCL(false)

Currently I'm rewritting some code from Mat to UMat that will hopefully run both with or without OpenCL depending on the OpenCL flag. Now I'm getting a refcount error I don't quite understand. It only shows up if setUseOpenCL is set to false.

(Since the images I work with are around 196Megapixel-RGB-images I do prefer avoiding deep copies as much as possible and I would like to understand why in the code below I'm not allowed to write into the orginal UMat.)

By the way: is there an easy way to simply convert any image (gray, bgr, bgra) to gray or even directly to CV_32FC1 or do I always have to manually check if the image is bgra or bgr or gray and then do a conversion?


main()
{
   ocl::setUseOpenCL(false); //myFoo() crashes only if this is set to false.
  myFoo(myimg, outImg);
}

}

//in this function the line convertTo() crashes if the input UMat is the same as the output UMat and setUseOpenCL is set to false void myFoo(InputArray img_ext, OutputArray img_Out) { UMat gray; //if I use Mat instead of UMat it doesnt crash. img_ext.copyTo(gray); //using getUMat() also crashes. crashes.

cvtColor(gray, gray, COLOR_BGR2GRAY); //doesn't crash

crash

UMat gray2; gray.convertTo(gray2, CV_32FC1); //this doesnt crash

crash

gray.convertTo(gray, CV_32FC1); //crashes with error message: OpenCV Error: Assertion failed (u->refcount == 0) in cv::StdMatAllocator::deallocate
cv::StdMatAllocator::deallocate

UMAT refcount error with setUseOpenCL(false)

Currently I'm rewritting some code from Mat to UMat that will hopefully run both with or without OpenCL depending on the OpenCL flag. Now I'm getting a refcount error I don't quite understand. It only shows up if setUseOpenCL is set to false.

(Since the images I work with are around 196Megapixel-RGB-images I do prefer avoiding deep copies as much as possible and I would like to understand why in the code below I'm not allowed to write into the orginal UMat.)

By the way: is there an easy way to simply convert any image (gray, bgr, bgra) to gray or even directly to CV_32FC1 or do I always have to manually check if the image is bgra or bgr or gray and then do a conversion?


main()
{
   ocl::setUseOpenCL(false); //myFoo() crashes only if this is set to false.
  myFoo(myimg, outImg);
}

//in this function the line convertTo() crashes if the input UMat is the same as the output UMat and setUseOpenCL is set to false void myFoo(InputArray img_ext, OutputArray img_Out) { UMat gray; //if I use Mat instead of UMat it doesnt crash. img_ext.copyTo(gray); //using getUMat() also crashes.

cvtColor(gray, gray, COLOR_BGR2GRAY); //doesn't crash

UMat gray2; gray2; gray.convertTo(gray2, CV_32FC1); //this doesnt crash

gray.convertTo(gray, CV_32FC1); //crashes with error message: OpenCV Error: Assertion failed (u->refcount == 0) in cv::StdMatAllocator::deallocate

UMAT refcount error with setUseOpenCL(false)

Currently I'm rewritting some code from Mat to UMat that will hopefully run both with or without OpenCL depending on the OpenCL flag. Now I'm getting a refcount error I don't quite understand. It only shows up if setUseOpenCL is set to false.

(Since the images I work with are around 196Megapixel-RGB-images I do prefer avoiding deep copies as much as possible and I would like to understand why in the code below I'm not allowed to write into the orginal UMat.)

By the way: is there an easy way to simply convert any image (gray, bgr, bgra) to gray or even directly to CV_32FC1 or do I always have to manually check if the image is bgra or bgr or gray and then do a conversion?


main()
{
   ocl::setUseOpenCL(false); //myFoo() crashes only if this is set to false.
  myFoo(myimg, outImg);
}

//in this function the line convertTo() crashes if the input UMat is the same as the output UMat and setUseOpenCL is set to false void myFoo(InputArray img_ext, OutputArray img_Out) { UMat gray; //if I use Mat instead of UMat it doesnt crash. img_ext.copyTo(gray); //using getUMat() //I also tried using getUMat(), but in both cases convertTo() below crashes.

cvtColor(gray, gray, COLOR_BGR2GRAY); //doesn't crash

UMat gray2; gray.convertTo(gray2, CV_32FC1); //this doesnt crash

gray.convertTo(gray, CV_32FC1); //crashes with error message: OpenCV Error: Assertion failed (u->refcount == 0) in cv::StdMatAllocator::deallocate