diff --git a/modules/core/include/opencv2/core/cuda.hpp b/modules/core/include/opencv2/core/cuda.hpp index 6cd6711582..8191c00783 100644 --- a/modules/core/include/opencv2/core/cuda.hpp +++ b/modules/core/include/opencv2/core/cuda.hpp @@ -413,8 +413,9 @@ public: data, which means that no data is copied. This operation is very efficient and can be used to process external data using OpenCV functions. The external data is not automatically deallocated, so you should take care of it. - @param step Array of _size.size()-1 steps in case of a multi-dimensional array (the last step is always - set to the element size). If not specified, the matrix is assumed to be continuous. + @param step Array of _size.size() or _size.size()-1 steps in case of a multi-dimensional array + (if specified, the last step must be equal to the element size, otherwise it will be added as such). + If not specified, the matrix is assumed to be continuous. */ GpuMatND(SizeArray size, int type, void* data, StepArray step = StepArray()); diff --git a/modules/core/src/cuda_gpu_mat_nd.cpp b/modules/core/src/cuda_gpu_mat_nd.cpp index 8440f179ea..98f270d848 100644 --- a/modules/core/src/cuda_gpu_mat_nd.cpp +++ b/modules/core/src/cuda_gpu_mat_nd.cpp @@ -12,7 +12,8 @@ GpuMatND::~GpuMatND() = default; GpuMatND::GpuMatND(SizeArray _size, int _type, void* _data, StepArray _step) : flags(0), dims(0), data(static_cast(_data)), offset(0) { - CV_Assert(_step.empty() || _size.size() == _step.size() + 1); + CV_Assert(_step.empty() || _size.size() == _step.size() + 1 || + (_size.size() == _step.size() && _step.back() == (size_t)CV_ELEM_SIZE(_type))); setFields(std::move(_size), _type, std::move(_step)); } @@ -106,7 +107,8 @@ void GpuMatND::setFields(SizeArray _size, int _type, StepArray _step) else { step = std::move(_step); - step.push_back(elemSize()); + if (step.size() < size.size()) + step.push_back(elemSize()); flags = cv::updateContinuityFlag(flags, dims, size.data(), step.data()); }