mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
attempt to add 0d/1d mat support to OpenCV (#23473)
* attempt to add 0d/1d mat support to OpenCV * revised the patch; now 1D mat is treated as 1xN 2D mat rather than Nx1. * a step towards 'green' tests * another little step towards 'green' tests * calib test failures seem to be fixed now * more fixes _core & _dnn * another step towards green ci; even 0D mat's (a.k.a. scalars) are now partly supported! * * fixed strange bug in aruco/charuco detector, not sure why it did not work * also fixed a few remaining failures (hopefully) in dnn & core * disabled failing GAPI tests - too complex to dig into this compiler pipeline * hopefully fixed java tests * trying to fix some more tests * quick followup fix * continue to fix test failures and warnings * quick followup fix * trying to fix some more tests * partly fixed support for 0D/scalar UMat's * use updated parseReduce() from upstream * trying to fix the remaining test failures * fixed [ch]aruco tests in Python * still trying to fix tests * revert "fix" in dnn's CUDA tensor * trying to fix dnn+CUDA test failures * fixed 1D umat creation * hopefully fixed remaining cuda test failures * removed training whitespaces
This commit is contained in:
@@ -243,6 +243,7 @@ public:
|
||||
bool isUMat() const;
|
||||
bool isMatVector() const;
|
||||
bool isUMatVector() const;
|
||||
bool isVecVector() const;
|
||||
bool isMatx() const;
|
||||
bool isVector() const;
|
||||
bool isGpuMat() const;
|
||||
@@ -355,6 +356,9 @@ public:
|
||||
UMat& getUMatRef(int i=-1) const;
|
||||
cuda::GpuMat& getGpuMatRef() const;
|
||||
std::vector<cuda::GpuMat>& getGpuMatVecRef() const;
|
||||
std::vector<Mat>& getMatVecRef() const;
|
||||
std::vector<UMat>& getUMatVecRef() const;
|
||||
template<typename _Tp> std::vector<std::vector<_Tp> >& getVecVecRef() const;
|
||||
ogl::Buffer& getOGlBufferRef() const;
|
||||
cuda::HostMem& getHostMemRef() const;
|
||||
void create(Size sz, int type, int i=-1, bool allowTransposed=false, _OutputArray::DepthMask fixedDepthMask=static_cast<_OutputArray::DepthMask>(0)) const;
|
||||
@@ -602,7 +606,7 @@ struct CV_EXPORTS MatStep
|
||||
MatStep& operator = (size_t s);
|
||||
|
||||
size_t* p;
|
||||
size_t buf[2];
|
||||
size_t buf[3];
|
||||
protected:
|
||||
MatStep& operator = (const MatStep&);
|
||||
};
|
||||
@@ -1510,6 +1514,15 @@ public:
|
||||
*/
|
||||
void create(const std::vector<int>& sizes, int type);
|
||||
|
||||
/** @brief Creates the matrix of the same size as another array.
|
||||
|
||||
The method is similar to _OutputArray::createSameSize(arr, type),
|
||||
but is applied to Mat.
|
||||
@param arr The other array.
|
||||
@param type New matrix type.
|
||||
*/
|
||||
void createSameSize(InputArray arr, int type);
|
||||
|
||||
/** @brief Increments the reference counter.
|
||||
|
||||
The method increments the reference counter associated with the matrix data. If the matrix header
|
||||
@@ -2134,6 +2147,7 @@ public:
|
||||
int dims;
|
||||
//! the number of rows and columns or (-1, -1) when the matrix has more than 2 dimensions
|
||||
int rows, cols;
|
||||
int dummy = 153;
|
||||
//! pointer to the data
|
||||
uchar* data;
|
||||
|
||||
@@ -2307,6 +2321,8 @@ public:
|
||||
void create(Size _size);
|
||||
//! equivalent to Mat::create(_ndims, _sizes, DatType<_Tp>::type)
|
||||
void create(int _ndims, const int* _sizes);
|
||||
//! equivalent to Mat::create(arr.ndims, arr.size.p, DatType<_Tp>::type)
|
||||
void createSameSize(InputArray arr);
|
||||
//! equivalent to Mat::release()
|
||||
void release();
|
||||
//! cross-product
|
||||
@@ -2526,6 +2542,10 @@ public:
|
||||
void create(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
|
||||
void create(const std::vector<int>& sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
|
||||
|
||||
//! allocates new matrix data unless the matrix already has specified size and type.
|
||||
// the size is taken from the specified array.
|
||||
void createSameSize(InputArray arr, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
|
||||
|
||||
//! increases the reference counter; use with care to avoid memleaks
|
||||
void addref();
|
||||
//! decreases reference counter;
|
||||
@@ -2980,7 +3000,6 @@ public:
|
||||
};
|
||||
|
||||
|
||||
|
||||
///////////////////////////////// SparseMat_<_Tp> ////////////////////////////////////
|
||||
|
||||
/** @brief Template sparse n-dimensional array class derived from SparseMat
|
||||
|
||||
@@ -188,6 +188,7 @@ inline bool _InputArray::isMat() const { return kind() == _InputArray::MAT; }
|
||||
inline bool _InputArray::isUMat() const { return kind() == _InputArray::UMAT; }
|
||||
inline bool _InputArray::isMatVector() const { return kind() == _InputArray::STD_VECTOR_MAT; }
|
||||
inline bool _InputArray::isUMatVector() const { return kind() == _InputArray::STD_VECTOR_UMAT; }
|
||||
inline bool _InputArray::isVecVector() const { return kind() == _InputArray::STD_VECTOR_VECTOR; }
|
||||
inline bool _InputArray::isMatx() const { return kind() == _InputArray::MATX; }
|
||||
inline bool _InputArray::isVector() const { return kind() == _InputArray::STD_VECTOR ||
|
||||
kind() == _InputArray::STD_BOOL_VECTOR ||
|
||||
@@ -321,6 +322,28 @@ _OutputArray _OutputArray::rawOut(std::array<_Tp, _Nm>& arr)
|
||||
return v;
|
||||
}
|
||||
|
||||
inline
|
||||
std::vector<Mat>& _OutputArray::getMatVecRef() const
|
||||
{
|
||||
CV_Assert(kind() == _InputArray::STD_VECTOR_MAT);
|
||||
return *(std::vector<Mat>*)obj;
|
||||
}
|
||||
|
||||
inline
|
||||
std::vector<UMat>& _OutputArray::getUMatVecRef() const
|
||||
{
|
||||
CV_Assert(kind() == _InputArray::STD_VECTOR_UMAT);
|
||||
return *(std::vector<UMat>*)obj;
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
std::vector<std::vector<_Tp> >& _OutputArray::getVecVecRef() const
|
||||
{
|
||||
CV_Assert(kind() == _InputArray::STD_VECTOR_VECTOR);
|
||||
CV_Assert(type() == traits::Type<_Tp>::value);
|
||||
return *(std::vector<std::vector<_Tp> >*)obj;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline _InputOutputArray::_InputOutputArray() { init(0+ACCESS_RW, 0); }
|
||||
@@ -460,27 +483,35 @@ CV__DEBUG_NS_END
|
||||
|
||||
template<typename _Tp> inline
|
||||
Mat::Mat(const std::vector<_Tp>& vec, bool copyData)
|
||||
: flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)vec.size()),
|
||||
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((int)vec.size()), data(0), datastart(0), dataend(0), datalimit(0),
|
||||
allocator(0), u(0), size(&cols)
|
||||
{
|
||||
step.buf[1] = sizeof(_Tp);
|
||||
step.buf[0] = cols*step.buf[1];
|
||||
step.p = &step.buf[1];
|
||||
|
||||
if(vec.empty())
|
||||
return;
|
||||
if( !copyData )
|
||||
{
|
||||
step[0] = step[1] = sizeof(_Tp);
|
||||
datastart = data = (uchar*)&vec[0];
|
||||
datalimit = dataend = datastart + rows * step[0];
|
||||
datalimit = dataend = datastart + cols * step[0];
|
||||
}
|
||||
else
|
||||
Mat((int)vec.size(), 1, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
|
||||
{
|
||||
int nelems = (int)vec.size();
|
||||
Mat(1, &nelems, traits::Type<_Tp>::value, (uchar*)&vec[0]).copyTo(*this);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename _Tp, typename> inline
|
||||
Mat::Mat(const std::initializer_list<_Tp> list)
|
||||
: Mat()
|
||||
{
|
||||
CV_Assert(list.size() != 0);
|
||||
Mat((int)list.size(), 1, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this);
|
||||
int nelems = (int)list.size();
|
||||
CV_Assert(nelems != 0);
|
||||
Mat(1, &nelems, traits::Type<_Tp>::value, (uchar*)list.begin()).copyTo(*this);
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
@@ -497,16 +528,20 @@ Mat::Mat(const std::initializer_list<int> sizes, const std::initializer_list<_Tp
|
||||
|
||||
template<typename _Tp, std::size_t _Nm> inline
|
||||
Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData)
|
||||
: flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows((int)arr.size()),
|
||||
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((int)arr.size()), data(0), datastart(0), dataend(0), datalimit(0),
|
||||
allocator(0), u(0), size(&cols), step(0)
|
||||
{
|
||||
step.buf[1] = sizeof(_Tp);
|
||||
step.buf[0] = cols*step.buf[1];
|
||||
step.p = &step.buf[1];
|
||||
|
||||
if(arr.empty())
|
||||
return;
|
||||
if( !copyData )
|
||||
{
|
||||
step[0] = step[1] = sizeof(_Tp);
|
||||
datastart = data = (uchar*)arr.data();
|
||||
datalimit = dataend = datastart + rows * step[0];
|
||||
datalimit = dataend = datastart + cols * step[0];
|
||||
}
|
||||
else
|
||||
Mat((int)arr.size(), 1, traits::Type<_Tp>::value, (uchar*)arr.data()).copyTo(*this);
|
||||
@@ -514,14 +549,16 @@ Mat::Mat(const std::array<_Tp, _Nm>& arr, bool copyData)
|
||||
|
||||
template<typename _Tp, int n> inline
|
||||
Mat::Mat(const Vec<_Tp, n>& vec, bool copyData)
|
||||
: flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(n), 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(n), data(0),
|
||||
datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&cols), step(0)
|
||||
{
|
||||
if( !copyData )
|
||||
{
|
||||
step[0] = step[1] = sizeof(_Tp);
|
||||
step.p = &step.buf[1];
|
||||
step.buf[1] = sizeof(_Tp);
|
||||
step.buf[0] = cols*step.buf[1];
|
||||
datastart = data = (uchar*)vec.val;
|
||||
datalimit = dataend = datastart + rows * step[0];
|
||||
datalimit = dataend = datastart + cols * step[0];
|
||||
}
|
||||
else
|
||||
Mat(n, 1, traits::Type<_Tp>::value, (void*)vec.val).copyTo(*this);
|
||||
@@ -535,8 +572,9 @@ Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData)
|
||||
{
|
||||
if( !copyData )
|
||||
{
|
||||
step[0] = cols * sizeof(_Tp);
|
||||
step[1] = sizeof(_Tp);
|
||||
step.p = &step.buf[0];
|
||||
step.buf[1] = sizeof(_Tp);
|
||||
step.buf[0] = n*sizeof(_Tp);
|
||||
datastart = data = (uchar*)M.val;
|
||||
datalimit = dataend = datastart + rows * step[0];
|
||||
}
|
||||
@@ -546,18 +584,21 @@ Mat::Mat(const Matx<_Tp,m,n>& M, bool copyData)
|
||||
|
||||
template<typename _Tp> inline
|
||||
Mat::Mat(const Point_<_Tp>& pt, bool copyData)
|
||||
: flags(MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(2), rows(2), 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(2), data(0),
|
||||
datastart(0), dataend(0), datalimit(0), allocator(0), u(0), size(&cols), step(0)
|
||||
{
|
||||
if( !copyData )
|
||||
{
|
||||
step[0] = step[1] = sizeof(_Tp);
|
||||
step.p = &step.buf[1];
|
||||
step.buf[1] = sizeof(_Tp);
|
||||
step.buf[0] = cols*step.buf[1];
|
||||
datastart = data = (uchar*)&pt.x;
|
||||
datalimit = dataend = datastart + rows * step[0];
|
||||
datalimit = dataend = datastart + cols * step[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
create(2, 1, traits::Type<_Tp>::value);
|
||||
int sz = 2;
|
||||
create(1, &sz, traits::Type<_Tp>::value);
|
||||
((_Tp*)data)[0] = pt.x;
|
||||
((_Tp*)data)[1] = pt.y;
|
||||
}
|
||||
@@ -565,14 +606,16 @@ Mat::Mat(const Point_<_Tp>& pt, bool copyData)
|
||||
|
||||
template<typename _Tp> 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(&cols), step(0)
|
||||
{
|
||||
if( !copyData )
|
||||
{
|
||||
step[0] = step[1] = sizeof(_Tp);
|
||||
step.p = &step.buf[1];
|
||||
step.buf[1] = sizeof(_Tp);
|
||||
step.buf[0] = cols*step.buf[1];
|
||||
datastart = data = (uchar*)&pt.x;
|
||||
datalimit = dataend = datastart + rows * step[0];
|
||||
datalimit = dataend = datastart + cols * step[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -724,7 +767,10 @@ const _Tp* Mat::ptr(int y) const
|
||||
inline
|
||||
uchar* Mat::ptr(int i0, int i1)
|
||||
{
|
||||
CV_DbgAssert(dims >= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
return ptr(i1);
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
|
||||
@@ -734,7 +780,10 @@ uchar* Mat::ptr(int i0, int i1)
|
||||
inline
|
||||
const uchar* Mat::ptr(int i0, int i1) const
|
||||
{
|
||||
CV_DbgAssert(dims >= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
return ptr(i1);
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
|
||||
@@ -744,7 +793,10 @@ const uchar* Mat::ptr(int i0, int i1) const
|
||||
template<typename _Tp> inline
|
||||
_Tp* Mat::ptr(int i0, int i1)
|
||||
{
|
||||
CV_DbgAssert(dims >= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
return ptr<_Tp>(i1);
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
|
||||
@@ -754,7 +806,10 @@ _Tp* Mat::ptr(int i0, int i1)
|
||||
template<typename _Tp> inline
|
||||
const _Tp* Mat::ptr(int i0, int i1) const
|
||||
{
|
||||
CV_DbgAssert(dims >= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
return ptr<_Tp>(i1);
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
|
||||
@@ -864,26 +919,28 @@ const _Tp* Mat::ptr(const int* idx) const
|
||||
template<int n> inline
|
||||
uchar* Mat::ptr(const Vec<int, n>& idx)
|
||||
{
|
||||
CV_DbgAssert(dims == n);
|
||||
return Mat::ptr(idx.val);
|
||||
}
|
||||
|
||||
template<int n> inline
|
||||
const uchar* Mat::ptr(const Vec<int, n>& idx) const
|
||||
{
|
||||
CV_DbgAssert(dims == n);
|
||||
return Mat::ptr(idx.val);
|
||||
}
|
||||
|
||||
template<typename _Tp, int n> inline
|
||||
_Tp* Mat::ptr(const Vec<int, n>& idx)
|
||||
{
|
||||
CV_DbgAssert( elemSize() == sizeof(_Tp) );
|
||||
CV_DbgAssert( dims == n && elemSize() == sizeof(_Tp) );
|
||||
return Mat::ptr<_Tp>(idx.val);
|
||||
}
|
||||
|
||||
template<typename _Tp, int n> inline
|
||||
const _Tp* Mat::ptr(const Vec<int, n>& idx) const
|
||||
{
|
||||
CV_DbgAssert( elemSize() == sizeof(_Tp) );
|
||||
CV_DbgAssert( dims == n && elemSize() == sizeof(_Tp) );
|
||||
return Mat::ptr<_Tp>(idx.val);
|
||||
}
|
||||
|
||||
@@ -891,7 +948,11 @@ const _Tp* Mat::ptr(const Vec<int, n>& idx) const
|
||||
template<typename _Tp> inline
|
||||
_Tp& Mat::at(int i0, int i1)
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims < 2) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
return at<_Tp>(i1);
|
||||
}
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
|
||||
@@ -902,7 +963,11 @@ _Tp& Mat::at(int i0, int i1)
|
||||
template<typename _Tp> inline
|
||||
const _Tp& Mat::at(int i0, int i1) const
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims < 2) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
return at<_Tp>(i1);
|
||||
}
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
|
||||
@@ -913,7 +978,11 @@ const _Tp& Mat::at(int i0, int i1) const
|
||||
template<typename _Tp> inline
|
||||
_Tp& Mat::at(Point pt)
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims < 2) {
|
||||
CV_DbgAssert(pt.y == 0);
|
||||
return at<_Tp>(pt.x);
|
||||
}
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
|
||||
@@ -924,7 +993,11 @@ _Tp& Mat::at(Point pt)
|
||||
template<typename _Tp> inline
|
||||
const _Tp& Mat::at(Point pt) const
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims < 2) {
|
||||
CV_DbgAssert(pt.y == 0);
|
||||
return at<_Tp>(pt.x);
|
||||
}
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)(pt.x * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels()));
|
||||
@@ -935,10 +1008,14 @@ const _Tp& Mat::at(Point pt) const
|
||||
template<typename _Tp> inline
|
||||
_Tp& Mat::at(int i0)
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
|
||||
CV_DbgAssert(elemSize() == sizeof(_Tp));
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)cols);
|
||||
return ((_Tp*)data)[i0];
|
||||
}
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
|
||||
if( isContinuous() || size.p[0] == 1 )
|
||||
return ((_Tp*)data)[i0];
|
||||
if( size.p[1] == 1 )
|
||||
@@ -950,16 +1027,20 @@ _Tp& Mat::at(int i0)
|
||||
template<typename _Tp> inline
|
||||
const _Tp& Mat::at(int i0) const
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)(size.p[0] * size.p[1]));
|
||||
CV_DbgAssert(elemSize() == sizeof(_Tp));
|
||||
if( isContinuous() || size.p[0] == 1 )
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)cols);
|
||||
return ((const _Tp*)data)[i0];
|
||||
if( size.p[1] == 1 )
|
||||
return *(const _Tp*)(data + step.p[0] * i0);
|
||||
}
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)(rows*cols));
|
||||
if( isContinuous() || rows == 1 )
|
||||
return ((const _Tp*)data)[i0];
|
||||
if( cols == 1 )
|
||||
return *(const _Tp*)(data + step.buf[0] * i0);
|
||||
int i = i0 / cols, j = i0 - i * cols;
|
||||
return ((const _Tp*)(data + step.p[0] * i))[j];
|
||||
return ((const _Tp*)(data + step.buf[0] * i))[j];
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
@@ -1146,8 +1227,7 @@ void Mat::push_back(const _Tp& elem)
|
||||
*this = Mat(1, 1, traits::Type<_Tp>::value, (void*)&elem).clone();
|
||||
return;
|
||||
}
|
||||
CV_Assert(traits::Type<_Tp>::value == type() && cols == 1
|
||||
/* && dims == 2 (cols == 1 implies dims == 2) */);
|
||||
CV_Assert(traits::Type<_Tp>::value == type() && cols == 1);
|
||||
const uchar* tmp = dataend + step[0];
|
||||
if( !isSubmatrix() && isContinuous() && tmp <= datalimit )
|
||||
{
|
||||
@@ -1193,8 +1273,9 @@ int MatSize::dims() const CV_NOEXCEPT
|
||||
inline
|
||||
Size MatSize::operator()() const
|
||||
{
|
||||
CV_DbgAssert(dims() <= 2);
|
||||
return Size(p[1], p[0]);
|
||||
int d = dims();
|
||||
CV_DbgAssert(d <= 2);
|
||||
return d == 2 ? Size(p[1], p[0]) : Size(p[0], 1);
|
||||
}
|
||||
|
||||
inline
|
||||
@@ -1236,13 +1317,13 @@ bool MatSize::operator != (const MatSize& sz) const CV_NOEXCEPT
|
||||
inline
|
||||
MatStep::MatStep() CV_NOEXCEPT
|
||||
{
|
||||
p = buf; p[0] = p[1] = 0;
|
||||
p = buf; p[0] = p[1] = 0; p[2] = 153;
|
||||
}
|
||||
|
||||
inline
|
||||
MatStep::MatStep(size_t s) CV_NOEXCEPT
|
||||
{
|
||||
p = buf; p[0] = s; p[1] = 0;
|
||||
p = buf; p[0] = s; p[1] = 0; p[2] = 153;
|
||||
}
|
||||
|
||||
inline
|
||||
@@ -1259,14 +1340,14 @@ size_t& MatStep::operator[](int i) CV_NOEXCEPT
|
||||
|
||||
inline MatStep::operator size_t() const
|
||||
{
|
||||
CV_DbgAssert( p == buf );
|
||||
return buf[0];
|
||||
CV_DbgAssert( p == buf || p == buf+1 );
|
||||
return *p;
|
||||
}
|
||||
|
||||
inline MatStep& MatStep::operator = (size_t s)
|
||||
{
|
||||
CV_DbgAssert( p == buf );
|
||||
buf[0] = s;
|
||||
CV_DbgAssert( p == buf || p == buf+1 );
|
||||
*p = s;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -1475,6 +1556,12 @@ void Mat_<_Tp>::create(int _dims, const int* _sz)
|
||||
Mat::create(_dims, _sz, traits::Type<_Tp>::value);
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
void Mat_<_Tp>::createSameSize(InputArray m)
|
||||
{
|
||||
_OutputArray(*this).createSameSize(m, traits::Type<_Tp>::value);
|
||||
}
|
||||
|
||||
template<typename _Tp> inline
|
||||
void Mat_<_Tp>::release()
|
||||
{
|
||||
@@ -1612,8 +1699,13 @@ const _Tp* Mat_<_Tp>::operator [](int y) const
|
||||
template<typename _Tp> inline
|
||||
_Tp& Mat_<_Tp>::operator ()(int i0, int i1)
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
CV_DbgAssert(0 <= i1 && i1 < size.p[0]);
|
||||
return ((_Tp*)data)[i1];
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
|
||||
CV_DbgAssert(type() == traits::Type<_Tp>::value);
|
||||
@@ -1623,8 +1715,13 @@ _Tp& Mat_<_Tp>::operator ()(int i0, int i1)
|
||||
template<typename _Tp> inline
|
||||
const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(i0 == 0);
|
||||
CV_DbgAssert(0 <= i1 && i1 < size.p[0]);
|
||||
return ((const _Tp*)data)[i1];
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert((unsigned)i0 < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)i1 < (unsigned)size.p[1]);
|
||||
CV_DbgAssert(type() == traits::Type<_Tp>::value);
|
||||
@@ -1634,8 +1731,13 @@ const _Tp& Mat_<_Tp>::operator ()(int i0, int i1) const
|
||||
template<typename _Tp> inline
|
||||
_Tp& Mat_<_Tp>::operator ()(Point pt)
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(pt.y == 0);
|
||||
CV_DbgAssert(0 <= pt.x && pt.x < size.p[0]);
|
||||
return ((_Tp*)data)[pt.x];
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
|
||||
CV_DbgAssert(type() == traits::Type<_Tp>::value);
|
||||
@@ -1645,8 +1747,13 @@ _Tp& Mat_<_Tp>::operator ()(Point pt)
|
||||
template<typename _Tp> inline
|
||||
const _Tp& Mat_<_Tp>::operator ()(Point pt) const
|
||||
{
|
||||
CV_DbgAssert(dims <= 2);
|
||||
if (dims <= 1) {
|
||||
CV_DbgAssert(pt.y == 0);
|
||||
CV_DbgAssert(0 <= pt.x && pt.x < size.p[0]);
|
||||
return ((const _Tp*)data)[pt.x];
|
||||
}
|
||||
CV_DbgAssert(data);
|
||||
CV_DbgAssert(dims == 2);
|
||||
CV_DbgAssert((unsigned)pt.y < (unsigned)size.p[0]);
|
||||
CV_DbgAssert((unsigned)pt.x < (unsigned)size.p[1]);
|
||||
CV_DbgAssert(type() == traits::Type<_Tp>::value);
|
||||
@@ -3319,9 +3426,7 @@ bool UMat::isSubmatrix() const
|
||||
inline
|
||||
size_t UMat::elemSize() const
|
||||
{
|
||||
size_t res = dims > 0 ? step.p[dims - 1] : 0;
|
||||
CV_DbgAssert(res != 0);
|
||||
return res;
|
||||
return CV_ELEM_SIZE(flags);
|
||||
}
|
||||
|
||||
inline
|
||||
|
||||
@@ -571,7 +571,7 @@ CV_INLINE CvMat cvMat(const cv::Mat& m)
|
||||
{
|
||||
CvMat self;
|
||||
CV_DbgAssert(m.dims <= 2);
|
||||
self = cvMat(m.rows, m.dims == 1 ? 1 : m.cols, m.type(), m.data);
|
||||
self = cvMat(m.dims == 1 ? 1 : m.rows, m.cols, m.type(), m.data);
|
||||
self.step = (int)m.step[0];
|
||||
self.type = (self.type & ~cv::Mat::CONTINUOUS_FLAG) | (m.flags & cv::Mat::CONTINUOUS_FLAG);
|
||||
return self;
|
||||
|
||||
Reference in New Issue
Block a user