mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +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:
@@ -550,7 +550,7 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, Stream& stream) co
|
||||
return;
|
||||
}
|
||||
|
||||
CV_Assert( sdepth <= CV_64F && ddepth <= CV_64F );
|
||||
CV_Assert(sdepth < CV_DEPTH_CURR_MAX && ddepth < CV_DEPTH_CURR_MAX);
|
||||
|
||||
GpuMat src = *this;
|
||||
|
||||
@@ -558,15 +558,21 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, Stream& stream) co
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
typedef void (*func_t)(const GpuMat& src, const GpuMat& dst, Stream& stream);
|
||||
static const func_t funcs[7][7] =
|
||||
static const func_t funcs[CV_DEPTH_CURR_MAX][CV_DEPTH_CURR_MAX] =
|
||||
{
|
||||
{0, convertToNoScale<uchar, schar>, convertToNoScale<uchar, ushort>, convertToNoScale<uchar, short>, convertToNoScale<uchar, int>, convertToNoScale<uchar, float>, convertToNoScale<uchar, double>},
|
||||
{convertToNoScale<schar, uchar>, 0, convertToNoScale<schar, ushort>, convertToNoScale<schar, short>, convertToNoScale<schar, int>, convertToNoScale<schar, float>, convertToNoScale<schar, double>},
|
||||
{convertToNoScale<ushort, uchar>, convertToNoScale<ushort, schar>, 0, convertToNoScale<ushort, short>, convertToNoScale<ushort, int>, convertToNoScale<ushort, float>, convertToNoScale<ushort, double>},
|
||||
{convertToNoScale<short, uchar>, convertToNoScale<short, schar>, convertToNoScale<short, ushort>, 0, convertToNoScale<short, int>, convertToNoScale<short, float>, convertToNoScale<short, double>},
|
||||
{convertToNoScale<int, uchar>, convertToNoScale<int, schar>, convertToNoScale<int, ushort>, convertToNoScale<int, short>, 0, convertToNoScale<int, float>, convertToNoScale<int, double>},
|
||||
{convertToNoScale<float, uchar>, convertToNoScale<float, schar>, convertToNoScale<float, ushort>, convertToNoScale<float, short>, convertToNoScale<float, int>, 0, convertToNoScale<float, double>},
|
||||
{convertToNoScale<double, uchar>, convertToNoScale<double, schar>, convertToNoScale<double, ushort>, convertToNoScale<double, short>, convertToNoScale<double, int>, convertToNoScale<double, float>, 0}
|
||||
{0, convertToNoScale<uchar, schar>, convertToNoScale<uchar, ushort>, convertToNoScale<uchar, short>, convertToNoScale<uchar, int>, convertToNoScale<uchar, float>, convertToNoScale<uchar, double>, 0, 0, 0, convertToNoScale<uchar, uint64_t>, convertToNoScale<uchar, int64_t>, convertToNoScale<uchar, uint32_t>},
|
||||
{convertToNoScale<schar, uchar>, 0, convertToNoScale<schar, ushort>, convertToNoScale<schar, short>, convertToNoScale<schar, int>, convertToNoScale<schar, float>, convertToNoScale<schar, double>, 0, 0, 0, convertToNoScale<schar, uint64_t>, convertToNoScale<schar, int64_t>, convertToNoScale<schar, uint32_t>},
|
||||
{convertToNoScale<ushort, uchar>, convertToNoScale<ushort, schar>, 0, convertToNoScale<ushort, short>, convertToNoScale<ushort, int>, convertToNoScale<ushort, float>, convertToNoScale<ushort, double>, 0, 0, 0, convertToNoScale<ushort, uint64_t>, convertToNoScale<ushort, int64_t>, convertToNoScale<ushort, uint32_t>},
|
||||
{convertToNoScale<short, uchar>, convertToNoScale<short, schar>, convertToNoScale<short, ushort>, 0, convertToNoScale<short, int>, convertToNoScale<short, float>, convertToNoScale<short, double>, 0, 0, 0, convertToNoScale<short, uint64_t>, convertToNoScale<short, int64_t>, convertToNoScale<short, uint32_t>},
|
||||
{convertToNoScale<int, uchar>, convertToNoScale<int, schar>, convertToNoScale<int, ushort>, convertToNoScale<int, short>, 0, convertToNoScale<int, float>, convertToNoScale<int, double>, 0, 0, 0, convertToNoScale<int, uint64_t>, convertToNoScale<int, int64_t>, convertToNoScale<int, uint32_t>},
|
||||
{convertToNoScale<float, uchar>, convertToNoScale<float, schar>, convertToNoScale<float, ushort>, convertToNoScale<float, short>, convertToNoScale<float, int>, 0, convertToNoScale<float, double>, 0, 0, 0, convertToNoScale<float, uint64_t>, convertToNoScale<float, int64_t>, convertToNoScale<float, uint32_t>},
|
||||
{convertToNoScale<double, uchar>, convertToNoScale<double, schar>, convertToNoScale<double, ushort>, convertToNoScale<double, short>, convertToNoScale<double, int>, convertToNoScale<double, float>, 0, 0, 0, 0, convertToNoScale<double, uint64_t>, convertToNoScale<double, int64_t>, convertToNoScale<double, uint32_t>},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{convertToNoScale<uint64_t, uchar>, convertToNoScale<uint64_t, schar>, convertToNoScale<uint64_t, ushort>, convertToNoScale<uint64_t, short>, convertToNoScale<uint64_t, int>, convertToNoScale<uint64_t, float>, convertToNoScale<uint64_t, double>, 0, 0, 0, 0, convertToNoScale<uint64_t, int64_t>, convertToNoScale<uint64_t, uint32_t>},
|
||||
{convertToNoScale<int64_t, uchar>, convertToNoScale<int64_t, schar>, convertToNoScale<int64_t, ushort>, convertToNoScale<int64_t, short>, convertToNoScale<int64_t, int>, convertToNoScale<int64_t, float>, convertToNoScale<int64_t, double>, 0, 0, 0, convertToNoScale<int64_t, uint64_t>, 0, convertToNoScale<int64_t, uint32_t>},
|
||||
{convertToNoScale<uint32_t, uchar>, convertToNoScale<uint32_t, schar>, convertToNoScale<uint32_t, ushort>, convertToNoScale<uint32_t, short>, convertToNoScale<uint32_t, int>, convertToNoScale<uint32_t, float>, convertToNoScale<uint32_t, double>, 0, 0, 0, convertToNoScale<uint32_t, uint64_t>, convertToNoScale<uint32_t, int64_t>, 0},
|
||||
};
|
||||
|
||||
funcs[sdepth][ddepth](src.reshape(1), dst.reshape(1), stream);
|
||||
@@ -582,7 +588,7 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, double alpha, doub
|
||||
const int sdepth = depth();
|
||||
const int ddepth = CV_MAT_DEPTH(rtype);
|
||||
|
||||
CV_Assert(sdepth <= CV_64F && ddepth <= CV_64F);
|
||||
CV_Assert(sdepth < CV_DEPTH_CURR_MAX && ddepth < CV_DEPTH_CURR_MAX);
|
||||
|
||||
GpuMat src = *this;
|
||||
|
||||
@@ -590,15 +596,21 @@ void cv::cuda::GpuMat::convertTo(OutputArray _dst, int rtype, double alpha, doub
|
||||
GpuMat dst = _dst.getGpuMat();
|
||||
|
||||
typedef void (*func_t)(const GpuMat& src, const GpuMat& dst, double alpha, double beta, Stream& stream);
|
||||
static const func_t funcs[7][7] =
|
||||
static const func_t funcs[CV_DEPTH_CURR_MAX][CV_DEPTH_CURR_MAX] =
|
||||
{
|
||||
{convertToScale<uchar, uchar>, convertToScale<uchar, schar>, convertToScale<uchar, ushort>, convertToScale<uchar, short>, convertToScale<uchar, int>, convertToScale<uchar, float>, convertToScale<uchar, double>},
|
||||
{convertToScale<schar, uchar>, convertToScale<schar, schar>, convertToScale<schar, ushort>, convertToScale<schar, short>, convertToScale<schar, int>, convertToScale<schar, float>, convertToScale<schar, double>},
|
||||
{convertToScale<ushort, uchar>, convertToScale<ushort, schar>, convertToScale<ushort, ushort>, convertToScale<ushort, short>, convertToScale<ushort, int>, convertToScale<ushort, float>, convertToScale<ushort, double>},
|
||||
{convertToScale<short, uchar>, convertToScale<short, schar>, convertToScale<short, ushort>, convertToScale<short, short>, convertToScale<short, int>, convertToScale<short, float>, convertToScale<short, double>},
|
||||
{convertToScale<int, uchar>, convertToScale<int, schar>, convertToScale<int, ushort>, convertToScale<int, short>, convertToScale<int, int>, convertToScale<int, float>, convertToScale<int, double>},
|
||||
{convertToScale<float, uchar>, convertToScale<float, schar>, convertToScale<float, ushort>, convertToScale<float, short>, convertToScale<float, int>, convertToScale<float, float>, convertToScale<float, double>},
|
||||
{convertToScale<double, uchar>, convertToScale<double, schar>, convertToScale<double, ushort>, convertToScale<double, short>, convertToScale<double, int>, convertToScale<double, float>, convertToScale<double, double>}
|
||||
{convertToScale<uchar, uchar>, convertToScale<uchar, schar>, convertToScale<uchar, ushort>, convertToScale<uchar, short>, convertToScale<uchar, int>, convertToScale<uchar, float>, convertToScale<uchar, double>, 0, 0, 0, convertToScale<uchar, uint64_t>, convertToScale<uchar, int64_t>, convertToScale<uchar, uint32_t>},
|
||||
{convertToScale<schar, uchar>, convertToScale<schar, schar>, convertToScale<schar, ushort>, convertToScale<schar, short>, convertToScale<schar, int>, convertToScale<schar, float>, convertToScale<schar, double>, 0, 0, 0, convertToScale<schar, uint64_t>, convertToScale<schar, int64_t>, convertToScale<schar, uint32_t>},
|
||||
{convertToScale<ushort, uchar>, convertToScale<ushort, schar>, convertToScale<ushort, ushort>, convertToScale<ushort, short>, convertToScale<ushort, int>, convertToScale<ushort, float>, convertToScale<ushort, double>, 0, 0, 0, convertToScale<ushort, uint64_t>, convertToScale<ushort, int64_t>, convertToScale<ushort, uint32_t>},
|
||||
{convertToScale<short, uchar>, convertToScale<short, schar>, convertToScale<short, ushort>, convertToScale<short, short>, convertToScale<short, int>, convertToScale<short, float>, convertToScale<short, double>, 0, 0, 0, convertToScale<short, uint64_t>, convertToScale<short, int64_t>, convertToScale<short, uint32_t>},
|
||||
{convertToScale<int, uchar>, convertToScale<int, schar>, convertToScale<int, ushort>, convertToScale<int, short>, convertToScale<int, int>, convertToScale<int, float>, convertToScale<int, double>, 0, 0, 0, convertToScale<int, uint64_t>, convertToScale<int, int64_t>, convertToScale<int, uint32_t>},
|
||||
{convertToScale<float, uchar>, convertToScale<float, schar>, convertToScale<float, ushort>, convertToScale<float, short>, convertToScale<float, int>, convertToScale<float, float>, convertToScale<float, double>, 0, 0, 0, convertToScale<float, uint64_t>, convertToScale<float, int64_t>, convertToScale<float, uint32_t>},
|
||||
{convertToScale<double, uchar>, convertToScale<double, schar>, convertToScale<double, ushort>, convertToScale<double, short>, convertToScale<double, int>, convertToScale<double, float>, convertToScale<double, double>, 0, 0, 0, convertToScale<double, uint64_t>, convertToScale<double, int64_t>, convertToScale<double, uint32_t>},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
{convertToScale<uint64_t, uchar>, convertToScale<uint64_t, schar>, convertToScale<uint64_t, ushort>, convertToScale<uint64_t, short>, convertToScale<uint64_t, int>, convertToScale<uint64_t, float>, convertToScale<uint64_t, double>, 0, 0, 0, convertToScale<uint64_t, uint64_t>, convertToScale<uint64_t, int64_t>, convertToScale<uint64_t, uint32_t>},
|
||||
{convertToScale<int64_t, uchar>, convertToScale<int64_t, schar>, convertToScale<int64_t, ushort>, convertToScale<int64_t, short>, convertToScale<int64_t, int>, convertToScale<int64_t, float>, convertToScale<int64_t, double>, 0, 0, 0, convertToScale<int64_t, uint64_t>, convertToScale<int64_t, int64_t>, convertToScale<int64_t, uint32_t>},
|
||||
{convertToScale<uint32_t, uchar>, convertToScale<uint32_t, schar>, convertToScale<uint32_t, ushort>, convertToScale<uint32_t, short>, convertToScale<uint32_t, int>, convertToScale<uint32_t, float>, convertToScale<uint32_t, double>, 0, 0, 0, convertToScale<uint32_t, uint64_t>, convertToScale<uint32_t, int64_t>, convertToScale<uint32_t, uint32_t>},
|
||||
};
|
||||
|
||||
func_t func = funcs[sdepth][ddepth];
|
||||
|
||||
Reference in New Issue
Block a user