Description
System information (version)
OpenCV & OpenCV Contrib 4.7.0
CUDA 11.7
Python 3.9.5
Ubuntu 20.04 x86_64
NVIDIA T4
Detailed description
When calling cv2.cuda.remap()
with a Mat that has one row, an output of all 0s is produced (sometimes there are negligible floating points values) or the destination Mat is not overwritten. When doing the similar cpu operation in cv2.remap()
, the correct output is produced. An example of this use case is using remap as lookup table for larger tables or floating point values.
Changing the src size to at least two rows produces the correct result.
Changing the src size to one column crashes with following error message: cv2.error: OpenCV(4.7.0) /home/ubuntu/opencv_contrib-4.7.0/modules/cudev/include/opencv2/cudev/ptr2d/texture.hpp:167: error: (-217:Gpu API call) invalid argument in function 'create'
. Similarly changing to 2 columns produced correct result.
This was tested across several combinations of borderMode, interpolation, and channel number and all reproduced the same behavior.
This case had previously worked in OpenCV 4.5.5 before I updated to 4.7.0. Tested only in Python.
Steps to reproduce
Some toy code to reproduce the problem
# wrong result
test_src, test_x, test_y, test_dst = cv2.cuda_GpuMat(1, 32766, cv2.CV_32FC2), cv2.cuda_GpuMat(100, 100, cv2.CV_32FC1), cv2.cuda_GpuMat(100, 100, cv2.CV_32FC1), cv2.cuda_GpuMat(100, 100, cv2.CV_32FC2)
test_src.upload(np.ones((1, 32766), dtype=np.float32) * 13.3)
test_x.upload(np.ones((100, 100), dtype=np.float32) * np.pi)
test_y.upload(np.zeros((100, 100), dtype=np.float32))
cv2.cuda.remap(test_src, test_x, test_y, cv2.INTER_NEAREST, dst=test_dst, borderMode=cv2.BORDER_REPLICATE)
test_out = np.zeros((100, 100), dtype=np.float32) + 42
test_dst.download(dst=test_out)
print(test_out)
# correct result
cv2.remap(np.ones((1, 32766), dtype=np.float32) * 13.3, np.ones((100, 100), dtype=np.float32) * np.pi, np.zeros((100, 100), dtype=np.float32), cv2.INTER_NEAREST, dst=test_out, borderMode=cv2.BORDER_REPLICATE)
print(test_out)
# correct result
test_src, test_x, test_y, test_dst = cv2.cuda_GpuMat(2, 32766, cv2.CV_32FC2), cv2.cuda_GpuMat(100, 100, cv2.CV_32FC1), cv2.cuda_GpuMat(100, 100, cv2.CV_32FC1), cv2.cuda_GpuMat(100, 100, cv2.CV_32FC2)
test_src.upload(np.ones((2, 32766), dtype=np.float32) * 13.3)
test_x.upload(np.ones((100, 100), dtype=np.float32) * np.pi)
test_y.upload(np.zeros((100, 100), dtype=np.float32))
cv2.cuda.remap(test_src, test_x, test_y, cv2.INTER_NEAREST, dst=test_dst, borderMode=cv2.BORDER_REPLICATE)
test_out = np.zeros((100, 100), dtype=np.float32) + 42
test_dst.download(dst=test_out)
print(test_out)
Issue submission checklist
- [ x ] I report the issue, it's not a question
- [ x ] I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found any solution - [ x ] I updated to the latest OpenCV version and the issue is still there
- [ x ] There is reproducer code and related data files: videos, images, onnx, etc