cuda::GpuMat::convertTo - fix for in-place arguments#17982
cuda::GpuMat::convertTo - fix for in-place arguments#17982opencv-pushbot merged 2 commits intoopencv:3.4from
Conversation
|
@nglee , could you please add a small test for this scenario or extend one of existing tests? |
|
@mshabunin There are some tests included in this PR(11ac26b). Should I add more test scenarios? |
Oh, I see now, perhaps I was reviewing only first commit. |
| cv::Mat dst_gold; | ||
| src.convertTo(dst_gold, depth2, a, b); | ||
|
|
||
| EXPECT_MAT_NEAR(dst_gold, d_srcDst, depth2 < CV_32F ? 1.0 : 1e-4); |
There was a problem hiding this comment.
Why 1.0 for integer types? Where do you have troubles with it?
There was a problem hiding this comment.
The values(1.0, 1e-4) are equal to existing non-in-place tests, which a large part of these in-place tests are copied from:
There was a problem hiding this comment.
For these tests that do not include scaling:
CUDA_TEST_P(GpuMat_ConvertTo, WithOutScaling)
CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithOutScaling)
we can set the tolerance to 0.0.
But for tests that include scaling:
CUDA_TEST_P(GpuMat_ConvertTo, WithScaling)
CUDA_TEST_P(GpuMat_ConvertTo, InplaceWithScaling)
some tests fail when tolerance is 0.0, but pass for 1.0.
I think this is acceptable since scaling includes multiplication.
|
@alalek Could you look at it? I'm not sure that convertTo is suitable for in-place processing in general case. |
|
@alalek @asmorkalov Could you review this comment: #17982 (comment) |
|
To justify why this fix is needed, other codes get the source matrix from opencv/modules/core/src/cuda/gpu_mat.cu Line 626 in 793e7c0
Even if arguments to |
Resolves #13092
If given in-place arguments to
GpuMat::convertTo,*thisanddstrefers to the same newly allocated GpuMat after these two lines:In consequence,
*thisrefers to a different GpuMat from whichsrcrefers to.Before this PR, in the following line:
the first argument derives from
*thiswhich refers to the same data asdst.So it should be fixed as the following line to make the first argument derive from
src:Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.