Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ThinPlateSplineShapeTransformer and WarpImage with UMat cause crash

Hello,

I have been working on a project making heavy use of ThinPlateSplineShapeTransformer to warp an image (using warpImage). I was using it with the good ol' cv::Mat and all was good (except performance). So, I thought of switching everything I could to UMat, as these kinds of transformations are really fast on the GPU.

Everything worked fine except for when I actually warp the image, here is a snippet:

 void performDistortion(cv::UMat outputImg, ...) {
    cv::Ptr<cv::ThinPlateSplineShapeTransformer> mytps;
    mytps = cv::createThinPlateSplineShapeTransformer(0);
    cv::UMat resmat;

    ////////////////////
    // Part where I fill in the source/destinations pairs, good matches and all
    ////////////////////

    mytps->estimateTransformation(points_dest, points_src, good_matches);
    mytps->applyTransformation(points_src, resmat);
    mytps->warpImage(outputImg, outputImg);
}

The thing works on a computer without a dedicated GPU (just an integrated Intel HD one) but when ran on an NVIDIA GTX 980, it crashes right away.

Error:

 OpenCV Error: Assertion failed (u->refcount == 0) in cv::UMat::handle, 
 file C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\umatrix.cpp, 
 line 7 88
 C:\build\master_winpack-build-win64-vc14\opencv\modules\core\src\umatrix.cpp:788: 
 error: (-215) u->refcount == 0 in function cv::UMat::handle

What should I do to fix it?