1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-29 23:33:05 +04:00

Merge pull request #27779 from dkurt:dlpack_5.x_types

Add 5.x types for DLPack. Keep uint32/int64/uint64 data type for conversion to Numpy. More types support for GpuMat::convertTo #27779

### Pull Request Readiness Checklist

**Merge with contrib**: https://github.com/opencv/opencv_contrib/pull/4000

related: https://github.com/opencv/opencv/pull/27581

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Dmitry Kurtaev
2025-09-25 10:14:46 +03:00
committed by GitHub
parent 9d232fe7f2
commit 4159c0ad98
7 changed files with 144 additions and 24 deletions
+13 -1
View File
@@ -146,13 +146,25 @@ class cuda_test(NewOpenCVTests):
self.assertEqual(True, hasattr(cv.cuda, 'nonLocalMeans'))
def test_dlpack_GpuMat(self):
for dtype in [np.int8, np.uint8, np.int16, np.uint16, np.float16, np.int32, np.float32, np.float64]:
for dtype in [np.int8, np.uint8, np.int16, np.uint16, np.float16, np.int32, np.float32, np.float64, np.int64, np.uint32, np.uint64, np.bool_]:
for channels in [2, 3, 5]:
ref = (np.random.random((64, 128, channels)) * 255).astype(dtype)
src = cv.cuda_GpuMat()
src.upload(ref)
# workaround int64/uint64 conversion to int32/uint32
if dtype == np.int64:
print("skip because of https://github.com/opencv/opencv/issues/27671")
continue
src = src.convertTo(cv.CV_64S)
elif dtype == np.uint64:
print("skip because of https://github.com/opencv/opencv/issues/27671")
continue
src = src.convertTo(cv.CV_64U)
dst = cv.cuda_GpuMat.from_dlpack(src)
test = dst.download()
self.assertEqual(ref.dtype, test.dtype)
equal = np.array_equal(ref, test)
if not equal:
print(f"Failed test with dtype {dtype} and {channels} channels")