Ask Your Question

Revision history [back]

Unexpected Results using CopyTo Rect with UMat

Hi, I am trying to use OpenCV with UMats to move some image processing to GPU and speed it up but I am getting some unexpected results.

I have changed my application to use the UMat class throughout but am getting some strange results when I do the following:

subImg.copyTo(mainImg(Rect(400, 400, 320, 180)));

(In this case mainImg is a UMat of size 1280 x 720 and subImg is a UMat of 320 x 180)

The sub image is copied in but appears in the wrong place, it is correct on the x axis but in the wrong place on the y-axis, except for a strip on the right hand side of the sub image (maybe 2 pixels wide) which appears in the correct position (e.g. the sub image is essentially split in two with a strip from the right hand side correctly placed and the rest of the image placed above it). Strangely if I change the y co-ordinate in the Rect it appears in the correct place when the given y value is below about 160.

If I copy the UMats back into Mats before performing the same operation and then back into a UMat everything works as expected:

Mat t1; Mat t2; mainImg.copyTo(t1); subImg.copyTo(t2); t2.copyTo(t1(Rect(400, 400, 320, 180))); UMat out; t2.copyTo(out);

I'm not sure if it is relevant but I am creating the UMats by first creating a standard Mat from an existing array of image data and then using copyTo to get this into a UMat. I'm not sure if this is the correct procedure but it seems to be working ok, except for this issue.

If anyone has any ideas what could be causing this that would be appreciated.

Thanks!

click to hide/show revision 2
No.2 Revision

updated 2016-11-07 04:28:44 -0600

berak gravatar image

Unexpected Results using CopyTo Rect with UMat

Hi, I am trying to use OpenCV with UMats to move some image processing to GPU and speed it up but I am getting some unexpected results.

I have changed my application to use the UMat class throughout but am getting some strange results when I do the following:

subImg.copyTo(mainImg(Rect(400, 400, 320, 180)));

180)));

(In this case mainImg is a UMat of size 1280 x 720 and subImg is a UMat of 320 x 180)

The sub image is copied in but appears in the wrong place, it is correct on the x axis but in the wrong place on the y-axis, except for a strip on the right hand side of the sub image (maybe 2 pixels wide) which appears in the correct position (e.g. the sub image is essentially split in two with a strip from the right hand side correctly placed and the rest of the image placed above it). Strangely if I change the y co-ordinate in the Rect it appears in the correct place when the given y value is below about 160.

If I copy the UMats back into Mats before performing the same operation and then back into a UMat everything works as expected:

Mat t1;
Mat t2;
mainImg.copyTo(t1);
subImg.copyTo(t2);
t2.copyTo(t1(Rect(400, 400, 320, 180)));
UMat out;
t2.copyTo(out);

t2.copyTo(out);

I'm not sure if it is relevant but I am creating the UMats by first creating a standard Mat from an existing array of image data and then using copyTo to get this into a UMat. I'm not sure if this is the correct procedure but it seems to be working ok, except for this issue.

If anyone has any ideas what could be causing this that would be appreciated.

Thanks!