add usageFlags to UMat static factories

- add abi compatible overloads
- add test case
This commit is contained in:
Dale Phurrough 2021-06-22 05:32:54 +02:00
parent 438e2dc228
commit 8be86cbdfd
No known key found for this signature in database
GPG Key ID: E53384A29713D41F
4 changed files with 54 additions and 27 deletions

View File

@ -2451,7 +2451,8 @@ public:
//! <0 - a diagonal from the lower half)
UMat diag(int d=0) const;
//! 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
UMat clone() const CV_NODISCARD;
@ -2485,14 +2486,22 @@ public:
double dot(InputArray m) const;
//! Matlab-style matrix initialization
static UMat zeros(int rows, int cols, int type);
static UMat zeros(Size size, int type);
static UMat zeros(int ndims, const int* sz, int type);
static UMat ones(int rows, int cols, int type);
static UMat ones(Size size, int type);
static UMat ones(int ndims, const int* sz, int type);
static UMat eye(int rows, int cols, int type);
static UMat eye(Size size, int type);
static UMat zeros(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat zeros(Size size, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
static UMat zeros(int ndims, const int* sz, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
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 zeros(Size size, int type) { return zeros(size, type, USAGE_DEFAULT); } // OpenCV 5.0: remove abi compatibility overload
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 ones(int rows, int cols, int type, UMatUsageFlags usageFlags /*= USAGE_DEFAULT*/);
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.
// previous data is unreferenced if needed.

View File

@ -229,14 +229,14 @@ void cv::setIdentity( InputOutputArray _m, const Scalar& s )
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);
return m;
}

View File

@ -951,11 +951,11 @@ UMat UMat::reshape(int new_cn, int new_rows) const
return hdr;
}
UMat UMat::diag(const UMat& d)
UMat UMat::diag(const UMat& d, UMatUsageFlags usageFlags)
{
CV_Assert( d.cols == 1 || d.rows == 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();
if( d.cols == 1 )
d.copyTo(md);
@ -1323,34 +1323,34 @@ UMat UMat::t() const
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);
}
}

View File

@ -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 /////////////////////////////////////////////////
OCL_INSTANTIATE_TEST_CASE_P(MatrixOperation, UMatExpr, Combine(OCL_ALL_DEPTHS_16F, OCL_ALL_CHANNELS));