Skip to content

Commit c038d1b

Browse files
committed
Merge pull request opencv#7858 from addisonElliott:master
2 parents faefbf9 + fa6692a commit c038d1b

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed

modules/core/include/opencv2/core/mat.hpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,13 @@ class CV_EXPORTS Mat
794794
*/
795795
Mat(int ndims, const int* sizes, int type);
796796

797+
/** @overload
798+
@param sizes Array of integers specifying an n-dimensional array shape.
799+
@param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
800+
CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
801+
*/
802+
Mat(const std::vector<int>& sizes, int type);
803+
797804
/** @overload
798805
@param ndims Array dimensionality.
799806
@param sizes Array of integers specifying an n-dimensional array shape.
@@ -805,6 +812,17 @@ class CV_EXPORTS Mat
805812
*/
806813
Mat(int ndims, const int* sizes, int type, const Scalar& s);
807814

815+
/** @overload
816+
@param sizes Array of integers specifying an n-dimensional array shape.
817+
@param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
818+
CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
819+
@param s An optional value to initialize each matrix element with. To set all the matrix elements to
820+
the particular value after the construction, use the assignment operator
821+
Mat::operator=(const Scalar& value) .
822+
*/
823+
Mat(const std::vector<int>& sizes, int type, const Scalar& s);
824+
825+
808826
/** @overload
809827
@param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied
810828
by these constructors. Instead, the header pointing to m data or its sub-array is constructed and
@@ -861,6 +879,20 @@ class CV_EXPORTS Mat
861879
*/
862880
Mat(int ndims, const int* sizes, int type, void* data, const size_t* steps=0);
863881

882+
/** @overload
883+
@param sizes Array of integers specifying an n-dimensional array shape.
884+
@param type Array type. Use CV_8UC1, ..., CV_64FC4 to create 1-4 channel matrices, or
885+
CV_8UC(n), ..., CV_64FC(n) to create multi-channel (up to CV_CN_MAX channels) matrices.
886+
@param data Pointer to the user data. Matrix constructors that take data and step parameters do not
887+
allocate matrix data. Instead, they just initialize the matrix header that points to the specified
888+
data, which means that no data is copied. This operation is very efficient and can be used to
889+
process external data using OpenCV functions. The external data is not automatically deallocated, so
890+
you should take care of it.
891+
@param steps Array of ndims-1 steps in case of a multi-dimensional array (the last step is always
892+
set to the element size). If not specified, the matrix is assumed to be continuous.
893+
*/
894+
Mat(const std::vector<int>& sizes, int type, void* data, const size_t* steps=0);
895+
864896
/** @overload
865897
@param m Array that (as a whole or partly) is assigned to the constructed matrix. No data is copied
866898
by these constructors. Instead, the header pointing to m data or its sub-array is constructed and
@@ -1328,6 +1360,12 @@ class CV_EXPORTS Mat
13281360
*/
13291361
void create(int ndims, const int* sizes, int type);
13301362

1363+
/** @overload
1364+
@param sizes Array of integers specifying a new array shape.
1365+
@param type New matrix type.
1366+
*/
1367+
void create(const std::vector<int>& sizes, int type);
1368+
13311369
/** @brief Increments the reference counter.
13321370
13331371
The method increments the reference counter associated with the matrix data. If the matrix header
@@ -2273,6 +2311,7 @@ class CV_EXPORTS UMat
22732311
void create(int rows, int cols, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
22742312
void create(Size size, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
22752313
void create(int ndims, const int* sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
2314+
void create(const std::vector<int>& sizes, int type, UMatUsageFlags usageFlags = USAGE_DEFAULT);
22762315

22772316
//! increases the reference counter; use with care to avoid memleaks
22782317
void addref();

modules/core/include/opencv2/core/mat.inl.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,23 @@ Mat::Mat(int _dims, const int* _sz, int _type, const Scalar& _s)
386386
*this = _s;
387387
}
388388

389+
inline
390+
Mat::Mat(const std::vector<int>& _sz, int _type)
391+
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
392+
datalimit(0), allocator(0), u(0), size(&rows)
393+
{
394+
create(_sz, _type);
395+
}
396+
397+
inline
398+
Mat::Mat(const std::vector<int>& _sz, int _type, const Scalar& _s)
399+
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
400+
datalimit(0), allocator(0), u(0), size(&rows)
401+
{
402+
create(_sz, _type);
403+
*this = _s;
404+
}
405+
389406
inline
390407
Mat::Mat(const Mat& m)
391408
: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),

modules/core/src/matrix.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ void Mat::create(int d, const int* _sizes, int _type)
439439
finalizeHdr(*this);
440440
}
441441

442+
void Mat::create(const std::vector<int>& _sizes, int _type)
443+
{
444+
create((int)_sizes.size(), _sizes.data(), _type);
445+
}
446+
442447
void Mat::copySize(const Mat& m)
443448
{
444449
setSize(*this, m.dims, 0, 0);
@@ -541,6 +546,17 @@ Mat::Mat(int _dims, const int* _sizes, int _type, void* _data, const size_t* _st
541546
}
542547

543548

549+
Mat::Mat(const std::vector<int>& _sizes, int _type, void* _data, const size_t* _steps)
550+
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
551+
datalimit(0), allocator(0), u(0), size(&rows)
552+
{
553+
flags |= CV_MAT_TYPE(_type);
554+
datastart = data = (uchar*)_data;
555+
setSize(*this, (int)_sizes.size(), _sizes.data(), _steps, true);
556+
finalizeHdr(*this);
557+
}
558+
559+
544560
Mat::Mat(const Mat& m, const Range* ranges)
545561
: flags(MAGIC_VAL), dims(0), rows(0), cols(0), data(0), datastart(0), dataend(0),
546562
datalimit(0), allocator(0), u(0), size(&rows)

modules/core/src/umatrix.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,11 @@ void UMat::create(int d, const int* _sizes, int _type, UMatUsageFlags _usageFlag
386386
addref();
387387
}
388388

389+
void UMat::create(const std::vector<int>& _sizes, int _type, UMatUsageFlags _usageFlags)
390+
{
391+
create((int)_sizes.size(), _sizes.data(), _type, _usageFlags);
392+
}
393+
389394
void UMat::copySize(const UMat& m)
390395
{
391396
setSize(*this, m.dims, 0, 0);

0 commit comments

Comments
 (0)