Skip to content

Commit d77abed

Browse files
authored
Merge pull request opencv#26472 from chacha21:gpumatnd_step
More convenient GpuMatND constructor opencv#26472 Closes opencv#26471 For convenience, GpuMatND can now accept a step.size() equal to size.size(), as long as the last step is equal to elemSize() - [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 - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake
1 parent e000190 commit d77abed

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

modules/core/include/opencv2/core/cuda.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,9 @@ class CV_EXPORTS_W GpuMatND
413413
data, which means that no data is copied. This operation is very efficient and can be used to
414414
process external data using OpenCV functions. The external data is not automatically deallocated, so
415415
you should take care of it.
416-
@param step Array of _size.size()-1 steps in case of a multi-dimensional array (the last step is always
417-
set to the element size). If not specified, the matrix is assumed to be continuous.
416+
@param step Array of _size.size() or _size.size()-1 steps in case of a multi-dimensional array
417+
(if specified, the last step must be equal to the element size, otherwise it will be added as such).
418+
If not specified, the matrix is assumed to be continuous.
418419
*/
419420
GpuMatND(SizeArray size, int type, void* data, StepArray step = StepArray());
420421

modules/core/src/cuda_gpu_mat_nd.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ GpuMatND::~GpuMatND() = default;
1212
GpuMatND::GpuMatND(SizeArray _size, int _type, void* _data, StepArray _step) :
1313
flags(0), dims(0), data(static_cast<uchar*>(_data)), offset(0)
1414
{
15-
CV_Assert(_step.empty() || _size.size() == _step.size() + 1);
15+
CV_Assert(_step.empty() || _size.size() == _step.size() + 1 ||
16+
(_size.size() == _step.size() && _step.back() == (size_t)CV_ELEM_SIZE(_type)));
1617

1718
setFields(std::move(_size), _type, std::move(_step));
1819
}
@@ -106,7 +107,8 @@ void GpuMatND::setFields(SizeArray _size, int _type, StepArray _step)
106107
else
107108
{
108109
step = std::move(_step);
109-
step.push_back(elemSize());
110+
if (step.size() < size.size())
111+
step.push_back(elemSize());
110112

111113
flags = cv::updateContinuityFlag(flags, dims, size.data(), step.data());
112114
}

0 commit comments

Comments
 (0)