add usageFlags to UMat static factories

- add abi compatible overloads
- add test case
pull/20295/head
Dale Phurrough 4 years ago
parent 438e2dc228
commit 8be86cbdfd
No known key found for this signature in database
GPG Key ID: E53384A29713D41F
  1. 27
      modules/core/include/opencv2/core/mat.hpp
  2. 8
      modules/core/src/matrix_operations.cpp
  3. 28
      modules/core/src/umatrix.cpp
  4. 18
      modules/core/test/ocl/test_matrix_expr.cpp

@ -2451,7 +2451,8 @@ public:
//! <0 - a diagonal from the lower half) //! <0 - a diagonal from the lower half)
UMat diag(int d=0) const; UMat diag(int d=0) const;
//! constructs a square diagonal matrix which main diagonal is vector "d" //! constructs a square diagonal matrix which main diagonal is vector "d"
static UMat diag(const UMat& d); static UMat diag(const UMat& d, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat diag(const UMat& d) { return diag(d, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
//! returns deep copy of the matrix, i.e. the data is copied //! returns deep copy of the matrix, i.e. the data is copied
UMat clone() const CV_NODISCARD; UMat clone() const CV_NODISCARD;
@ -2485,14 +2486,22 @@ public:
double dot(InputArray m) const; double dot(InputArray m) const;
//! Matlab-style matrix initialization //! Matlab-style matrix initialization
static UMat zeros(int rows, int cols, int type); static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat zeros(Size size, int type); static UMat zeros(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat zeros(int ndims, const int* sz, int type); static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat ones(int rows, int cols, int type); static UMat zeros(int rows, int cols, int type) { return zeros(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat ones(Size size, int type); static UMat zeros(Size size, int type) { return zeros(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat ones(int ndims, const int* sz, int type); static UMat zeros(int ndims, const int* sz, int type) { return zeros(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat eye(int rows, int cols, int type); static UMat ones(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat eye(Size size, int type); static UMat ones(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat ones(int rows, int cols, int type) { return ones(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat ones(Size size, int type) { return ones(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat ones(int ndims, const int* sz, int type) { return ones(ndims, sz, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat eye(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat eye(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat eye(int rows, int cols, int type) { return eye(rows, cols, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
static UMat eye(Size size, int type) { return eye(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
//! allocates new matrix data unless the matrix already has specified size and type. //! allocates new matrix data unless the matrix already has specified size and type.
// previous data is unreferenced if needed. // previous data is unreferenced if needed.

@ -229,14 +229,14 @@ void cv::setIdentity( InputOutputArray _m, const Scalar& s )
namespace cv { namespace cv {
UMat UMat::eye(int rows, int cols, int type) UMat UMat::eye(int rows, int cols, int type, UMatUsageFlags usageFlags)
{ {
return UMat::eye(Size(cols, rows), type); return UMat::eye(Size(cols, rows), type, usageFlags);
} }
UMat UMat::eye(Size size, int type) UMat UMat::eye(Size size, int type, UMatUsageFlags usageFlags)
{ {
UMat m(size, type); UMat m(size, type, usageFlags);
setIdentity(m); setIdentity(m);
return m; return m;
} }

@ -951,11 +951,11 @@ UMat UMat::reshape(int new_cn, int new_rows) const
return hdr; return hdr;
} }
UMat UMat::diag(const UMat& d) UMat UMat::diag(const UMat& d, UMatUsageFlags usageFlags)
{ {
CV_Assert( d.cols == 1 || d.rows == 1 ); CV_Assert( d.cols == 1 || d.rows == 1 );
int len = d.rows + d.cols - 1; int len = d.rows + d.cols - 1;
UMat m(len, len, d.type(), Scalar(0)); UMat m(len, len, d.type(), Scalar(0), usageFlags);
UMat md = m.diag(); UMat md = m.diag();
if( d.cols == 1 ) if( d.cols == 1 )
d.copyTo(md); d.copyTo(md);
@ -1323,34 +1323,34 @@ UMat UMat::t() const
return m; return m;
} }
UMat UMat::zeros(int rows, int cols, int type) UMat UMat::zeros(int rows, int cols, int type, UMatUsageFlags usageFlags)
{ {
return UMat(rows, cols, type, Scalar::all(0)); return UMat(rows, cols, type, Scalar::all(0), usageFlags);
} }
UMat UMat::zeros(Size size, int type) UMat UMat::zeros(Size size, int type, UMatUsageFlags usageFlags)
{ {
return UMat(size, type, Scalar::all(0)); return UMat(size, type, Scalar::all(0), usageFlags);
} }
UMat UMat::zeros(int ndims, const int* sz, int type) UMat UMat::zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags)
{ {
return UMat(ndims, sz, type, Scalar::all(0)); return UMat(ndims, sz, type, Scalar::all(0), usageFlags);
} }
UMat UMat::ones(int rows, int cols, int type) UMat UMat::ones(int rows, int cols, int type, UMatUsageFlags usageFlags)
{ {
return UMat::ones(Size(cols, rows), type); return UMat(rows, cols, type, Scalar(1), usageFlags);
} }
UMat UMat::ones(Size size, int type) UMat UMat::ones(Size size, int type, UMatUsageFlags usageFlags)
{ {
return UMat(size, type, Scalar(1)); return UMat(size, type, Scalar(1), usageFlags);
} }
UMat UMat::ones(int ndims, const int* sz, int type) UMat UMat::ones(int ndims, const int* sz, int type, UMatUsageFlags usageFlags)
{ {
return UMat(ndims, sz, type, Scalar(1)); return UMat(ndims, sz, type, Scalar(1), usageFlags);
} }
} }

@ -76,6 +76,24 @@ OCL_TEST_P(UMatExpr, Ones)
} }
} }
//////////////////////////////// with usageFlags /////////////////////////////////////////////////
OCL_TEST_P(UMatExpr, WithUsageFlags)
{
for (int j = 0; j < test_loop_times; j++)
{
generateTestData();
UMat u0 = UMat::zeros(size, type, cv::USAGE_ALLOCATE_HOST_MEMORY);
UMat u1 = UMat::ones(size, type, cv::USAGE_ALLOCATE_HOST_MEMORY);
UMat u8 = UMat::eye(size, type, cv::USAGE_ALLOCATE_HOST_MEMORY);
EXPECT_EQ(cv::USAGE_ALLOCATE_HOST_MEMORY, u0.usageFlags);
EXPECT_EQ(cv::USAGE_ALLOCATE_HOST_MEMORY, u1.usageFlags);
EXPECT_EQ(cv::USAGE_ALLOCATE_HOST_MEMORY, u8.usageFlags);
}
}
//////////////////////////////// Instantiation ///////////////////////////////////////////////// //////////////////////////////// Instantiation /////////////////////////////////////////////////
OCL_INSTANTIATE_TEST_CASE_P(MatrixOperation, UMatExpr, Combine(OCL_ALL_DEPTHS_16F, OCL_ALL_CHANNELS)); OCL_INSTANTIATE_TEST_CASE_P(MatrixOperation, UMatExpr, Combine(OCL_ALL_DEPTHS_16F, OCL_ALL_CHANNELS));

Loading…
Cancel
Save