diff --git a/modules/core/include/opencv2/core/cuda.inl.hpp b/modules/core/include/opencv2/core/cuda.inl.hpp index 9390b3a529..237ef21052 100644 --- a/modules/core/include/opencv2/core/cuda.inl.hpp +++ b/modules/core/include/opencv2/core/cuda.inl.hpp @@ -751,7 +751,7 @@ namespace cv { inline Mat::Mat(const cuda::GpuMat& m) - : flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows) + : flags(0), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), datalimit(0), allocator(0), u(0) { m.download(*this); } diff --git a/modules/core/include/opencv2/core/cvstd.inl.hpp b/modules/core/include/opencv2/core/cvstd.inl.hpp index 37ad1e6906..9ea39ecd11 100644 --- a/modules/core/include/opencv2/core/cvstd.inl.hpp +++ b/modules/core/include/opencv2/core/cvstd.inl.hpp @@ -169,16 +169,22 @@ std::ostream& operator << (std::ostream& out, const Rect_<_Tp>& rect) return out << "[" << rect.width << " x " << rect.height << " from (" << rect.x << ", " << rect.y << ")]"; } -static inline std::ostream& operator << (std::ostream& out, const MatSize& msize) +static inline std::ostream& operator << (std::ostream& strm, const MatShape& shape) { - int i, dims = msize.dims(); - for( i = 0; i < dims; i++ ) - { - out << msize[i]; - if( i < dims-1 ) - out << " x "; + strm << '['; + if (shape.empty()) { + strm << ""; + } else { + size_t n = shape.size(); + if (n == 0) { + strm << ""; + } else { + for(size_t i = 0; i < n; ++i) + strm << (i > 0 ? " x " : "") << shape[i]; + } } - return out; + strm << "]"; + return strm; } static inline std::ostream &operator<< (std::ostream &s, cv::Range &r) diff --git a/modules/core/include/opencv2/core/mat.hpp b/modules/core/include/opencv2/core/mat.hpp index e9f78cfe9c..b40ec9689c 100644 --- a/modules/core/include/opencv2/core/mat.hpp +++ b/modules/core/include/opencv2/core/mat.hpp @@ -148,8 +148,9 @@ struct CV_EXPORTS_W_SIMPLE MatShape const int& back() const; void push_back(int value); void emplace_back(int value); - int& operator [](size_t idx); const int& operator [](size_t idx) const; + int& operator [](size_t idx); + Size operator()() const; // for compatibility with MatSize CV_WRAP bool hasSymbols() const; // negative elements in the shape may denote 'symbols' instead of actual values. @@ -162,7 +163,7 @@ struct CV_EXPORTS_W_SIMPLE MatShape size_t total() const; // returns the total number of elements in the tensor (including padding elements, i.e. the method ignores 'C' in the case of block layout). Returns 1 for scalar tensors. Returns 0 for empty shapes. - operator std::vector() const; + std::vector vec() const; std::string str() const; int dims; @@ -723,20 +724,7 @@ struct CV_EXPORTS UMatData }; CV_ENUM_FLAGS(UMatData::MemoryFlag) - -struct CV_EXPORTS MatSize -{ - explicit MatSize(int* _p) CV_NOEXCEPT; - int dims() const CV_NOEXCEPT; - Size operator()() const; - const int& operator[](int i) const; - int& operator[](int i); - operator const int*() const CV_NOEXCEPT; // TODO OpenCV 4.0: drop this - bool operator == (const MatSize& sz) const CV_NOEXCEPT; - bool operator != (const MatSize& sz) const CV_NOEXCEPT; - - int* p; -}; +typedef MatShape MatSize; struct CV_EXPORTS MatStep { @@ -746,11 +734,9 @@ struct CV_EXPORTS MatStep size_t& operator[](int i) CV_NOEXCEPT; operator size_t() const; MatStep& operator = (size_t s); + void clear(); - size_t* p; - size_t buf[3]; -protected: - MatStep& operator = (const MatStep&); + size_t p[MatShape::MAX_DIMS]; }; /** @example samples/cpp/cout_mat.cpp @@ -1633,6 +1619,12 @@ public: */ CV_NODISCARD_STD static MatExpr zeros(int ndims, const int* sz, int type); + /** @overload + @param shape Array shape. + @param type Created matrix type. + */ + CV_NODISCARD_STD static MatExpr zeros(const MatShape& shape, int type); + /** @brief Returns an array of all 1's of the specified size and type. The method returns a Matlab-style 1's array initializer, similarly to Mat::zeros. Note that using @@ -1664,6 +1656,12 @@ public: */ CV_NODISCARD_STD static MatExpr ones(int ndims, const int* sz, int type); + /** @overload + @param shape Array shape. + @param type Created matrix type. + */ + CV_NODISCARD_STD static MatExpr ones(const MatShape& shape, int type); + /** @brief Returns an identity matrix of the specified size and type. The method returns a Matlab-style identity matrix initializer, similarly to Mat::zeros. Similarly to @@ -2745,6 +2743,8 @@ public: //! constructs n-dimensional matrix UMat(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); UMat(int ndims, const int* sizes, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(const MatShape& shape, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + UMat(const MatShape& shape, int type, const Scalar& s, UMatUsageFlags usageFlags = USAGE_DEFAULT); //! copy constructor UMat(const UMat& m); @@ -2816,9 +2816,11 @@ public: CV_NODISCARD_STD static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); CV_NODISCARD_STD static UMat zeros(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); CV_NODISCARD_STD static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat zeros(const MatShape& shape, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); CV_NODISCARD_STD static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); CV_NODISCARD_STD static UMat ones(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); CV_NODISCARD_STD static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); + CV_NODISCARD_STD static UMat ones(const MatShape& shape, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); CV_NODISCARD_STD static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); CV_NODISCARD_STD static UMat eye(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT); diff --git a/modules/core/include/opencv2/core/mat.inl.hpp b/modules/core/include/opencv2/core/mat.inl.hpp index be1e192e84..63fc211862 100644 --- a/modules/core/include/opencv2/core/mat.inl.hpp +++ b/modules/core/include/opencv2/core/mat.inl.hpp @@ -94,16 +94,24 @@ inline const int* MatShape::data() const { return p; } inline int& MatShape::operator [](size_t idx) { - CV_Assert(idx < (size_t)(dims >= 0 ? dims : 1)); + CV_Assert(idx < (size_t)(dims > 0 ? dims : 1)); return p[idx]; } inline const int& MatShape::operator [](size_t idx) const { - CV_Assert(idx < (size_t)(dims >= 0 ? dims : 1)); + CV_Assert(idx < (size_t)(dims > 0 ? dims : 1)); return p[idx]; } +inline Size MatShape::operator()() const +{ + CV_Assert(dims <= 2); + int cols = dims > 0 ? p[dims > 1] : int(dims >= 0); + int rows = dims > 1 ? p[0] : int(dims >= 0); + return Size(cols, rows); +} + template inline MatShape::MatShape(_It begin, _It end) { int buf[MAX_DIMS]; @@ -540,11 +548,10 @@ template inline Mat::Mat(const std::vector<_Tp>& vec, bool copyData) : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(1), rows(1), cols((int)vec.size()), data(0), datastart(0), dataend(0), datalimit(0), - allocator(0), u(0), size(&cols) + allocator(0), u(0), size(1) { - step.buf[1] = sizeof(_Tp); - step.buf[0] = cols*step.buf[1]; - step.p = &step.buf[1]; + size[0] = cols; + step[0] = sizeof(_Tp); if(vec.empty()) return; @@ -585,11 +592,10 @@ template inline Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(1), rows(1), cols((int)arr.size()), data(0), datastart(0), dataend(0), datalimit(0), - allocator(0), u(0), size(&cols), step(0) + allocator(0), u(0), size(1), step(0) { - step.buf[1] = sizeof(_Tp); - step.buf[0] = cols*step.buf[1]; - step.p = &step.buf[1]; + size[0] = cols; + step[0] = sizeof(_Tp); if(arr.empty()) return; @@ -605,13 +611,12 @@ Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData) template inline Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(1), rows(1), cols(n), data(0), - datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&cols), step(0) + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(1), step(0) { if( !copyData ) { - step.p = &step.buf[1]; - step.buf[1] = sizeof(_Tp); - step.buf[0] = cols*step.buf[1]; + size[0] = cols; + step[0] = sizeof(_Tp); datastart = data = (uchar*)vec.val; datalimit = dataend = datastart + cols * step[0]; } @@ -623,13 +628,14 @@ Mat::Mat(const Vec<_Tp, n>& vec, bool copyData) template inline Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(m), cols(n), data(0), - datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(2), step(0) { if( !copyData ) { - step.p = &step.buf[0]; - step.buf[1] = sizeof(_Tp); - step.buf[0] = n*sizeof(_Tp); + size[1] = cols; + size[0] = rows; + step[1] = sizeof(_Tp); + step[0] = n*sizeof(_Tp); datastart = data = (uchar*)M.val; datalimit = dataend = datastart + rows * step[0]; } @@ -640,13 +646,12 @@ Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData) template inline Mat::Mat(const Point_<_Tp>& pt, bool copyData) : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(1), rows(1), cols(2), data(0), - datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&cols), step(0) + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(1), step(0) { if( !copyData ) { - step.p = &step.buf[1]; - step.buf[1] = sizeof(_Tp); - step.buf[0] = cols*step.buf[1]; + size[0] = cols; + step[0] = sizeof(_Tp); datastart = data = (uchar*)&pt.x; datalimit = dataend = datastart + cols * step[0]; } @@ -661,20 +666,20 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData) template inline Mat::Mat(const Point3_<_Tp>& pt, bool copyData) - : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(3), cols(1), data(0), - datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&rows), step(0) + : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(1), rows(1), cols(3), data(0), + datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(1), step(0) { if( !copyData ) { - step.p = &step.buf[1]; - step.buf[1] = sizeof(_Tp); - step.buf[0] = cols*step.buf[1]; + size[0] = cols; + step[0] = sizeof(_Tp); datastart = data = (uchar*)&pt.x; datalimit = dataend = datastart + cols * step[0]; } else { - create(3, 1, traits::Type<_Tp>::value); + int sz = 3; + create(1, &sz, traits::Type<_Tp>::value); ((_Tp*)data)[0] = pt.x; ((_Tp*)data)[1] = pt.y; ((_Tp*)data)[2] = pt.z; @@ -684,7 +689,7 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData) template inline Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer) : flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0), - datastart(0), dataend(0), allocator(0), u(0), size(&rows) + datastart(0), dataend(0), allocator(0), u(0) { *this = commaInitializer.operator Mat_<_Tp>(); } @@ -791,6 +796,12 @@ int Mat::channels() const return CV_MAT_CN(flags); } +inline +MatShape Mat::shape() const +{ + return size; +} + inline uchar* Mat::ptr(int y) { @@ -1093,9 +1104,9 @@ const _Tp& Mat::at(int i0) const if( isContinuous() || rows == 1 ) return ((const _Tp*)data)[i0]; if( cols == 1 ) - return *(const _Tp*)(data + step.buf[0] * i0); + return *(const _Tp*)(data + step[0] * i0); int i = i0 / cols, j = i0 - i * cols; - return ((const _Tp*)(data + step.buf[0] * i))[j]; + return ((const _Tp*)(data + step[0] * i))[j]; } template inline @@ -1287,6 +1298,10 @@ void Mat::push_back(const _Tp& elem) if( !isSubmatrix() && isContinuous() && tmp <= datalimit ) { *(_Tp*)(data + (size.p[0]++) * step.p[0]) = elem; + if (dims == 2) + rows = size.p[0]; + else if (dims == 1) + cols = size.p[0]; dataend = tmp; } else @@ -1315,6 +1330,7 @@ void Mat::push_back(const std::vector<_Tp>& v) ///////////////////////////// MatSize //////////////////////////// +/* inline MatSize::MatSize(int* _p) CV_NOEXCEPT : p(_p) {} @@ -1364,21 +1380,21 @@ bool MatSize::operator != (const MatSize& sz) const CV_NOEXCEPT { return !(*this == sz); } - - +*/ ///////////////////////////// MatStep //////////////////////////// inline MatStep::MatStep() CV_NOEXCEPT { - p = buf; p[0] = p[1] = 0; p[2] = 153; + clear(); } inline MatStep::MatStep(size_t s) CV_NOEXCEPT { - p = buf; p[0] = s; p[1] = 0; p[2] = 153; + clear(); + p[0] = s; } inline @@ -1395,18 +1411,20 @@ size_t& MatStep::operator[](int i) CV_NOEXCEPT inline MatStep::operator size_t() const { - CV_DbgAssert( p == buf || p == buf+1 ); - return *p; + return p[0]; } inline MatStep& MatStep::operator = (size_t s) { - CV_DbgAssert( p == buf || p == buf+1 ); - *p = s; + p[0] = s; return *this; } - +inline void MatStep::clear() +{ + for (int i = 0; i < MatShape::MAX_DIMS; i++) + p[i] = 0; +} ////////////////////////////// Mat_<_Tp> //////////////////////////// diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 2149ee46be..03f502ba48 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1623,7 +1623,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) int cn = src1.channels(); - _dst.create(src1.dims, src1.size, CV_8UC(cn)); + _dst.create(src1.size, CV_8UC(cn)); src1 = src1.reshape(1); src2 = src2.reshape(1); Mat dst = _dst.getMat().reshape(1); diff --git a/modules/core/src/convert.dispatch.cpp b/modules/core/src/convert.dispatch.cpp index c18fc2faef..16a760b1fc 100644 --- a/modules/core/src/convert.dispatch.cpp +++ b/modules/core/src/convert.dispatch.cpp @@ -164,7 +164,7 @@ void Mat::convertTo(OutputArray dst, int type_, double alpha, double beta) const bool allowTransposed = dims == 1 || dst.kind() == _InputArray::STD_VECTOR || (dst.fixedSize() && dst.dims() == 1); - dst.create( dims, size, dtype, -1, allowTransposed ); + dst.create( size, dtype, -1, allowTransposed ); Mat dstMat = dst.getMat(); if( dims <= 2 ) diff --git a/modules/core/src/convert_scale.dispatch.cpp b/modules/core/src/convert_scale.dispatch.cpp index 07edfc2637..d115dbee0e 100644 --- a/modules/core/src/convert_scale.dispatch.cpp +++ b/modules/core/src/convert_scale.dispatch.cpp @@ -94,7 +94,7 @@ void convertScaleAbs(InputArray _src, OutputArray _dst, double alpha, double bet Mat src = _src.getMat(); int cn = src.channels(); double scale[] = {alpha, beta}; - _dst.create( src.dims, src.size, CV_8UC(cn) ); + _dst.create( src.size, CV_8UC(cn) ); Mat dst = _dst.getMat(); BinaryFunc func = getCvtScaleAbsFunc(src.depth()); CV_Assert( func != 0 ); diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 957d67d0f5..de7cb6354e 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -520,7 +520,7 @@ void Mat::copyTo( OutputArray _dst ) const return; } - _dst.create( dims, size, stype ); + _dst.create( size, stype ); Mat dst = _dst.getMat(); if( data == dst.data ) return; @@ -595,7 +595,7 @@ void Mat::copyTo( OutputArray _dst, InputArray _mask ) const Mat dst; { Mat dst0 = _dst.getMat(); - _dst.create(dims, size, type()); // TODO Prohibit 'dst' re-creation, user should pass it explicitly with correct size/type or empty + _dst.create(size, type()); // TODO Prohibit 'dst' re-creation, user should pass it explicitly with correct size/type or empty dst = _dst.getMat(); if (dst.data != dst0.data) // re-allocation happened diff --git a/modules/core/src/dxt.cpp b/modules/core/src/dxt.cpp index 93392bd4bb..a4fad757a5 100644 --- a/modules/core/src/dxt.cpp +++ b/modules/core/src/dxt.cpp @@ -2389,7 +2389,7 @@ static bool ocl_dft(InputArray _src, OutputArray _dst, int flags, int nonzero_ro else { _dst.createSameSize(src, CV_MAKETYPE(depth, 1)); - output.create(src.dims, src.size, CV_MAKETYPE(depth, 2)); + output.create(src.size, CV_MAKETYPE(depth, 2)); } } diff --git a/modules/core/src/mathfuncs.cpp b/modules/core/src/mathfuncs.cpp index b2ea6aa46e..ae172b5b78 100644 --- a/modules/core/src/mathfuncs.cpp +++ b/modules/core/src/mathfuncs.cpp @@ -155,7 +155,7 @@ void magnitude( InputArray src1, InputArray src2, OutputArray dst ) ocl_math_op(src1, src2, dst, OCL_OP_MAG)) Mat X = src1.getMat(), Y = src2.getMat(); - dst.create(X.dims, X.size, X.type()); + dst.create(X.size, X.type()); Mat Mag = dst.getMat(); const Mat* arrays[] = {&X, &Y, &Mag, 0}; @@ -191,7 +191,7 @@ void phase( InputArray src1, InputArray src2, OutputArray dst, bool angleInDegre ocl_math_op(src1, src2, dst, angleInDegrees ? OCL_OP_PHASE_DEGREES : OCL_OP_PHASE_RADIANS)) Mat X = src1.getMat(), Y = src2.getMat(); - dst.create( X.dims, X.size, type ); + dst.create( X.size, type ); Mat Angle = dst.getMat(); const Mat* arrays[] = {&X, &Y, &Angle, 0}; @@ -288,8 +288,8 @@ void cartToPolar( InputArray src1, InputArray src2, Mat X = src1.getMat(), Y = src2.getMat(); int type = X.type(), depth = X.depth(), cn = X.channels(); CV_Assert( X.size == Y.size && type == Y.type() && (depth == CV_32F || depth == CV_64F)); - dst1.create( X.dims, X.size, type ); - dst2.create( X.dims, X.size, type ); + dst1.create( X.size, type ); + dst2.create( X.size, type ); Mat Mag = dst1.getMat(), Angle = dst2.getMat(); const Mat* arrays[] = {&X, &Y, &Mag, &Angle, 0}; @@ -393,8 +393,8 @@ void polarToCart( InputArray src1, InputArray src2, Mat Mag = src1.getMat(), Angle = src2.getMat(); CV_Assert( Mag.empty() || Angle.size == Mag.size); - dst1.create( Angle.dims, Angle.size, type ); - dst2.create( Angle.dims, Angle.size, type ); + dst1.create( Angle.size, type ); + dst2.create( Angle.size, type ); Mat X = dst1.getMat(), Y = dst2.getMat(); const Mat* arrays[] = {&Mag, &Angle, &X, &Y, 0}; @@ -445,7 +445,7 @@ void exp( InputArray _src, OutputArray _dst ) ocl_math_op(_src, noArray(), _dst, OCL_OP_EXP)) Mat src = _src.getMat(); - _dst.create( src.dims, src.size, type ); + _dst.create( src.size, type ); Mat dst = _dst.getMat(); const Mat* arrays[] = {&src, &dst, 0}; @@ -478,7 +478,7 @@ void log( InputArray _src, OutputArray _dst ) ocl_math_op(_src, noArray(), _dst, OCL_OP_LOG)) Mat src = _src.getMat(); - _dst.create( src.dims, src.size, type ); + _dst.create( src.size, type ); Mat dst = _dst.getMat(); const Mat* arrays[] = {&src, &dst, 0}; @@ -1032,7 +1032,7 @@ void pow( InputArray _src, double power, OutputArray _dst ) CV_OCL_RUN(useOpenCL, ocl_pow(_src, power, _dst, is_ipower, ipower)) Mat src = _src.getMat(); - _dst.create( src.dims, src.size, type ); + _dst.create( src.size, type ); Mat dst = _dst.getMat(); const Mat* arrays[] = {&src, &dst, 0}; diff --git a/modules/core/src/matmul.dispatch.cpp b/modules/core/src/matmul.dispatch.cpp index 1dfd1dd7c0..0629bc4611 100644 --- a/modules/core/src/matmul.dispatch.cpp +++ b/modules/core/src/matmul.dispatch.cpp @@ -656,7 +656,7 @@ void scaleAdd(InputArray _src1, double alpha, InputArray _src2, OutputArray _dst Mat src1 = _src1.getMat(), src2 = _src2.getMat(); CV_Assert(src1.size == src2.size); - _dst.create(src1.dims, src1.size, type); + _dst.create(src1.size, type); Mat dst = _dst.getMat(); float falpha = (float)alpha; diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 1a731eaa02..942733322f 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -191,6 +191,13 @@ size_t MatShape::total() const return result; } +std::vector MatShape::vec() const +{ + if (dims < 0) + return std::vector(1, 0); + return std::vector(p, p + dims); +} + std::string MatShape::str() const { std::stringstream sstrm; @@ -401,13 +408,6 @@ MatShape MatShape::expand(const MatShape& another) const return result; } -MatShape::operator std::vector() const -{ - if (dims < 0) - return std::vector(1, 0); - return std::vector(p, p + dims); -} - /////////////////////////// MatAllocator //////////////////////////// void MatAllocator::map(UMatData*, AccessFlag) const @@ -603,85 +603,31 @@ MatAllocator* Mat::getStdAllocator() //================================================================================================== -bool MatSize::operator==(const MatSize& sz) const CV_NOEXCEPT -{ - int d = dims(); - int dsz = sz.dims(); - if( d != dsz ) - return false; - if( d == 2 ) - return p[0] == sz.p[0] && p[1] == sz.p[1]; - - for( int i = 0; i < d; i++ ) - if( p[i] != sz.p[i] ) - return false; - return true; -} - void setSize( Mat& m, int _dims, const int* _sz, const size_t* _steps, bool autoSteps) { - CV_Assert( 0 <= _dims && _dims <= CV_MAX_DIM ); - if( m.dims != _dims ) - { - if( m.step.p != m.step.buf && m.step.p != m.step.buf+1) - { - fastFree(m.step.p); - } - m.step.p = m.step.buf; - m.size.p = &m.rows; - if( _dims > 2 ) - { - m.step.p = (size_t*)fastMalloc(_dims*sizeof(m.step.p[0]) + (_dims+1)*sizeof(m.size.p[0])); - m.size.p = (int*)(m.step.p + _dims) + 1; - m.size.p[-1] = _dims; - m.rows = m.cols = -1; - } - } + CV_Assert( 0 <= _dims && _dims <= CV_MAX_DIM && _dims <= MatShape::MAX_DIMS); m.dims = _dims; - size_t esz = CV_ELEM_SIZE(m.flags), esz1 = CV_ELEM_SIZE1(m.flags), total = esz; - if (_sz != 0) { - for( int i = _dims-1; i >= 0; i-- ) - { - int s = _sz[i]; - CV_Assert( s >= 0 ); - m.size.p[i] = s; - - if( _steps ) - { - if (i < _dims-1) - { - if (_steps[i] % esz1 != 0) - { - CV_Error_(Error::BadStep, ("Step %zu for dimension %d must be a multiple of esz1 %zu", _steps[i], i, esz1)); - } - - m.step.p[i] = _steps[i]; - } - else - { - m.step.p[i] = esz; - } - } - else if( autoSteps ) - { - m.step.p[i] = total; - uint64 total1 = (uint64)total*s; - if( (uint64)total1 != (size_t)total1 ) - CV_Error( cv::Error::StsOutOfRange, "The total matrix size does not fit to \"size_t\" type" ); - total = (size_t)total1; - } + m.size = MatShape(_dims, _sz); + m.step[std::max(_dims-1, 0)] = CV_ELEM_SIZE(m.flags); + for (int i = _dims-2; i >= 0; i--) { + size_t autostep = m.size[i+1]*m.step[i+1]; + if (_steps) { + m.step[i] = _steps[i]; + //CV_Assert(m.step[i] >= autostep); + } else if (autoSteps) { + m.step[i] = autostep; + } else { + m.step[i] = 0; } } - if( _dims < 2 ) + if( _dims <= 2 ) { - m.cols = _dims >= 1 && _sz ? _sz[0] : 1; - m.rows = 1; - m.size.p = &m.cols; - m.step.buf[0] = m.cols*esz; - m.step.buf[1] = esz; - m.step.p = &m.step.buf[1]; + m.cols = _dims == 0 ? 1 : _sz ? _sz[_dims > 1] : 0; + m.rows = _dims < 2 ? 1 : _sz ? _sz[0] : 0; + } else { + m.cols = m.rows = -1; } } @@ -743,19 +689,19 @@ void finalizeHdr(Mat& m) Mat::Mat() CV_NOEXCEPT : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) {} Mat::Mat(int _rows, int _cols, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_rows, _cols, _type); } Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_rows, _cols, _type); *this = _s; @@ -763,14 +709,14 @@ Mat::Mat(int _rows, int _cols, int _type, const Scalar& _s) Mat::Mat(Size _sz, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create( _sz.height, _sz.width, _type ); } Mat::Mat(Size _sz, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_sz.height, _sz.width, _type); *this = _s; @@ -778,14 +724,14 @@ Mat::Mat(Size _sz, int _type, const Scalar& _s) Mat::Mat(int _dims, const int* _sz, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_dims, _sz, _type); } Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_dims, _sz, _type); *this = _s; @@ -793,14 +739,14 @@ Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s) Mat::Mat(const std::vector& _sz, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_sz, _type); } Mat::Mat(const std::vector& _sz, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_sz, _type); *this = _s; @@ -808,21 +754,21 @@ Mat::Mat(const std::vector& _sz, int _type, const Scalar& _s) Mat::Mat(const MatShape& _shape, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_shape, _type); } Mat::Mat(std::initializer_list _shape, int _type) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_shape, _type); } Mat::Mat(const MatShape& _shape, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_shape, _type); *this = _s; @@ -830,7 +776,7 @@ Mat::Mat(const MatShape& _shape, int _type, const Scalar& _s) Mat::Mat(std::initializer_list _shape, int _type, const Scalar& _s) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows), step(0) + datalimit(0), allocator(0), u(0) { create(_shape, _type); *this = _s; @@ -839,29 +785,16 @@ Mat::Mat(std::initializer_list _shape, int _type, const Scalar& _s) Mat::Mat(const Mat& m) : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), - u(m.u), size(&rows), step(0) + u(m.u), size(m.size), step(m.step) { if( u ) CV_XADD(&u->refcount, 1); - if( m.dims <= 2 ) - { - int _1d = m.dims <= 1; - size.p = &rows + _1d; - step.p = &step.buf[_1d]; - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - } - else - { - dims = 0; - copySize(m); - } } Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_rows), cols(_cols), data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), - allocator(0), u(0), size(&rows) + allocator(0), u(0), size(2) { CV_Assert(total() == 0 || data != NULL); @@ -879,8 +812,10 @@ Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) CV_Error(Error::BadStep, "Step must be a multiple of esz1"); } } - step.buf[0] = _step; - step.buf[1] = esz; + size[0] = rows; + size[1] = cols; + step[0] = _step; + step[1] = esz; datalimit = datastart + _step * rows; dataend = datalimit - _step + minstep; updateContinuityFlag(); @@ -889,7 +824,7 @@ Mat::Mat(int _rows, int _cols, int _type, void* _data, size_t _step) Mat::Mat(Size _sz, int _type, void* _data, size_t _step) : flags(MAGIC_VAL + (_type & TYPE_MASK)), dims(2), rows(_sz.height), cols(_sz.width), data((uchar*)_data), datastart((uchar*)_data), dataend(0), datalimit(0), - allocator(0), u(0), size(&rows) + allocator(0), u(0), size(2) { CV_Assert(total() == 0 || data != NULL); @@ -908,6 +843,8 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step) CV_Error(Error::BadStep, "Step must be a multiple of esz1"); } } + size[0] = rows; + size[1] = cols; step[0] = _step; step[1] = esz; datalimit = datastart + _step*rows; @@ -918,13 +855,10 @@ Mat::Mat(Size _sz, int _type, void* _data, size_t _step) Mat::~Mat() { - CV_Assert(dummy == 153 && step.buf[2] == 153); release(); - if( step.p != step.buf && step.p != step.buf+1 ) - fastFree(step.p); } -Mat& Mat::operator=(const Mat& m) +Mat& Mat::operator = (const Mat& m) { if( this != &m ) { @@ -932,20 +866,11 @@ Mat& Mat::operator=(const Mat& m) CV_XADD(&m.u->refcount, 1); release(); flags = m.flags; - - if( dims <= 2 && m.dims <= 2 ) - { - int _1d = m.dims < 2; - dims = m.dims; - rows = m.rows; - cols = m.cols; - step.p = &step.buf[_1d]; - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - size.p = &rows + _1d; - } - else - copySize(m); + dims = m.dims; + rows = m.rows; + cols = m.cols; + size = m.size; + step = m.step; data = m.data; datastart = m.datastart; dataend = m.dataend; @@ -987,7 +912,8 @@ void Mat::create(Size _sz, int _type) void Mat::createSameSize(InputArray m, int type) { - _OutputArray(*this).createSameSize(m, type); + MatShape msize = m.shape(); + create(msize, type); } void Mat::fit(int _dims, const int* _sizes, int _type) @@ -1063,16 +989,9 @@ void Mat::release() datastart = dataend = datalimit = data = 0; for(int i = 0; i < dims; i++) size.p[i] = 0; -#ifdef _DEBUG flags = MAGIC_VAL; - if(step.p != step.buf && step.p != step.buf+1) - { - fastFree(step.p); - step.p = step.buf; - size.p = &rows; - } dims = rows = cols = 0; -#endif + size.clear(); } size_t Mat::step1(int i) const @@ -1105,71 +1024,31 @@ size_t Mat::total(int startDim, int endDim) const return p; } -MatShape Mat::shape() const -{ - return dims == 0 && data == 0 ? MatShape() : MatShape(dims, size.p); -} - Mat::Mat(Mat&& m) CV_NOEXCEPT : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), - u(m.u), size(&rows) + u(m.u), size(m.size), step(m.step) { - if (m.dims <= 2) // move new step/size info - { - int _1d = dims <= 1; - step.p = &step.buf[_1d]; - size.p = &rows + _1d; - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - } - else - { - CV_Assert(m.step.p != m.step.buf && m.step.p != m.step.buf+1); - step.p = m.step.p; - size.p = m.size.p; - m.step.p = m.step.buf; - m.size.p = &m.rows; - } m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.size.clear(); m.step.clear(); m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; m.allocator = NULL; m.u = NULL; } -Mat& Mat::operator=(Mat&& m) +Mat& Mat::operator = (Mat&& m) { if (this == &m) return *this; release(); flags = m.flags; dims = m.dims; rows = m.rows; cols = m.cols; data = m.data; + size = m.size; step = m.step; datastart = m.datastart; dataend = m.dataend; datalimit = m.datalimit; allocator = m.allocator; u = m.u; - if (step.p != step.buf && step.p != step.buf+1) // release self step/size - { - fastFree(step.p); - } - step.p = step.buf; - size.p = &rows; - if (m.dims <= 2) // move new step/size info - { - int _1d = dims <= 1; - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - step.p = &step.buf[_1d]; - size.p = &rows + _1d; - } - else - { - CV_Assert(m.step.p != m.step.buf && m.step.p != m.step.buf+1); - step.p = m.step.p; - size.p = m.size.p; - } - m.step.p = m.step.buf; - m.size.p = &m.rows; m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + m.size.clear(); m.step.clear(); m.data = NULL; m.datastart = NULL; m.dataend = NULL; m.datalimit = NULL; m.allocator = NULL; m.u = NULL; @@ -1218,7 +1097,7 @@ void Mat::create(int d0, const int* _sizes, int _type) a = a0; try { - u = a->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, USAGE_DEFAULT); + u = a->allocate(dims, size.p, _type, 0, step.p, ACCESS_RW /* ignored */, USAGE_DEFAULT); CV_Assert(u != 0); allocator = a; } @@ -1226,7 +1105,7 @@ void Mat::create(int d0, const int* _sizes, int _type) { if (a == a0) throw; - u = a0->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, USAGE_DEFAULT); + u = a0->allocate(dims, size.p, _type, 0, step.p, ACCESS_RW /* ignored */, USAGE_DEFAULT); CV_Assert(u != 0); allocator = a0; } @@ -1235,7 +1114,7 @@ void Mat::create(int d0, const int* _sizes, int _type) addref(); finalizeHdr(*this); - dims = d0; + size.dims = dims = d0; } void Mat::create(const std::vector& _sizes, int _type) @@ -1266,14 +1145,11 @@ void Mat::create(std::initializer_list _shape, int _type) void Mat::copySize(const Mat& m) { - setSize(*this, m.dims, 0, 0); - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - for( int i = 0; i < dims; i++ ) - { - size[i] = m.size[i]; - step[i] = m.step[i]; - } + dims = m.dims; + cols = m.cols; + rows = m.rows; + size = m.size; + step = m.step; } void Mat::deallocate() @@ -1288,17 +1164,20 @@ void Mat::deallocate() Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0) { - CV_Assert( m.dims >= 2 || (m.dims == 1 && (_rowRange == Range::all() || _rowRange == Range(0, m.rows)))); + CV_Assert(m.dims <= MatShape::MAX_DIMS); + CV_Assert(m.dims >= 2 || + (m.dims == 1 && (_rowRange == Range::all() || + _rowRange == Range(0, m.rows)))); if( m.dims > 2 ) { - AutoBuffer rs(m.dims); + Range rs[MatShape::MAX_DIMS]; rs[0] = _rowRange; rs[1] = _colRange; for( int i = 2; i < m.dims; i++ ) rs[i] = Range::all(); - *this = m(rs.data()); + *this = m(rs); return; } @@ -1309,7 +1188,7 @@ Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) { CV_Assert( 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows ); - rows = _rowRange.size(); + size[0] = rows = _rowRange.size(); data += step*_rowRange.start; flags |= SUBMATRIX_FLAG; } @@ -1318,7 +1197,7 @@ Mat::Mat(const Mat& m, const Range& _rowRange, const Range& _colRange) { CV_Assert( 0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols ); - cols = _colRange.size(); + size[dims > 1] = cols = _colRange.size(); data += _colRange.start*elemSize(); flags |= SUBMATRIX_FLAG; } @@ -1343,7 +1222,7 @@ Mat::Mat(const Mat& m, const Rect& roi) : flags(m.flags), dims(2), rows(roi.height), cols(roi.width), data(m.data + roi.y*m.step[0]), datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), - allocator(m.allocator), u(m.u), size(&rows) + allocator(m.allocator), u(m.u), size(2) { CV_Assert( m.dims <= 2 ); @@ -1354,7 +1233,10 @@ Mat::Mat(const Mat& m, const Rect& roi) if( roi.width < m.cols || roi.height < m.rows ) flags |= SUBMATRIX_FLAG; - step[0] = m.step[0]; step[1] = esz; + size[0] = rows; + size[1] = cols; + step[0] = m.step[0]; + step[1] = esz; updateContinuityFlag(); addref(); @@ -1368,7 +1250,7 @@ Mat::Mat(const Mat& m, const Rect& roi) Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _steps) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0) { flags |= CV_MAT_TYPE(_type); datastart = data = (uchar*)_data; @@ -1380,7 +1262,7 @@ Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _st Mat::Mat(const std::vector& _sizes, int _type, void* _data, const size_t* _steps) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0) { flags |= CV_MAT_TYPE(_type); datastart = data = (uchar*)_data; @@ -1392,7 +1274,7 @@ Mat::Mat(const std::vector& _sizes, int _type, void* _data, const size_t* _ Mat::Mat(const MatShape& _shape, int _type, void* _data, const size_t* _steps) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0) { flags |= CV_MAT_TYPE(_type); datastart = data = (uchar*)_data; @@ -1407,7 +1289,7 @@ Mat::Mat(const MatShape& _shape, int _type, void* _data, const size_t* _steps) Mat::Mat(std::initializer_list _shape, int _type, void* _data, const size_t* _steps) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0) { int new_shape[MatShape::MAX_DIMS]; int _dims = (int)_shape.size(); @@ -1425,7 +1307,7 @@ Mat::Mat(std::initializer_list _shape, int _type, void* _data, const size_t Mat::Mat(const Mat& m, const Range* ranges) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0) { int d = m.dims; @@ -1446,12 +1328,17 @@ Mat::Mat(const Mat& m, const Range* ranges) flags |= SUBMATRIX_FLAG; } } + + if (d <= 2) { + rows = d == 2 ? size[0] : 1; + cols = d <= 0 ? (d >= 0) : size[d > 1]; + } updateContinuityFlag(); } Mat::Mat(const Mat& m, const std::vector& ranges) : flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0), - datalimit(0), allocator(0), u(0), size(&rows) + datalimit(0), allocator(0), u(0) { int d = m.dims; @@ -1472,6 +1359,11 @@ Mat::Mat(const Mat& m, const std::vector& ranges) flags |= SUBMATRIX_FLAG; } } + + if (d <= 2) { + rows = d == 2 ? size[0] : 1; + cols = d <= 0 ? (d >= 0) : size[d > 1]; + } updateContinuityFlag(); } @@ -1511,12 +1403,17 @@ Mat Mat::diag(int d) const void Mat::pop_back(size_t nelems) { CV_Assert( nelems <= (size_t)size.p[0] ); + CV_Assert( dims >= 1 ); if( isSubmatrix() ) *this = rowRange(0, size.p[0] - (int)nelems); else { size.p[0] -= (int)nelems; + if (dims == 2) + rows = size.p[0]; + else if (dims == 1) + cols = size.p[0]; dataend -= nelems*step.p[0]; } } @@ -1531,6 +1428,10 @@ void Mat::push_back_(const void* elem) size_t esz = elemSize(); memcpy(data + r*step.p[0], elem, esz); size.p[0] = int(r + 1); + if (dims == 2) + rows = size.p[0]; + else if (dims == 1) + cols = size.p[0]; dataend += step.p[0]; uint64 tsz = size.p[0]; for( int i = 1; i < dims; i++ ) @@ -1545,23 +1446,28 @@ void Mat::reserve(size_t nelems) const size_t MIN_SIZE = 64; CV_Assert( (int)nelems >= 0 ); - if( !isSubmatrix() && data + step.p[0]*nelems <= datalimit ) + if( !isSubmatrix() && step.p[0] != 0 && data + step.p[0]*nelems <= datalimit ) return; int r = size.p[0]; - - if( (size_t)r >= nelems ) + if( (size_t)r >= nelems) return; - size.p[0] = std::max((int)nelems, 1); - size_t newsize = total()*elemSize(); + MatShape newsize = size; + size_t esz = elemSize(); + newsize.dims = std::max(newsize.dims, 1); + if (dims > 1 && r == 0 && step.p[0] == 0) { + step.p[0] = size.p[1] * (dims == 2 ? esz : step.p[1]); + } + newsize.p[0] = (int)nelems; + size_t newbytes = newsize.total() * esz; + if (newbytes < MIN_SIZE) { + newsize.p[0] = 1; + newsize.p[0] = int(MIN_SIZE / newsize.total() / esz); + } - if( newsize < MIN_SIZE ) - size.p[0] = (int)((MIN_SIZE + newsize - 1)*nelems/newsize); - - Mat m(dims, size.p, type()); - size.p[0] = r; - if( r > 0 ) + Mat m(newsize, type()); + if( r > 0) { Mat mpart = m.rowRange(0, r); copyTo(mpart); @@ -1569,6 +1475,11 @@ void Mat::reserve(size_t nelems) *this = m; size.p[0] = r; + + if (dims == 2) + rows = size.p[0]; + else if (dims == 1) + cols = size.p[0]; dataend = data + step.p[0]*r; } @@ -1602,8 +1513,8 @@ void Mat::reserveBuffer(size_t nbytes) void Mat::resize(size_t nelems) { - int saveRows = size.p[0]; - if( saveRows == (int)nelems ) + int r = size.p[0]; + if( r == (int)nelems ) return; CV_Assert( (int)nelems >= 0 ); @@ -1611,7 +1522,11 @@ void Mat::resize(size_t nelems) reserve(nelems); size.p[0] = (int)nelems; - dataend += (size.p[0] - saveRows)*step.p[0]; + if (dims == 2) + rows = size.p[0]; + else if (dims == 1) + cols = size.p[0]; + dataend += (size.p[0] - r)*(int64_t)step.p[0]; //updateContinuityFlag(*this); } @@ -1646,6 +1561,7 @@ void Mat::push_back(const Mat& elems) *this = elems.clone(); return; } + CV_Assert(dims > 0); size.p[0] = elems.size.p[0]; bool eq = size == elems.size; @@ -1654,17 +1570,28 @@ void Mat::push_back(const Mat& elems) CV_Error(cv::Error::StsUnmatchedSizes, "Pushed vector length is not equal to matrix row length"); if( type() != elems.type() ) CV_Error(cv::Error::StsUnmatchedFormats, "Pushed vector type is not the same as matrix type"); + size_t esz = elemSize(); + size_t minstep = dims <= 1 ? esz : size.p[1] * (dims == 2 ? esz : step.p[1]); + size_t step0 = step.p[0]; + if (step0 < minstep) { + if (size.p[0] <= 1) + step.p[0] = step0 = minstep; + } - if( isSubmatrix() || dataend + step.p[0]*delta > datalimit ) + if( isSubmatrix() || dataend + step0*delta > datalimit ) reserve( std::max(r + delta, (r*3+1)/2) ); size.p[0] += int(delta); - dataend += step.p[0]*delta; + if (dims == 2) + rows = size.p[0]; + else if (dims == 1) + cols = size.p[0]; + dataend += step0*delta; //updateContinuityFlag(*this); if( isContinuous() && elems.isContinuous() ) - memcpy(data + r*step.p[0], elems.data, elems.total()*elems.elemSize()); + memcpy(data + r*step0, elems.data, elems.total()*elems.elemSize()); else { Mat part = rowRange(int(r), int(r + delta)); @@ -1763,8 +1690,12 @@ Mat Mat::reshape(int new_cn, int new_rows) const CV_Error( cv::Error::StsBadArg, "The total number of matrix elements " "is not divisible by the new number of rows" ); - hdr.rows = new_rows; - hdr.step.buf[0] = total_width * elemSize1(); + hdr.size[0] = hdr.rows = new_rows; + hdr.step[0] = total_width * elemSize1(); + } else { + hdr.size[0] = hdr.rows = rows; + if (dims <= 1) + hdr.step[0] = cols * CV_ELEM_SIZE(flags); } int new_width = total_width / new_cn; @@ -1773,12 +1704,10 @@ Mat Mat::reshape(int new_cn, int new_rows) const CV_Error( cv::Error::BadNumChannels, "The total width is not divisible by the new number of channels" ); - hdr.dims = 2; - hdr.cols = new_width; + hdr.size.dims = hdr.dims = 2; + hdr.size[1] = hdr.cols = new_width; hdr.flags = (hdr.flags & ~CV_MAT_CN_MASK) | ((new_cn-1) << CV_CN_SHIFT); - hdr.step.buf[1] = CV_ELEM_SIZE(hdr.flags); - hdr.step.p = &hdr.step.buf[0]; - hdr.size.p = &hdr.rows; + hdr.step[1] = CV_ELEM_SIZE(hdr.flags); return hdr; } diff --git a/modules/core/src/matrix_expressions.cpp b/modules/core/src/matrix_expressions.cpp index f42f7bff33..ab7005de78 100644 --- a/modules/core/src/matrix_expressions.cpp +++ b/modules/core/src/matrix_expressions.cpp @@ -1679,7 +1679,7 @@ void MatOp_Initializer::assign(const MatExpr& e, Mat& m, int _type) const if( _type == -1 ) _type = e.a.type(); - m.create(e.a.dims, e.a.size, _type); + m.create(e.a.size, _type); if( e.flags == 'I' && e.a.dims <= 2 ) setIdentity(m, Scalar(e.alpha)); @@ -1767,6 +1767,15 @@ MatExpr Mat::zeros(int ndims, const int* sizes, int type) return e; } +MatExpr Mat::zeros(const MatShape& shape, int type) +{ + CV_INSTRUMENT_REGION(); + + MatExpr e; + MatOp_Initializer::makeExpr(e, '0', shape.dims, shape.p, type); + return e; +} + MatExpr Mat::ones(int rows, int cols, int type) { CV_INSTRUMENT_REGION(); @@ -1794,6 +1803,15 @@ MatExpr Mat::ones(int ndims, const int* sizes, int type) return e; } +MatExpr Mat::ones(const MatShape& shape, int type) +{ + CV_INSTRUMENT_REGION(); + + MatExpr e; + MatOp_Initializer::makeExpr(e, '1', shape.dims, shape.p, type); + return e; +} + MatExpr Mat::eye(int rows, int cols, int type) { CV_INSTRUMENT_REGION(); diff --git a/modules/core/src/matrix_iterator.cpp b/modules/core/src/matrix_iterator.cpp index 00d5164da4..f52cd55660 100644 --- a/modules/core/src/matrix_iterator.cpp +++ b/modules/core/src/matrix_iterator.cpp @@ -82,7 +82,7 @@ void NAryMatIterator::init(const Mat** _arrays, Mat* _planes, uchar** _ptrs, int if( i0 >= 0 ) { - size = arrays[i0]->size[d > 0 ? d-1 : 0]; + size = arrays[i0]->size[std::max(d-1, 0)]; for( j = d-1; j > iterdepth; j-- ) { int64 total1 = (int64)size*arrays[i0]->size[j-1]; diff --git a/modules/core/src/matrix_operations.cpp b/modules/core/src/matrix_operations.cpp index b2f4daabfd..a703bc5394 100644 --- a/modules/core/src/matrix_operations.cpp +++ b/modules/core/src/matrix_operations.cpp @@ -29,24 +29,8 @@ void cv::swap( Mat& a, Mat& b ) std::swap(a.allocator, b.allocator); std::swap(a.u, b.u); - std::swap(a.size.p, b.size.p); - std::swap(a.step.p, b.step.p); - std::swap(a.step.buf[0], b.step.buf[0]); - std::swap(a.step.buf[1], b.step.buf[1]); - - if(a.dims <= 2) - { - int a_1d = a.dims <= 1; - a.step.p = &a.step.buf[a_1d]; - a.size.p = &a.rows + a_1d; - } - - if(b.dims <= 2) - { - int b_1d = b.dims <= 1; - b.step.p = &b.step.buf[b_1d]; - b.size.p = &b.rows + b_1d; - } + std::swap(a.size, b.size); + std::swap(a.step, b.step); } diff --git a/modules/core/src/matrix_sparse.cpp b/modules/core/src/matrix_sparse.cpp index 6867e598a1..3fc2eff723 100644 --- a/modules/core/src/matrix_sparse.cpp +++ b/modules/core/src/matrix_sparse.cpp @@ -273,7 +273,7 @@ size_t SparseMat::hash(const int* idx) const SparseMat::SparseMat(const Mat& m) : flags(MAGIC_VAL), hdr(0) { - create( m.dims, m.size, m.type() ); + create( m.dims, m.size.p, m.type() ); int i, idx[CV_MAX_DIM] = {0}, d = m.dims, lastSize = m.size[d - 1]; size_t esz = m.elemSize(); diff --git a/modules/core/src/merge.dispatch.cpp b/modules/core/src/merge.dispatch.cpp index bd7a936cf9..668026ee00 100644 --- a/modules/core/src/merge.dispatch.cpp +++ b/modules/core/src/merge.dispatch.cpp @@ -136,7 +136,7 @@ void merge(const Mat* mv, size_t n, OutputArray _dst) } CV_Assert( 0 < cn && cn <= CV_CN_MAX ); - _dst.create(mv[0].dims, mv[0].size, CV_MAKETYPE(depth, cn)); + _dst.create(mv[0].size, CV_MAKETYPE(depth, cn)); Mat dst = _dst.getMat(); if( n == 1 ) diff --git a/modules/core/src/split.dispatch.cpp b/modules/core/src/split.dispatch.cpp index 42a07ed2e3..f10bcba7e0 100644 --- a/modules/core/src/split.dispatch.cpp +++ b/modules/core/src/split.dispatch.cpp @@ -132,7 +132,7 @@ void split(const Mat& src, Mat* mv) for( k = 0; k < cn; k++ ) { - mv[k].create(src.dims, src.size, depth); + mv[k].create(src.size, depth); } CV_IPP_RUN_FAST(ipp_split(src, mv, cn)); diff --git a/modules/core/src/umatrix.cpp b/modules/core/src/umatrix.cpp index eea94a2f28..7598abf647 100644 --- a/modules/core/src/umatrix.cpp +++ b/modules/core/src/umatrix.cpp @@ -260,65 +260,66 @@ UMatDataAutoLock::~UMatDataAutoLock() //////////////////////////////// UMat //////////////////////////////// UMat::UMat(UMatUsageFlags _usageFlags) CV_NOEXCEPT -: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) {} UMat::UMat(int _rows, int _cols, int _type, UMatUsageFlags _usageFlags) -: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) { create(_rows, _cols, _type); } UMat::UMat(int _rows, int _cols, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) -: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) { create(_rows, _cols, _type); *this = _s; } UMat::UMat(Size _sz, int _type, UMatUsageFlags _usageFlags) -: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) { create( _sz.height, _sz.width, _type ); } UMat::UMat(Size _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) -: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) { create(_sz.height, _sz.width, _type); *this = _s; } UMat::UMat(int _dims, const int* _sz, int _type, UMatUsageFlags _usageFlags) -: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) { create(_dims, _sz, _type); } UMat::UMat(int _dims, const int* _sz, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) -: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0), size(&rows) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) { create(_dims, _sz, _type); *this = _s; } +UMat::UMat(const MatShape& _shape, int _type, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) +{ + create(_shape.dims, _shape.p, _type); +} + +UMat::UMat(const MatShape& _shape, int _type, const Scalar& _s, UMatUsageFlags _usageFlags) +: flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(_usageFlags), u(0), offset(0) +{ + create(_shape.dims, _shape.p, _type); + *this = _s; +} + UMat::UMat(const UMat& m) : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), - usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) + usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(m.size), step(m.step) { addref(); - if( m.dims <= 2 ) - { - int _1d = dims <= 1; - step.buf[0] = m.step.buf[0]; step.buf[1] = m.step.buf[1]; - step.p = &step.buf[_1d]; - size.p = &rows + _1d; - } - else - { - dims = 0; - copySize(m); - } } UMat& UMat::operator=(const UMat& m) @@ -328,19 +329,11 @@ UMat& UMat::operator=(const UMat& m) const_cast(m).addref(); release(); flags = m.flags; - if( dims <= 2 && m.dims <= 2 ) - { - dims = m.dims; - rows = m.rows; - cols = m.cols; - int _1d = dims <= 1; - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - step.p = &step.buf[_1d]; - size.p = &rows + _1d; - } - else - copySize(m); + dims = m.dims; + rows = m.rows; + cols = m.cols; + size = m.size; + step = m.step; allocator = m.allocator; usageFlags = m.usageFlags; u = m.u; @@ -392,9 +385,9 @@ void UMat::release() { if( u && CV_XADD(&(u->urefcount), -1) == 1 ) deallocate(); - for(int i = 0; i < dims; i++) - size.p[i] = 0; u = 0; + size.clear(); + dims = cols = rows = 0; } bool UMat::empty() const @@ -414,30 +407,19 @@ size_t UMat::total() const MatShape UMat::shape() const { - return dims == 0 && u == 0 ? MatShape() : MatShape(dims, size.p); + return size; } UMat::UMat(UMat&& m) : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), allocator(m.allocator), - usageFlags(m.usageFlags), u(m.u), offset(m.offset), size(&rows) + usageFlags(m.usageFlags), u(m.u), offset(m.offset) { - if (m.dims <= 2) // move new step/size info - { - int _1d = m.dims <= 1; - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - step.p = &step.buf[_1d]; - size.p = &rows + _1d; - } - else - { - CV_DbgAssert(m.step.p != m.step.buf && m.step.p != m.step.buf+1); - step.p = m.step.p; - size.p = m.size.p; - m.step.p = m.step.buf; - m.size.p = &m.rows; - } - m.flags = MAGIC_VAL; m.dims = m.rows = m.cols = 0; + size = m.size; + step = m.step; + m.flags = MAGIC_VAL; + m.usageFlags = USAGE_DEFAULT; + m.dims = m.rows = m.cols = 0; + m.size.clear(); m.allocator = NULL; m.u = NULL; m.offset = 0; @@ -452,28 +434,8 @@ UMat& UMat::operator=(UMat&& m) allocator = m.allocator; usageFlags = m.usageFlags; u = m.u; offset = m.offset; - if (step.p != step.buf && step.p != step.buf+1) // release self step/size - { - fastFree(step.p); - } - step.p = step.buf; - size.p = &rows; - if (m.dims <= 2) // move new step/size info - { - int _1d = dims <= 1; - step.buf[0] = m.step.buf[0]; - step.buf[1] = m.step.buf[1]; - step.p = &step.buf[_1d]; - size.p = &rows + _1d; - } - else - { - CV_DbgAssert(m.step.p != m.step.buf && m.step.p != m.step.buf+1); - step.p = m.step.p; - size.p = m.size.p; - } - m.step.p = m.step.buf; - m.size.p = &m.rows; + size = m.size; + step = m.step; m.flags = MAGIC_VAL; m.usageFlags = USAGE_DEFAULT; m.dims = m.rows = m.cols = 0; @@ -503,80 +465,37 @@ void swap( UMat& a, UMat& b ) std::swap(a.u, b.u); std::swap(a.offset, b.offset); - std::swap(a.size.p, b.size.p); - std::swap(a.step.p, b.step.p); - std::swap(a.step.buf[0], b.step.buf[0]); - std::swap(a.step.buf[1], b.step.buf[1]); - - if(a.dims <= 2) - { - int a_1d = a.dims <= 1; - a.step.p = &a.step.buf[a_1d]; - a.size.p = &a.rows + a_1d; - } - - if( b.dims <= 2) - { - int b_1d = b.dims <= 1; - b.step.p = &b.step.buf[b_1d]; - b.size.p = &b.rows + b_1d; - } + std::swap(a.size, b.size); + std::swap(a.step, b.step); } void setSize( UMat& m, int _dims, const int* _sz, const size_t* _steps, bool autoSteps ) { - CV_Assert( 0 <= _dims && _dims <= CV_MAX_DIM ); - if( m.dims != _dims ) - { - if( m.step.p != m.step.buf && m.step.p != m.step.buf+1 ) - { - fastFree(m.step.p); - } - m.step.p = m.step.buf; - m.size.p = &m.rows; - if( _dims > 2 ) - { - m.step.p = (size_t*)fastMalloc(_dims*sizeof(m.step.p[0]) + (_dims+1)*sizeof(m.size.p[0])); - m.size.p = (int*)(m.step.p + _dims) + 1; - m.size.p[-1] = _dims; - m.rows = m.cols = -1; - } - } + CV_Assert( 0 <= _dims && _dims <= CV_MAX_DIM && _dims <= MatShape::MAX_DIMS); m.dims = _dims; - - size_t esz = CV_ELEM_SIZE(m.flags), total = esz; - if (_sz != 0) { - int i; - for( i = _dims-1; i >= 0; i-- ) - { - int s = _sz[i]; - CV_Assert( s >= 0 ); - m.size.p[i] = s; - - if( _steps ) - m.step.p[i] = i < _dims-1 ? _steps[i] : esz; - else if( autoSteps ) - { - m.step.p[i] = total; - int64 total1 = (int64)total*s; - if( (uint64)total1 != (size_t)total1 ) - CV_Error( cv::Error::StsOutOfRange, "The total matrix size does not fit to \"size_t\" type" ); - total = (size_t)total1; - } + m.size = MatShape(_dims, _sz); + m.step[std::max(_dims-1, 0)] = CV_ELEM_SIZE(m.flags); + for (int i = _dims-2; i >= 0; i--) { + size_t autostep = m.size[i+1]*m.step[i+1]; + if (_steps) { + m.step[i] = _steps[i]; + //CV_Assert(m.step[i] >= autostep); + } else if (autoSteps) { + m.step[i] = autostep; + } else { + m.step[i] = 0; } } - if( _dims < 2 ) + if( _dims <= 2 ) { - m.cols = _dims >= 1 && _sz ? _sz[0] : 1; - m.rows = 1; - m.size.p = &m.cols; - m.step.buf[0] = m.cols*esz; - m.step.buf[1] = esz; - m.step.p = &m.step.buf[1]; + m.cols = _dims == 0 ? 1 : _sz ? _sz[_dims > 1] : 0; + m.rows = _dims < 2 ? 1 : _sz ? _sz[0] : 0; + } else { + m.cols = m.rows = -1; } } @@ -622,11 +541,12 @@ UMat Mat::getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags) const accessFlags |= ACCESS_RW; UMatData* new_u = NULL; + MatStep new_step = step; { MatAllocator *a = allocator, *a0 = getDefaultAllocator(); if(!a) a = a0; - new_u = a->allocate(dims, size.p, type(), data, step.p, accessFlags, usageFlags); + new_u = a->allocate(dims, size.p, type(), data, new_step.p, accessFlags, usageFlags); new_u->originalUMatData = u; } bool allocated = false; @@ -658,7 +578,7 @@ UMat Mat::getUMat(AccessFlag accessFlags, UMatUsageFlags usageFlags) const { hdr.flags = flags; hdr.usageFlags = usageFlags; - setSize(hdr, dims, size.p, step.p); + setSize(hdr, dims, size.p, new_step.p); finalizeHdr(hdr); hdr.u = new_u; hdr.offset = 0; //data - datastart; @@ -733,13 +653,13 @@ void UMat::create(int d0, const int* _sizes, int _type, UMatUsageFlags _usageFla } try { - u = a->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, usageFlags); + u = a->allocate(dims, size.p, _type, 0, step.p, ACCESS_RW /* ignored */, usageFlags); CV_Assert(u != 0); } catch(...) { if(a != a0) - u = a0->allocate(dims, size, _type, 0, step.p, ACCESS_RW /* ignored */, usageFlags); + u = a0->allocate(dims, size.p, _type, 0, step.p, ACCESS_RW /* ignored */, usageFlags); CV_Assert(u != 0); } CV_Assert( step[dims-1] == (size_t)CV_ELEM_SIZE(flags) ); @@ -747,7 +667,7 @@ void UMat::create(int d0, const int* _sizes, int _type, UMatUsageFlags _usageFla finalizeHdr(*this); addref(); - dims = d0; + size.dims = dims = d0; } void UMat::create(const std::vector& _sizes, int _type, UMatUsageFlags _usageFlags) @@ -818,20 +738,16 @@ void UMat::fitSameSize(InputArray m, int _type, UMatUsageFlags _usageFlags) void UMat::copySize(const UMat& m) { - setSize(*this, m.dims, 0, 0); - for( int i = 0; i < dims; i++ ) - { - size[i] = m.size[i]; - step[i] = m.step[i]; - } + dims = m.dims; + cols = m.cols; + rows = m.rows; + size = m.size; + step = m.step; } - UMat::~UMat() { release(); - if( step.p != step.buf && step.p != step.buf+1 ) - fastFree(step.p); } void UMat::deallocate() @@ -843,33 +759,37 @@ void UMat::deallocate() UMat::UMat(const UMat& m, const Range& _rowRange, const Range& _colRange) - : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0) { - CV_Assert( m.dims >= 2 ); + CV_Assert( m.dims >= 2 && m.dims <= MatShape::MAX_DIMS ); if( m.dims > 2 ) { - AutoBuffer rs(m.dims); + Range rs[MatShape::MAX_DIMS]; rs[0] = _rowRange; rs[1] = _colRange; for( int i = 2; i < m.dims; i++ ) rs[i] = Range::all(); - *this = m(rs.data()); + *this = m(rs); return; } *this = m; if( _rowRange != Range::all() && _rowRange != Range(0,rows) ) { - CV_Assert( 0 <= _rowRange.start && _rowRange.start <= _rowRange.end && _rowRange.end <= m.rows ); - rows = _rowRange.size(); + CV_Assert( 0 <= _rowRange.start && + _rowRange.start <= _rowRange.end && + _rowRange.end <= m.rows ); + size[0] = rows = _rowRange.size(); offset += step*_rowRange.start; flags |= SUBMATRIX_FLAG; } if( _colRange != Range::all() && _colRange != Range(0,cols) ) { - CV_Assert( 0 <= _colRange.start && _colRange.start <= _colRange.end && _colRange.end <= m.cols ); - cols = _colRange.size(); + CV_Assert( 0 <= _colRange.start && + _colRange.start <= _colRange.end && + _colRange.end <= m.cols ); + size[1] = cols = _colRange.size(); offset += _colRange.start*elemSize(); flags |= SUBMATRIX_FLAG; } @@ -886,7 +806,8 @@ UMat::UMat(const UMat& m, const Range& _rowRange, const Range& _colRange) UMat::UMat(const UMat& m, const Rect& roi) : flags(m.flags), dims(2), rows(roi.height), cols(roi.width), - allocator(m.allocator), usageFlags(m.usageFlags), u(m.u), offset(m.offset + roi.y*m.step[0]), size(&rows) + allocator(m.allocator), usageFlags(m.usageFlags), u(m.u), + offset(m.offset + roi.y*m.step[0]), size(2) { CV_Assert( m.dims <= 2 ); @@ -897,7 +818,11 @@ UMat::UMat(const UMat& m, const Rect& roi) if( roi.width < m.cols || roi.height < m.rows ) flags |= SUBMATRIX_FLAG; - step[0] = m.step[0]; step[1] = esz; + size[0] = rows; + size[1] = cols; + step[0] = m.dims == 2 ? m.step[0] : cols*esz; + step[1] = esz; + updateContinuityFlag(); addref(); @@ -910,7 +835,7 @@ UMat::UMat(const UMat& m, const Rect& roi) UMat::UMat(const UMat& m, const Range* ranges) - : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0) { int i, d = m.dims; @@ -931,11 +856,16 @@ UMat::UMat(const UMat& m, const Range* ranges) flags |= SUBMATRIX_FLAG; } } + + if (d <= 2) { + rows = d == 2 ? size[0] : 1; + cols = d <= 0 ? (d >= 0) : size[d > 1]; + } updateContinuityFlag(); } UMat::UMat(const UMat& m, const std::vector& ranges) - : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0), size(&rows) + : flags(MAGIC_VAL), dims(0), rows(0), cols(0), allocator(0), usageFlags(USAGE_DEFAULT), u(0), offset(0) { int i, d = m.dims; @@ -956,6 +886,11 @@ UMat::UMat(const UMat& m, const std::vector& ranges) flags |= SUBMATRIX_FLAG; } } + + if (d <= 2) { + rows = d == 2 ? size[0] : 1; + cols = d <= 0 ? (d >= 0) : size[d > 1]; + } updateContinuityFlag(); } @@ -1069,8 +1004,12 @@ UMat UMat::reshape(int new_cn, int new_rows) const CV_Error( cv::Error::StsBadArg, "The total number of matrix elements " "is not divisible by the new number of rows" ); - hdr.rows = new_rows; - hdr.step.buf[0] = total_width * elemSize1(); + hdr.size[0] = hdr.rows = new_rows; + hdr.step[0] = total_width * elemSize1(); + } else { + hdr.size[0] = hdr.rows = rows; + if (dims <= 1) + hdr.step[0] = cols * CV_ELEM_SIZE(flags); } int new_width = total_width / new_cn; @@ -1079,12 +1018,10 @@ UMat UMat::reshape(int new_cn, int new_rows) const CV_Error( cv::Error::BadNumChannels, "The total width is not divisible by the new number of channels" ); - hdr.dims = 2; - hdr.cols = new_width; + hdr.size.dims = hdr.dims = 2; + hdr.size[1] = hdr.cols = new_width; hdr.flags = (hdr.flags & ~CV_MAT_CN_MASK) | ((new_cn-1) << CV_CN_SHIFT); - hdr.step.buf[1] = CV_ELEM_SIZE(hdr.flags); - hdr.step.p = &hdr.step.buf[0]; - hdr.size.p = &hdr.rows; + hdr.step[1] = CV_ELEM_SIZE(hdr.flags); return hdr; } @@ -1328,7 +1265,7 @@ void UMat::copyTo(OutputArray _dst, InputArray _mask) const if (ocl::useOpenCL() && _dst.isUMat() && dims <= 2) { UMatData * prevu = _dst.getUMat().u; - _dst.create( dims, size, type() ); + _dst.create( size, type() ); UMat dst = _dst.getUMat(); @@ -1453,6 +1390,11 @@ UMat UMat::zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags) return UMat(ndims, sz, type, Scalar::all(0), usageFlags); } +UMat UMat::zeros(const MatShape& shape, int type, UMatUsageFlags usageFlags) +{ + return UMat(shape.dims, shape.p, type, Scalar::all(0), usageFlags); +} + UMat UMat::ones(int rows, int cols, int type, UMatUsageFlags usageFlags) { return UMat(rows, cols, type, Scalar(1), usageFlags); @@ -1468,6 +1410,11 @@ UMat UMat::ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags) return UMat(ndims, sz, type, Scalar(1), usageFlags); } +UMat UMat::ones(const MatShape& shape, int type, UMatUsageFlags usageFlags) +{ + return UMat(shape.dims, shape.p, type, Scalar(1), usageFlags); +} + } /* End of file. */ diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index fa77547d7b..912eb3249b 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -614,7 +614,7 @@ static void inRange(const Mat& src, const Mat& lb, const Mat& rb, Mat& dst) { CV_Assert( src.type() == lb.type() && src.type() == rb.type() && src.size == lb.size && src.size == rb.size ); - dst.create( src.dims, &src.size[0], CV_8U ); + dst.create( src.size, CV_8U ); const Mat *arrays[]={&src, &lb, &rb, &dst, 0}; Mat planes[4]; @@ -678,7 +678,7 @@ static void inRange(const Mat& src, const Mat& lb, const Mat& rb, Mat& dst) static void inRangeS(const Mat& src, const Scalar& lb, const Scalar& rb, Mat& dst) { - dst.create( src.dims, &src.size[0], CV_8U ); + dst.create( src.size, CV_8U ); const Mat *arrays[]={&src, &dst, 0}; Mat planes[2]; @@ -836,7 +836,7 @@ static void finiteMask_(const _Tp *src, uchar *dst, size_t total, int cn) static void finiteMask(const Mat& src, Mat& dst) { - dst.create(src.dims, &src.size[0], CV_8UC1); + dst.create(src.size, CV_8UC1); const Mat *arrays[]={&src, &dst, 0}; Mat planes[2]; @@ -1019,7 +1019,7 @@ namespace reference { static void flip(const Mat& src, Mat& dst, int flipcode) { CV_Assert(src.dims <= 2); - dst.createSameSize(src, src.type()); + dst.create(src.size, src.type()); int i, j, k, esz = (int)src.elemSize(), width = src.cols*esz; for( i = 0; i < dst.rows; i++ ) @@ -1191,7 +1191,7 @@ struct SetZeroOp : public BaseElemWiseOp namespace reference { static void exp(const Mat& src, Mat& dst) { - dst.create( src.dims, &src.size[0], src.type() ); + dst.create( src.size, src.type() ); const Mat *arrays[]={&src, &dst, 0}; Mat planes[2]; @@ -1220,7 +1220,7 @@ static void exp(const Mat& src, Mat& dst) static void log(const Mat& src, Mat& dst) { - dst.create( src.dims, &src.size[0], src.type() ); + dst.create( src.size, src.type() ); const Mat *arrays[]={&src, &dst, 0}; Mat planes[2]; @@ -1312,8 +1312,8 @@ static void cartToPolar(const Mat& mx, const Mat& my, Mat& mmag, Mat& mangle, bo { CV_Assert( (mx.type() == CV_32F || mx.type() == CV_64F) && mx.type() == my.type() && mx.size == my.size ); - mmag.create( mx.dims, &mx.size[0], mx.type() ); - mangle.create( mx.dims, &mx.size[0], mx.type() ); + mmag.create( mx.size, mx.type() ); + mangle.create( mx.size, mx.type() ); const Mat *arrays[]={&mx, &my, &mmag, &mangle, 0}; Mat planes[4]; @@ -1380,7 +1380,7 @@ struct CartToPolarToCartOp : public BaseArithmOp Mat msrc[] = {mag, angle, x, y}; int pairs[] = {0, 0, 1, 1, 2, 2, 3, 3}; - dst.create(src[0].dims, src[0].size, CV_MAKETYPE(src[0].depth(), 4)); + dst.create(src[0].size, CV_MAKETYPE(src[0].depth(), 4)); cv::mixChannels(msrc, 4, &dst, 1, pairs, 4); } void refop(const vector& src, Mat& dst, const Mat&) @@ -1389,7 +1389,7 @@ struct CartToPolarToCartOp : public BaseArithmOp reference::cartToPolar(src[0], src[1], mag, angle, angleInDegrees); Mat msrc[] = {mag, angle, src[0], src[1]}; int pairs[] = {0, 0, 1, 1, 2, 2, 3, 3}; - dst.create(src[0].dims, src[0].size, CV_MAKETYPE(src[0].depth(), 4)); + dst.create(src[0].size, CV_MAKETYPE(src[0].depth(), 4)); cv::mixChannels(msrc, 4, &dst, 1, pairs, 4); } void generateScalars(int, RNG& rng) diff --git a/modules/core/test/test_hasnonzero.cpp b/modules/core/test/test_hasnonzero.cpp index 127ecac9df..00634b26a7 100644 --- a/modules/core/test/test_hasnonzero.cpp +++ b/modules/core/test/test_hasnonzero.cpp @@ -160,23 +160,26 @@ TEST_P(HasNonZeroNd, hasNonZeroNd) std::vector steps(ndims); std::vector sizes(ndims); size_t totalBytes = 1; - for(int dim = 0 ; dim= 0; --dim) { const bool isFirstDim = (dim == 0); const bool isLastDim = (dim+1 == ndims); const int length = rng.uniform(1, 64); - steps[dim] = (isLastDim ? 1 : static_cast(length))*CV_ELEM_SIZE(type); + steps[dim] = isLastDim ? CV_ELEM_SIZE(type) : sizes[dim+1]*steps[dim+1]; sizes[dim] = (isFirstDim || continuous) ? length : rng.uniform(1, length); - totalBytes *= steps[dim]*static_cast(sizes[dim]); + totalBytes *= steps[dim]; } + totalBytes *= sizes[0]; - std::vector buffer(totalBytes); - void* data = buffer.data(); + unsigned char magicval = 153; + size_t border = 128; + std::vector buffer(totalBytes+border*2, magicval); + void* data = buffer.data() + border; Mat m = Mat(ndims, sizes.data(), type, data, steps.data()); std::vector nzRange(ndims); - for(int dim = 0 ; dim0), hasNonZero(m)); + for (size_t j = 0; j < border; j++) { + ASSERT_EQ(buffer[j], magicval); + ASSERT_EQ(buffer[border + totalBytes + j], magicval); + } } } diff --git a/modules/core/test/test_io.cpp b/modules/core/test/test_io.cpp index 4d4437f2c3..c60626fd58 100644 --- a/modules/core/test/test_io.cpp +++ b/modules/core/test/test_io.cpp @@ -131,13 +131,13 @@ protected: static_cast(cvtest::randInt(rng)%10+1), static_cast(cvtest::randInt(rng)%10+1), }; - MatND test_mat_nd(3, sz, CV_MAKETYPE(depth, cn)); + Mat test_mat_nd(3, sz, CV_MAKETYPE(depth, cn)); rng0.fill(test_mat_nd, RNG::UNIFORM, Scalar::all(ranges[depth][0]), Scalar::all(ranges[depth][1])); if( depth >= CV_32F ) { exp(test_mat_nd, test_mat_nd); - MatND test_mat_scale(test_mat_nd.dims, test_mat_nd.size, test_mat_nd.type()); + Mat test_mat_scale(test_mat_nd.size, test_mat_nd.type()); rng0.fill(test_mat_scale, RNG::UNIFORM, Scalar::all(-1), Scalar::all(1)); cv::multiply(test_mat_nd, test_mat_scale, test_mat_nd); } @@ -148,8 +148,9 @@ protected: static_cast(cvtest::randInt(rng)%10+1), static_cast(cvtest::randInt(rng)%10+1), }; - SparseMat test_sparse_mat = cvTsGetRandomSparseMat(4, ssz, cvtest::randInt(rng)%(CV_64F+1), - cvtest::randInt(rng) % 10000, 0, 100, rng); + SparseMat test_sparse_mat = + cvTsGetRandomSparseMat(4, ssz, cvtest::randInt(rng)%(CV_64F+1), + cvtest::randInt(rng) % 10000, 0, 100, rng); fs << "test_int" << test_int << "test_real" << test_real << "test_string" << test_string; fs << "test_mat" << test_mat; diff --git a/modules/core/test/test_mat.cpp b/modules/core/test/test_mat.cpp index 286cddf808..89812139a6 100644 --- a/modules/core/test/test_mat.cpp +++ b/modules/core/test/test_mat.cpp @@ -2411,7 +2411,7 @@ TEST(Mat1D, basic) m1.at(50) = 10; EXPECT_FALSE(m1.empty()); ASSERT_EQ(1, m1.dims); - ASSERT_EQ(1, m1.size.dims()); // hack map on .rows + ASSERT_EQ(1, m1.size.dims); // hack map on .rows EXPECT_EQ(Size(100, 1), m1.size()); { @@ -2598,7 +2598,7 @@ TEST(Mat, Recreate1DMatWithSameMeta) cv::Mat m(dims, depth); // By default m has dims: [1, 100] - m.dims = 1; + m.size.dims = m.dims = 1; EXPECT_NO_THROW(m.create(dims, depth)); } diff --git a/modules/dnn/include/opencv2/dnn/shape_utils.hpp b/modules/dnn/include/opencv2/dnn/shape_utils.hpp index ec5914ce3b..9b88b07b2d 100644 --- a/modules/dnn/include/opencv2/dnn/shape_utils.hpp +++ b/modules/dnn/include/opencv2/dnn/shape_utils.hpp @@ -208,24 +208,6 @@ static inline MatShape concat(const MatShape& a, const MatShape& b) return c; } -static inline std::ostream& operator << (std::ostream& strm, const MatShape& shape) -{ - strm << '['; - if (shape.empty()) { - strm << ""; - } else { - size_t n = shape.size(); - if (n == 0) { - strm << ""; - } else { - for(size_t i = 0; i < n; ++i) - strm << (i > 0 ? " x " : "") << shape[i]; - } - } - strm << "]"; - return strm; -} - static inline std::string toString(const MatShape& shape, const String& name = "") { std::ostringstream ss; diff --git a/modules/dnn/misc/objc/gen_dict.json b/modules/dnn/misc/objc/gen_dict.json index 48c8c92f26..9e47677206 100644 --- a/modules/dnn/misc/objc/gen_dict.json +++ b/modules/dnn/misc/objc/gen_dict.json @@ -26,18 +26,18 @@ "MatShape": { "objc_type": "IntVector*", "to_cpp": "cv::MatShape(%(n)s.nativeRef)", - "from_cpp": "[IntVector fromNative:(std::vector)%(n)s]" + "from_cpp": "[IntVector fromNative:%(n)s.vec()]" }, "vector_MatShape": { "objc_type": "IntVector*", "to_cpp": "cv::MatShape(%(n)s.nativeRef)", - "from_cpp": "[IntVector fromNative:(std::vector)%(n)s]", + "from_cpp": "[IntVector fromNative:%(n)s.vec()]", "v_type": "MatShape" }, "vector_vector_MatShape": { "objc_type": "IntVector*", "to_cpp": "cv::MatShape(%(n)s.nativeRef)", - "from_cpp": "[IntVector fromNative:(std::vector)%(n)s]", + "from_cpp": "[IntVector fromNative:%(n)s.vec()]", "v_v_type": "MatShape" }, "LayerId": { diff --git a/modules/dnn/src/caffe/caffe_importer.cpp b/modules/dnn/src/caffe/caffe_importer.cpp index 46e222b922..3bd27c028a 100644 --- a/modules/dnn/src/caffe/caffe_importer.cpp +++ b/modules/dnn/src/caffe/caffe_importer.cpp @@ -271,7 +271,7 @@ public: CV_Assert(pbBlob.data_size() == (int)dstBlob.total()); CV_DbgAssert(pbBlob.GetDescriptor()->FindFieldByLowercaseName("data")->cpp_type() == FieldDescriptor::CPPTYPE_FLOAT); - Mat(dstBlob.dims, &dstBlob.size[0], CV_32F, (void*)pbBlob.data().data()).copyTo(dstBlob); + Mat(dstBlob.size, CV_32F, (void*)pbBlob.data().data()).copyTo(dstBlob); } else { diff --git a/modules/dnn/src/dnn_common.hpp b/modules/dnn/src/dnn_common.hpp index 13f124d7e3..68c35aabda 100644 --- a/modules/dnn/src/dnn_common.hpp +++ b/modules/dnn/src/dnn_common.hpp @@ -147,7 +147,9 @@ static inline std::string toString(const Mat& blob, const std::string& name = st else if (blob.dims == 1) { Mat blob_ = blob; - blob_.dims = 2; // hack + blob_.size.dims = blob_.dims = 2; // hack + blob_.size[1] = blob_.size[0]; + blob_.size[0] = 1; ss << blob_.t(); } else diff --git a/modules/dnn/src/int8layers/convolution_layer.cpp b/modules/dnn/src/int8layers/convolution_layer.cpp index aca01c3e9d..4864b06067 100644 --- a/modules/dnn/src/int8layers/convolution_layer.cpp +++ b/modules/dnn/src/int8layers/convolution_layer.cpp @@ -86,7 +86,7 @@ public: MatSize weightShape = blobs[0].size; CV_Assert(inputs[0].dims == outputs[0].dims); - if (weightShape.dims() == 3) + if (weightShape.dims == 3) { kernel_size.resize(1, kernel_size[0]); strides.resize(1, strides[0]); @@ -94,7 +94,7 @@ public: pads_begin.resize(1, pads_begin[0]); pads_end.resize(1, pads_end[0]); } - CV_Assert(weightShape.dims() == kernel_size.size() + 2); + CV_Assert(weightShape.dims == kernel_size.size() + 2); for (int i = 0; i < kernel_size.size(); i++) { CV_Assert(weightShape[i + 2] == kernel_size[i]); } diff --git a/modules/dnn/src/layer_internals.hpp b/modules/dnn/src/layer_internals.hpp index 4a3e045dd8..aecb82f538 100644 --- a/modules/dnn/src/layer_internals.hpp +++ b/modules/dnn/src/layer_internals.hpp @@ -273,7 +273,7 @@ struct DataLayer : public Layer std::vector plane(4, Range::all()); plane[0] = Range(n, n + 1); plane[1] = Range(c, c + 1); - UMat out = outputs[i](plane).reshape(1, inp.dims, inp.size); + UMat out = outputs[i](plane).reshape(1, inp.size); if (isFP16) { diff --git a/modules/dnn/src/layers/accum_layer.cpp b/modules/dnn/src/layers/accum_layer.cpp index 56124831ad..024a7071b3 100644 --- a/modules/dnn/src/layers/accum_layer.cpp +++ b/modules/dnn/src/layers/accum_layer.cpp @@ -107,7 +107,7 @@ public: const int out_h = outputs[0].size[2]; const int out_w = outputs[0].size[3]; float* out_data = outputs[0].ptr(); - std::vector sizes(&outputs[0].size[0], &outputs[0].size[0] + outputs[0].size.dims()); + std::vector sizes(&outputs[0].size[0], &outputs[0].size[0] + outputs[0].size.dims); for (int i = 0; i < inputs.size() - have_reference; i++) { sizes[1] = inputs[i].size[1]; diff --git a/modules/dnn/src/layers/bitshift_layer.cpp b/modules/dnn/src/layers/bitshift_layer.cpp index abce06627e..b935affe55 100644 --- a/modules/dnn/src/layers/bitshift_layer.cpp +++ b/modules/dnn/src/layers/bitshift_layer.cpp @@ -29,7 +29,7 @@ static inline T doShift(T inputVal, U shiftVal, int direction, int bitWidth) template void runBitShift(const Mat& input, const Mat& shift, Mat& output, int direction) { - output.create(input.dims, input.size.p, input.type()); + output.create(input.size, input.type()); const size_t numElements = input.total(); const T* inputPtr = input.ptr(); diff --git a/modules/dnn/src/layers/convolution_layer.cpp b/modules/dnn/src/layers/convolution_layer.cpp index b1e08df9f0..7984495e71 100644 --- a/modules/dnn/src/layers/convolution_layer.cpp +++ b/modules/dnn/src/layers/convolution_layer.cpp @@ -617,7 +617,7 @@ public: if (fusedWeights) { weightsMat.copyTo(weightVK); // to handle the case of isContinuous() == false - weightVK = weightVK.reshape(1, blobs[0].dims, blobs[0].size); + weightVK = weightVK.reshape(1, blobs[0].size); } else weightVK = blobs[0]; diff --git a/modules/dnn/src/layers/detection_output_layer.cpp b/modules/dnn/src/layers/detection_output_layer.cpp index c7b2272550..443fc99c47 100644 --- a/modules/dnn/src/layers/detection_output_layer.cpp +++ b/modules/dnn/src/layers/detection_output_layer.cpp @@ -252,7 +252,7 @@ public: const cv::String& code_type, const bool variance_encoded_in_target, const bool clip, std::vector& all_decode_bboxes) { - UMat outmat = UMat(loc_mat.dims, loc_mat.size, CV_32F); + UMat outmat(loc_mat.size, CV_32F); size_t nthreads = loc_mat.total(); String kernel_name; @@ -382,7 +382,7 @@ public: return true; } - UMat umat = use_half ? UMat::zeros(4, outputs[0].size, CV_32F) : outputs[0]; + UMat umat = use_half ? UMat::zeros(outputs[0].size, CV_32F) : outputs[0]; if (!use_half) umat.setTo(0); diff --git a/modules/dnn/src/layers/einsum_layer.cpp b/modules/dnn/src/layers/einsum_layer.cpp index ceb5c2d662..6c5abaeb60 100644 --- a/modules/dnn/src/layers/einsum_layer.cpp +++ b/modules/dnn/src/layers/einsum_layer.cpp @@ -532,7 +532,7 @@ public: // create temporary variable MatShape tmpResult; - for (int i = 0; i < result.size.dims(); i++) + for (int i = 0; i < result.size.dims; i++) tmpResult.emplace_back(result.size[i]); @@ -656,7 +656,7 @@ void LayerEinsumImpl::preProcessInputs(InputArrayOfArrays& inputs_arr) } if (IsTransposeRequired( - !preprocessed.empty() ? preprocessed.size.dims() : inputs[inputIter].size.dims(), + !preprocessed.empty() ? preprocessed.size.dims : inputs[inputIter].size.dims, permutation)) { // call transpose diff --git a/modules/dnn/src/layers/fully_connected_layer.cpp b/modules/dnn/src/layers/fully_connected_layer.cpp index 7b6c853e55..6818d4851c 100644 --- a/modules/dnn/src/layers/fully_connected_layer.cpp +++ b/modules/dnn/src/layers/fully_connected_layer.cpp @@ -671,7 +671,7 @@ public: CV_Assert(!weightsMat.empty()); Mat wm; weightsMat.copyTo(wm); // to handle the case of isContinuous() == false - wm = wm.reshape(1, blobs[0].dims, blobs[0].size); + wm = wm.reshape(1, blobs[0].size); vkBlobs.push_back(wm.t()); Ptr inputWrap = inputs[0].dynamicCast(); diff --git a/modules/dnn/src/layers/is_inf_layer.cpp b/modules/dnn/src/layers/is_inf_layer.cpp index 55798eb2e8..83d79a345e 100644 --- a/modules/dnn/src/layers/is_inf_layer.cpp +++ b/modules/dnn/src/layers/is_inf_layer.cpp @@ -101,7 +101,7 @@ public: const int defaultOutType = CV_BoolC1; const int outType = Y.empty() ? defaultOutType : Y.type(); - Y.create(X.dims, X.size.p, outType); + Y.create(X.size, outType); const int depth = CV_MAT_DEPTH(X.type()); const size_t total = X.total(); diff --git a/modules/dnn/src/layers/is_nan_layer.cpp b/modules/dnn/src/layers/is_nan_layer.cpp index 8361c0d454..945103a8c6 100644 --- a/modules/dnn/src/layers/is_nan_layer.cpp +++ b/modules/dnn/src/layers/is_nan_layer.cpp @@ -70,7 +70,7 @@ public: const int defaultOutType = CV_BoolC1; const int outType = (Y.empty() || Y.type() < 0) ? defaultOutType : Y.type(); - Y.create(X.dims, X.size.p, outType); + Y.create(X.size, outType); const int depth = CV_MAT_DEPTH(X.type()); const size_t total = X.total(); diff --git a/modules/dnn/src/layers/recurrent2_layers.cpp b/modules/dnn/src/layers/recurrent2_layers.cpp index bdfbbef1a8..f981aceb82 100644 --- a/modules/dnn/src/layers/recurrent2_layers.cpp +++ b/modules/dnn/src/layers/recurrent2_layers.cpp @@ -26,7 +26,7 @@ static void tanh(const Mat &src, Mat &dst) static void tanh(const Mat &src, Mat &dst) { - dst.create(src.dims, (const int*)src.size, src.type()); + dst.create(src.size, src.type()); if (src.type() == CV_32F) tanh(src, dst); else if (src.type() == CV_64F) diff --git a/modules/dnn/src/layers/recurrent_layers.cpp b/modules/dnn/src/layers/recurrent_layers.cpp index ad45a8a2a9..e3c3d54d9b 100644 --- a/modules/dnn/src/layers/recurrent_layers.cpp +++ b/modules/dnn/src/layers/recurrent_layers.cpp @@ -70,7 +70,7 @@ static void tanh(const Mat &src, Mat &dst) //TODO: make utils method static void tanh(const Mat &src, Mat &dst) { - dst.create(src.dims, (const int*)src.size, src.type()); + dst.create(src.size, src.type()); if (src.type() == CV_32F) tanh(src, dst); diff --git a/modules/dnn/src/layers/region_layer.cpp b/modules/dnn/src/layers/region_layer.cpp index 409cdfa38b..fccc11e222 100644 --- a/modules/dnn/src/layers/region_layer.cpp +++ b/modules/dnn/src/layers/region_layer.cpp @@ -280,7 +280,7 @@ public: } if (useSoftmax) { // Yolo v2 - Mat _inpBlob = inpBlob.reshape(0, outBlob.dims, outBlob.size); + Mat _inpBlob = inpBlob.reshape(0, outBlob.size); softmax(outBlob, _inpBlob, -1, 5, classes); } else if (useLogistic) { // Yolo v3 diff --git a/modules/dnn/src/legacy_backend.hpp b/modules/dnn/src/legacy_backend.hpp index d8ad88cb72..4b5b5f80ae 100644 --- a/modules/dnn/src/legacy_backend.hpp +++ b/modules/dnn/src/legacy_backend.hpp @@ -213,7 +213,7 @@ public: { reuse(bestBlobPin, lp); dst = bestBlob.reshape(1, 1).colRange(0, targetTotal).reshape(1, shape); - dst.dims = shape.size(); + dst.size.dims = dst.dims = shape.size(); return; } } diff --git a/modules/dnn/src/net_impl.cpp b/modules/dnn/src/net_impl.cpp index a4b9a1d04a..b66c7c759c 100644 --- a/modules/dnn/src/net_impl.cpp +++ b/modules/dnn/src/net_impl.cpp @@ -626,7 +626,7 @@ void Net::Impl::allocateLayers(const std::vector& blobsToKeep_) { type = CV_16F; if (layers[0].dtype == CV_32F) - layers[0].outputBlobs[i].create(inp.dims, inp.size, CV_16F); + layers[0].outputBlobs[i].create(inp.size, CV_16F); } } inputShapes.push_back(shape(inp)); @@ -1426,7 +1426,7 @@ void Net::Impl::updateLayersShapes() preferableTarget == DNN_TARGET_OPENCL_FP16 && inputLayerData.dtype == CV_32F) { - inp.create(inp.dims, inp.size, CV_16F); + inp.create(inp.size, CV_16F); } inputShapes.push_back(shape(inp)); inputTypes.push_back(inp.type()); diff --git a/modules/dnn/src/onnx/onnx_graph_simplifier.cpp b/modules/dnn/src/onnx/onnx_graph_simplifier.cpp index 0a16f736c7..f409dfb861 100644 --- a/modules/dnn/src/onnx/onnx_graph_simplifier.cpp +++ b/modules/dnn/src/onnx/onnx_graph_simplifier.cpp @@ -1927,8 +1927,9 @@ Mat getMatFromTensor(const opencv_onnx::TensorProto& tensor_proto, bool uint8ToI CV_LOG_ERROR(NULL, errorMsg); return blob; } - if (tensor_proto.dims_size() == 0) - blob.dims = 1; // To force 1-dimensional cv::Mat for scalars. + if (tensor_proto.dims_size() == 0) { + blob.size.dims = blob.dims = 1; // To force 1-dimensional cv::Mat for scalars. + } return blob; } diff --git a/modules/dnn/src/onnx/onnx_importer.cpp b/modules/dnn/src/onnx/onnx_importer.cpp index 38069dada5..3338a86a88 100644 --- a/modules/dnn/src/onnx/onnx_importer.cpp +++ b/modules/dnn/src/onnx/onnx_importer.cpp @@ -2193,7 +2193,7 @@ void ONNXImporter::parseSqueeze(LayerParams& layerParams, const opencv_onnx::Nod { Mat inp = getBlob(node_proto, 0); Mat out = inp.reshape(1, outShape); - out.dims = outShape.size(); // to workaround dims == 1 + out.size.dims = out.dims = outShape.size(); // to workaround dims == 1 addConstant(node_proto.output(0), out); return; } @@ -2465,7 +2465,7 @@ void ONNXImporter::parseShape(LayerParams& layerParams, const opencv_onnx::NodeP int dims = static_cast(inpShape.size()); if (isInput1D) dims = 1; - Mat shapeMat(1, dims, CV_64S); + Mat shapeMat(1, &dims, CV_64S); bool isDynamicShape = false; for (int j = 0; j < dims; ++j) { @@ -2473,7 +2473,6 @@ void ONNXImporter::parseShape(LayerParams& layerParams, const opencv_onnx::NodeP isDynamicShape |= (sz == 0); shapeMat.at(j) = sz; } - shapeMat.dims = 1; // FIXIT Mat 1D if (isDynamicShape) { @@ -2508,7 +2507,7 @@ void ONNXImporter::parseCast(LayerParams& layerParams, const opencv_onnx::NodePr } Mat dst; blob.convertTo(dst, type); - dst.dims = blob.dims; + //dst.size.dims = dst.dims = blob.dims; addConstant(node_proto.output(0), dst); return; } @@ -2918,8 +2917,8 @@ void ONNXImporter::parseElementWise(LayerParams& layerParams, const opencv_onnx: LayerParams constParams; constParams.name = node_proto.input(i); constParams.type = "Const"; - // Non-constant propagated layers cannot output 1-d or 0-d tensors. - inp.dims = std::max(inp.dims, 2); + // Non-constant propagated layers cannot output 0-d tensors. + inp.size.dims = inp.dims = std::max(inp.dims, 1); constParams.blobs.push_back(inp); opencv_onnx::NodeProto proto; @@ -3870,7 +3869,7 @@ void ONNXImporter::parseQConcat(LayerParams& layerParams, const opencv_onnx::Nod for (size_t i = 2; i < num_inputs; i += 3) { Mat blob = getBlob(node_proto, i); - if (blob.size.dims() > inputShape.size()) + if (blob.size.dims > inputShape.size()) { inputShape = shape(blob); } diff --git a/modules/dnn/src/onnx/onnx_importer2.cpp b/modules/dnn/src/onnx/onnx_importer2.cpp index 8c1ed98190..0b1790c3cc 100644 --- a/modules/dnn/src/onnx/onnx_importer2.cpp +++ b/modules/dnn/src/onnx/onnx_importer2.cpp @@ -106,7 +106,7 @@ static std::string dataType2str(int dt) static Mat getMatFromTensor2(const opencv_onnx::TensorProto& tensor_proto, const std::string base_path="") { Mat m = getMatFromTensor(tensor_proto, false, base_path); - m.dims = (int)tensor_proto.dims_size(); + m.size.dims = m.dims = (int)tensor_proto.dims_size(); return m; } diff --git a/modules/dnn/src/tflite/tflite_importer.cpp b/modules/dnn/src/tflite/tflite_importer.cpp index dd74d6ead0..e7f447109f 100644 --- a/modules/dnn/src/tflite/tflite_importer.cpp +++ b/modules/dnn/src/tflite/tflite_importer.cpp @@ -130,7 +130,7 @@ Mat TFLiteImporter::parseTensor(const Tensor& tensor) Mat res = Mat(shape, dtype, const_cast(data)); // workaround for scalars support if (!tensor_shape || shape.size() == 1) - res.dims = 1; + res.size.dims = res.dims = 1; return res; } @@ -287,7 +287,7 @@ void TFLiteImporter::populateNet() Mat dataFP32; data.convertTo(dataFP32, CV_32F); // workaround for scalars support - dataFP32.dims = data.dims; + dataFP32.size.dims = dataFP32.dims = data.dims; allTensors[op_outputs->Get(0)] = dataFP32; continue; } diff --git a/modules/dnn/test/test_int.cpp b/modules/dnn/test/test_int.cpp index 9bde00dd0b..f5a6ecb356 100644 --- a/modules/dnn/test/test_int.cpp +++ b/modules/dnn/test/test_int.cpp @@ -100,7 +100,7 @@ TEST_P(Test_NaryEltwise_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], input1.size[0]); EXPECT_EQ(re.size[1], input1.size[1]); EXPECT_EQ(re.size[2], input1.size[2]); @@ -175,7 +175,7 @@ TEST_P(Test_Const_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], input1.size[0]); EXPECT_EQ(re.size[1], input1.size[1]); EXPECT_EQ(re.size[2], input1.size[2]); @@ -281,7 +281,7 @@ TEST_P(Test_ScatterND_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); ASSERT_EQ(shape(input), shape(re)); std::vector reIndices(4); @@ -364,7 +364,7 @@ TEST_P(Test_Concat_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], input1.size[0]); EXPECT_EQ(re.size[1], input1.size[1] + input2.size[1]); EXPECT_EQ(re.size[2], input1.size[2]); @@ -441,7 +441,7 @@ TEST_P(Test_ArgMax_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), CV_64S); - EXPECT_EQ(re.size.dims(), 3); + EXPECT_EQ(re.size.dims, 3); EXPECT_EQ(re.size[0], inShape[0]); EXPECT_EQ(re.size[1], inShape[2]); EXPECT_EQ(re.size[2], inShape[3]); @@ -510,7 +510,7 @@ TEST_P(Test_Blank_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], 2); EXPECT_EQ(re.size[1], 3); EXPECT_EQ(re.size[2], 4); @@ -568,7 +568,7 @@ TEST_P(Test_Expand_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], 2); EXPECT_EQ(re.size[1], 3); EXPECT_EQ(re.size[2], 4); @@ -631,7 +631,7 @@ TEST_P(Test_Permute_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], 2); EXPECT_EQ(re.size[1], 4); EXPECT_EQ(re.size[2], 5); @@ -705,7 +705,7 @@ TEST_P(Test_GatherElements_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); ASSERT_EQ(shape(indicesMat), shape(re)); std::vector inIndices(4); @@ -823,7 +823,7 @@ TEST_P(Test_Cast_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), outMatType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); ASSERT_EQ(shape(input), shape(re)); normAssert(outputRef, re); @@ -865,7 +865,7 @@ TEST_P(Test_Pad_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], 2); EXPECT_EQ(re.size[1], 3); EXPECT_EQ(re.size[2], 5); @@ -940,7 +940,7 @@ TEST_P(Test_Slice_Int, random) Mat out = net.forward(); Mat gt = input(range); - EXPECT_EQ(out.size.dims(), 4); + EXPECT_EQ(out.size.dims, 4); EXPECT_EQ(out.size[0], gt.size[0]); EXPECT_EQ(out.size[1], gt.size[1]); EXPECT_EQ(out.size[2], gt.size[2]); @@ -981,7 +981,7 @@ TEST_P(Test_Reshape_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], outShape[0]); EXPECT_EQ(re.size[1], outShape[1]); EXPECT_EQ(re.size[2], outShape[2]); @@ -1022,7 +1022,7 @@ TEST_P(Test_Flatten_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 2); + EXPECT_EQ(re.size.dims, 2); EXPECT_EQ(re.size[0], inShape[0]); EXPECT_EQ(re.size[1], inShape[1] * inShape[2] * inShape[3]); @@ -1062,7 +1062,7 @@ TEST_P(Test_Tile_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 4); + EXPECT_EQ(re.size.dims, 4); EXPECT_EQ(re.size[0], inShape[0] * repeats[0]); EXPECT_EQ(re.size[1], inShape[1] * repeats[1]); EXPECT_EQ(re.size[2], inShape[2] * repeats[2]); @@ -1142,7 +1142,7 @@ TEST_P(Test_Reduce_Int, random) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 3); + EXPECT_EQ(re.size.dims, 3); EXPECT_EQ(re.size[0], inShape[0]); EXPECT_EQ(re.size[1], inShape[2]); EXPECT_EQ(re.size[2], inShape[3]); @@ -1219,7 +1219,7 @@ TEST_P(Test_Reduce_Int, two_axes) Mat re; re = net.forward(); EXPECT_EQ(re.depth(), matType); - EXPECT_EQ(re.size.dims(), 2); + EXPECT_EQ(re.size.dims, 2); EXPECT_EQ(re.size[0], inShape[0]); EXPECT_EQ(re.size[1], inShape[2]); diff --git a/modules/dnn/test/test_layers.cpp b/modules/dnn/test/test_layers.cpp index 67c04a5a9f..2182969696 100644 --- a/modules/dnn/test/test_layers.cpp +++ b/modules/dnn/test/test_layers.cpp @@ -965,7 +965,7 @@ TEST_P(Scale_untrainable, Accuracy) net.setPreferableBackend(DNN_BACKEND_OPENCV); Mat out = net.forward(); - Mat ref(input.dims, input.size, CV_32F); + Mat ref(input.size, CV_32F); float* inpData = (float*)input.data; float* refData = (float*)ref.data; float* weightsData = (float*)weights.data; @@ -1060,7 +1060,7 @@ TEST_P(Crop, Accuracy) for (int i = axis; i < 4; i++) crop_range[i] = Range(offsetVal, sizShape[i] + offsetVal); - Mat ref(sizImage.dims, sizImage.size, CV_32F); + Mat ref(sizImage.size, CV_32F); inpImage(&crop_range[0]).copyTo(ref); normAssert(out, ref); } diff --git a/modules/dnn/test/test_layers_1d.cpp b/modules/dnn/test/test_layers_1d.cpp index 91dc2f9eba..16e6fc6ac0 100644 --- a/modules/dnn/test/test_layers_1d.cpp +++ b/modules/dnn/test/test_layers_1d.cpp @@ -1438,7 +1438,7 @@ TEST_P(Layer_FullyConnected_Test, Accuracy_01D) Mat input(input_shape, CV_32F); randn(input, 0, 1); Mat output_ref = input.reshape(1, 1) * weights; - output_ref.dims = input_shape.dims; + output_ref.size.dims = output_ref.dims = input_shape.dims; std::vector inputs{input}; std::vector outputs; diff --git a/modules/imgproc/src/deriv.cpp b/modules/imgproc/src/deriv.cpp index 0760d224ab..d38a345037 100644 --- a/modules/imgproc/src/deriv.cpp +++ b/modules/imgproc/src/deriv.cpp @@ -776,17 +776,18 @@ void cv::Laplacian( InputArray _src, OutputArray _dst, int ddepth, int ksize, const uchar* sptr = src.ptr() + src.step[0] * y; int dy0 = std::min(std::max((int)(STRIPE_SIZE/(CV_ELEM_SIZE(stype)*src.cols)), 1), src.rows); - Mat d2x( dy0 + kd.rows - 1, src.cols, wtype ); - Mat d2y( dy0 + kd.rows - 1, src.cols, wtype ); + Mat d2xbuf( dy0 + kd.rows - 1, src.cols, wtype ); + Mat d2ybuf( dy0 + kd.rows - 1, src.cols, wtype ); for( ; dsty < src.rows; sptr += dy0*src.step, dsty += dy ) { - fx->proceed( sptr, (int)src.step, dy0, d2x.ptr(), (int)d2x.step ); - dy = fy->proceed( sptr, (int)src.step, dy0, d2y.ptr(), (int)d2y.step ); + fx->proceed( sptr, (int)src.step, dy0, d2xbuf.ptr(), (int)d2xbuf.step ); + dy = fy->proceed( sptr, (int)src.step, dy0, d2ybuf.ptr(), (int)d2ybuf.step ); if( dy > 0 ) { Mat dstripe = dst.rowRange(dsty, dsty + dy); - d2x.rows = d2y.rows = dy; // modify the headers, which should work + Mat d2x = d2xbuf.rowRange(0, dy); + Mat d2y = d2ybuf.rowRange(0, dy); d2x += d2y; d2x.convertTo( dstripe, ddepth, scale, delta ); } diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index ce5951f5a0..835d35c285 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -929,7 +929,7 @@ void cv::calcHist( const Mat* images, int nimages, const int* channels, Size imsize; CV_Assert( mask.empty() || mask.type() == CV_8UC1 || mask.type() == CV_BoolC1); - histPrepareImages( images, nimages, channels, mask, dims, hist.size, ranges, + histPrepareImages( images, nimages, channels, mask, dims, hist.size.p, ranges, uniform, ptrs, deltas, imsize, uniranges ); const double* _uniranges = uniform ? &uniranges[0] : 0; @@ -1568,7 +1568,7 @@ void cv::calcBackProject( const Mat* images, int nimages, const int* channels, CV_Assert( dims > 0 && !hist.empty() ); _backProject.create( images[0].size(), images[0].depth() ); Mat backProject = _backProject.getMat(); - histPrepareImages( images, nimages, channels, backProject, dims, hist.size, ranges, + histPrepareImages( images, nimages, channels, backProject, dims, hist.size.p, ranges, uniform, ptrs, deltas, imsize, uniranges ); const double* _uniranges = uniform ? &uniranges[0] : 0; diff --git a/modules/ts/src/ts_func.cpp b/modules/ts/src/ts_func.cpp index 5c8e46a780..ff1a761411 100644 --- a/modules/ts/src/ts_func.cpp +++ b/modules/ts/src/ts_func.cpp @@ -187,7 +187,7 @@ void add(const Mat& _a, double alpha, const Mat& _b, double beta, if( ctype < 0 ) ctype = a.depth(); ctype = CV_MAKETYPE(CV_MAT_DEPTH(ctype), a.channels()); - c.create(a.dims, &a.size[0], ctype); + c.create(a.size, ctype); const Mat *arrays[] = {&a, &b, &c, 0}; Mat planes[3], buf[3]; @@ -349,7 +349,7 @@ void convert(const Mat& src, cv::OutputArray _dst, int ddepth = CV_MAT_DEPTH(dtype); dtype = CV_MAKETYPE(ddepth, src.channels()); - _dst.create(src.dims, &src.size[0], dtype); + _dst.create(src.size, dtype); Mat dst = _dst.getMat(); if( alpha == 0 ) { @@ -424,7 +424,7 @@ void convert(const Mat& src, cv::OutputArray _dst, void copy(const Mat& src, Mat& dst, const Mat& mask, bool invertMask) { - dst.create(src.dims, &src.size[0], src.type()); + dst.create(src.size, src.type()); if(mask.empty()) { @@ -576,7 +576,7 @@ void insert(const Mat& src, Mat& dst, int coi) void extract(const Mat& src, Mat& dst, int coi) { - dst.create( src.dims, &src.size[0], src.depth() ); + dst.create( src.size, src.depth() ); CV_Assert( 0 <= coi && coi < src.channels() ); const Mat* arrays[] = {&src, &dst, 0}; @@ -1770,7 +1770,7 @@ void logicOp( const Mat& src1, const Mat& src2, Mat& dst, char op ) { CV_Assert( op == '&' || op == '|' || op == '^' ); CV_Assert( src1.type() == src2.type() && src1.size == src2.size ); - dst.create( src1.dims, &src1.size[0], src1.type() ); + dst.create( src1.size, src1.type() ); const Mat *arrays[]={&src1, &src2, &dst, 0}; Mat planes[3]; @@ -1792,7 +1792,7 @@ void logicOp( const Mat& src1, const Mat& src2, Mat& dst, char op ) void logicOp(const Mat& src, const Scalar& s, Mat& dst, char op) { CV_Assert( op == '&' || op == '|' || op == '^' || op == '~' ); - dst.create( src.dims, &src.size[0], src.type() ); + dst.create( src.size, src.type() ); const Mat *arrays[]={&src, &dst, 0}; Mat planes[2]; @@ -1887,7 +1887,7 @@ compareS_(const _Tp* src1, _WTp value, uchar* dst, size_t total, int cmpop) void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop) { CV_Assert( src1.type() == src2.type() && src1.channels() == 1 && src1.size == src2.size ); - dst.create( src1.dims, &src1.size[0], CV_8U ); + dst.create( src1.size, CV_8U ); const Mat *arrays[]={&src1, &src2, &dst, 0}; Mat planes[3]; @@ -1949,7 +1949,7 @@ void compare(const Mat& src1, const Mat& src2, Mat& dst, int cmpop) void compare(const Mat& src, double value, Mat& dst, int cmpop) { CV_Assert( src.channels() == 1 ); - dst.create( src.dims, &src.size[0], CV_8U ); + dst.create( src.size, CV_8U ); const Mat *arrays[]={&src, &dst, 0}; Mat planes[2]; @@ -2749,7 +2749,7 @@ minmax16f_(const _Tp* src1, const _Tp* src2, _Tp* dst, size_t total, char op) static void minmax(const Mat& src1, const Mat& src2, Mat& dst, char op) { - dst.create(src1.dims, src1.size, src1.type()); + dst.create(src1.size, src1.type()); CV_Assert( src1.type() == src2.type() && src1.size == src2.size ); const Mat *arrays[]={&src1, &src2, &dst, 0}; Mat planes[3]; @@ -2845,7 +2845,7 @@ minmax_16f(const _Tp* src1, _Tp val_, _Tp* dst, size_t total, char op) static void minmax(const Mat& src1, double val, Mat& dst, char op) { - dst.create(src1.dims, src1.size, src1.type()); + dst.create(src1.size, src1.type()); const Mat *arrays[]={&src1, &dst, 0}; Mat planes[2]; @@ -2947,7 +2947,7 @@ muldiv_16f(const _Tp* src1, const _Tp* src2, _Tp* dst, size_t total, double scal static void muldiv(const Mat& src1, const Mat& src2, Mat& dst, int ctype, double scale, char op) { - dst.create(src2.dims, src2.size, (ctype >= 0 ? ctype : src2.type())); + dst.create(src2.size, (ctype >= 0 ? ctype : src2.type())); CV_Assert( src1.empty() || (src1.type() == src2.type() && src1.size == src2.size) ); const Mat *arrays[]={&src1, &src2, &dst, 0}; Mat planes[3];