mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Merge pull request #26333 from vpisarev:fix_26322
Fix #26322: construction of another Mat header for empty matrix #26333 The PR fixes #26322 - [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:
@@ -1372,7 +1372,8 @@ Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _st
|
||||
{
|
||||
flags |= CV_MAT_TYPE(_type);
|
||||
datastart = data = (uchar*)_data;
|
||||
setSize(*this, _dims, _sizes, _steps, true);
|
||||
if (_dims > 0 || _data != nullptr)
|
||||
setSize(*this, _dims, _sizes, _steps, true);
|
||||
finalizeHdr(*this);
|
||||
}
|
||||
|
||||
@@ -1383,7 +1384,9 @@ Mat::Mat(const std::vector<int>& _sizes, int _type, void* _data, const size_t* _
|
||||
{
|
||||
flags |= CV_MAT_TYPE(_type);
|
||||
datastart = data = (uchar*)_data;
|
||||
setSize(*this, (int)_sizes.size(), _sizes.data(), _steps, true);
|
||||
int _dims = (int)_sizes.size();
|
||||
if (_dims > 0 || _data != nullptr)
|
||||
setSize(*this, _dims, _sizes.data(), _steps, true);
|
||||
finalizeHdr(*this);
|
||||
}
|
||||
|
||||
@@ -1407,15 +1410,16 @@ Mat::Mat(std::initializer_list<int> _shape, int _type, void* _data, const size_t
|
||||
datalimit(0), allocator(0), u(0), size(&rows)
|
||||
{
|
||||
int new_shape[MatShape::MAX_DIMS];
|
||||
int new_ndims = (int)_shape.size();
|
||||
CV_Assert(new_ndims <= MatShape::MAX_DIMS);
|
||||
int _dims = (int)_shape.size();
|
||||
CV_Assert(_dims <= MatShape::MAX_DIMS);
|
||||
auto it = _shape.begin();
|
||||
for (int i = 0; i < new_ndims; i++, ++it)
|
||||
for (int i = 0; i < _dims; i++, ++it)
|
||||
new_shape[i] = *it;
|
||||
|
||||
flags |= CV_MAT_TYPE(_type);
|
||||
datastart = data = (uchar*)_data;
|
||||
setSize(*this, new_ndims, new_shape, _steps, true);
|
||||
if (_dims > 0 || _data != nullptr)
|
||||
setSize(*this, _dims, new_shape, _steps, true);
|
||||
finalizeHdr(*this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user