mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 15:23: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:
@@ -159,8 +159,10 @@ static DLDataType GetDLPackType(size_t elemSize1, int depth) {
|
||||
dtype.lanes = 1;
|
||||
switch (depth)
|
||||
{
|
||||
case CV_8S: case CV_16S: case CV_32S: dtype.code = kDLInt; break;
|
||||
case CV_8U: case CV_16U: dtype.code = kDLUInt; break;
|
||||
case CV_Bool: dtype.code = kDLBool; break;
|
||||
case CV_16BF: dtype.code = kDLBfloat; break;
|
||||
case CV_8S: case CV_16S: case CV_32S: case CV_64S: dtype.code = kDLInt; break;
|
||||
case CV_8U: case CV_16U: case CV_32U: case CV_64U: dtype.code = kDLUInt; break;
|
||||
case CV_16F: case CV_32F: case CV_64F: dtype.code = kDLFloat; break;
|
||||
default:
|
||||
CV_Error(Error::StsNotImplemented, "__dlpack__ data type");
|
||||
@@ -176,6 +178,7 @@ static int DLPackTypeToCVType(const DLDataType& dtype, int channels) {
|
||||
case 8: return CV_8SC(channels);
|
||||
case 16: return CV_16SC(channels);
|
||||
case 32: return CV_32SC(channels);
|
||||
case 64: return CV_64SC(channels);
|
||||
default:
|
||||
{
|
||||
PyErr_SetString(PyExc_BufferError,
|
||||
@@ -190,6 +193,8 @@ static int DLPackTypeToCVType(const DLDataType& dtype, int channels) {
|
||||
{
|
||||
case 8: return CV_8UC(channels);
|
||||
case 16: return CV_16UC(channels);
|
||||
case 32: return CV_32UC(channels);
|
||||
case 64: return CV_64UC(channels);
|
||||
default:
|
||||
{
|
||||
PyErr_SetString(PyExc_BufferError,
|
||||
@@ -213,6 +218,14 @@ static int DLPackTypeToCVType(const DLDataType& dtype, int channels) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dtype.code == kDLBool)
|
||||
{
|
||||
return CV_BoolC(channels);
|
||||
}
|
||||
if (dtype.code == kDLBfloat)
|
||||
{
|
||||
return CV_16BFC(channels);
|
||||
}
|
||||
PyErr_SetString(PyExc_BufferError, format("Unsupported dlpack data type: %d", dtype.code).c_str());
|
||||
return -1;
|
||||
}
|
||||
@@ -227,7 +240,11 @@ static int DLPackTypeToCVType(const DLDataType& dtype, int channels) {
|
||||
{"CV_32FC", (PyCFunction)(pycvMakeTypeCh<CV_32F>), METH_O, "CV_32FC(channels) -> retval"}, \
|
||||
{"CV_64FC", (PyCFunction)(pycvMakeTypeCh<CV_64F>), METH_O, "CV_64FC(channels) -> retval"}, \
|
||||
{"CV_16FC", (PyCFunction)(pycvMakeTypeCh<CV_16F>), METH_O, "CV_16FC(channels) -> retval"}, \
|
||||
{"CV_BoolC", (PyCFunction)(pycvMakeTypeCh<CV_Bool>), METH_O, "CV_BoolC(channels) -> retval"},
|
||||
{"CV_BoolC", (PyCFunction)(pycvMakeTypeCh<CV_Bool>), METH_O, "CV_BoolC(channels) -> retval"}, \
|
||||
{"CV_32UC", (PyCFunction)(pycvMakeTypeCh<CV_32U>), METH_O, "CV_32UC(channels) -> retval"}, \
|
||||
{"CV_64UC", (PyCFunction)(pycvMakeTypeCh<CV_64U>), METH_O, "CV_64UC(channels) -> retval"}, \
|
||||
{"CV_64SC", (PyCFunction)(pycvMakeTypeCh<CV_64S>), METH_O, "CV_64SC(channels) -> retval"}, \
|
||||
{"CV_16BFC", (PyCFunction)(pycvMakeTypeCh<CV_16BF>), METH_O, "CV_16BFC(channels) -> retval"},
|
||||
|
||||
#endif // HAVE_OPENCV_CORE
|
||||
#endif // OPENCV_CORE_PYOPENCV_CORE_HPP
|
||||
|
||||
Reference in New Issue
Block a user