1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-25 13:23:02 +04:00
Files
Dmitry Kurtaev 4159c0ad98 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
2025-09-25 10:14:46 +03:00

80 lines
2.3 KiB
C++
Executable File

// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
#if defined(HAVE_CUDA)
#include "test_precomp.hpp"
#include <cuda_runtime.h>
#include "opencv2/core/cuda.hpp"
namespace opencv_test { namespace {
TEST(CUDA_Stream, construct_cudaFlags)
{
cv::cuda::Stream stream(cudaStreamNonBlocking);
EXPECT_NE(stream.cudaPtr(), nullptr);
}
typedef testing::TestWithParam< tuple<perf::MatType, perf::MatType> > GpuMat;
TEST_P(GpuMat, convertTo)
{
int sdepth = get<0>(GetParam());
int ddepth = get<1>(GetParam());
if (sdepth == CV_16F || sdepth == CV_Bool || sdepth == CV_16BF)
throw SkipTestException("Unsupported src type");
if (ddepth == CV_16F || ddepth == CV_Bool || ddepth == CV_16BF)
throw SkipTestException("Unsupported dst type");
Mat ref(16, 20, CV_8U), testMat;
randu(ref, 0, 128);
ref.convertTo(ref, sdepth);
cv::cuda::GpuMat src, dst;
src.upload(ref);
EXPECT_EQ(sdepth, src.depth());
src.convertTo(dst, ddepth);
EXPECT_EQ(ddepth, dst.depth());
dst.download(testMat);
Mat expected;
ref.convertTo(expected, ddepth);
EXPECT_EQ(ddepth, testMat.depth());
ASSERT_EQ(0, cvtest::norm(expected, testMat, NORM_INF));
}
TEST_P(GpuMat, convertToScale)
{
int sdepth = get<0>(GetParam());
int ddepth = get<1>(GetParam());
if (sdepth == CV_16F || sdepth == CV_Bool || sdepth == CV_16BF)
throw SkipTestException("Unsupported src type");
if (ddepth == CV_16F || ddepth == CV_Bool || ddepth == CV_16BF)
throw SkipTestException("Unsupported dst type");
Mat ref(16, 20, CV_8U), testMat;
randu(ref, 10, 50);
ref.convertTo(ref, sdepth);
cv::cuda::GpuMat src, dst;
src.upload(ref);
EXPECT_EQ(sdepth, src.depth());
src.convertTo(dst, ddepth, 2, -1);
EXPECT_EQ(ddepth, dst.depth());
dst.download(testMat);
Mat expected;
ref.convertTo(expected, ddepth, 2, -1);
EXPECT_EQ(ddepth, testMat.depth());
ASSERT_EQ(0, cvtest::norm(expected, testMat, NORM_INF));
}
INSTANTIATE_TEST_CASE_P(/*nothing*/, GpuMat, testing::Combine(
testing::Range(perf::MatType(CV_8U), perf::MatType(CV_DEPTH_CURR_MAX)),
testing::Range(perf::MatType(CV_8U), perf::MatType(CV_DEPTH_CURR_MAX))
));
}} // namespace
#endif