Add implementations for Mat::zeros() and Mat::ones()

In class Mat, "static MatExpr Mat::zeros(int ndims, const int* sz, int
type)" and "static MatExpr Mat::ones(int ndims, const int* sz, int
type)" are declared but never implemented. That means we can see their
manuals from
"http://docs.opencv.org/modules/core/doc/basic_structures.html" but we
can't use them. Here I tried to finish their implementation.
I have also changed MatOp_Initializer::assign to make it support
multi-dimension Mat.
Test cases are added in test_math.cpp as well.
This commit is contained in:
Artanis
2013-03-01 13:18:44 +08:00
parent 0532a521a2
commit 993522598b
2 changed files with 47 additions and 5 deletions

View File

@@ -2536,12 +2536,30 @@ TYPED_TEST_P(Core_CheckRange, Zero)
double min_bound = 0.0;
double max_bound = 0.1;
cv::Mat src = cv::Mat::zeros(3,3, cv::DataDepth<TypeParam>::value);
cv::Mat src1 = cv::Mat::zeros(3, 3, cv::DataDepth<TypeParam>::value);
ASSERT_TRUE( checkRange(src, true, NULL, min_bound, max_bound) );
int sizes[] = {5, 6, 7};
cv::Mat src2 = cv::Mat::zeros(3, sizes, cv::DataDepth<TypeParam>::value);
ASSERT_TRUE( checkRange(src1, true, NULL, min_bound, max_bound) );
ASSERT_TRUE( checkRange(src2, true, NULL, min_bound, max_bound) );
}
REGISTER_TYPED_TEST_CASE_P(Core_CheckRange, Negative, Positive, Bounds, Zero);
TYPED_TEST_P(Core_CheckRange, One)
{
double min_bound = 1.0;
double max_bound = 1.1;
cv::Mat src1 = cv::Mat::ones(3, 3, cv::DataDepth<TypeParam>::value);
int sizes[] = {5, 6, 7};
cv::Mat src2 = cv::Mat::ones(3, sizes, cv::DataDepth<TypeParam>::value);
ASSERT_TRUE( checkRange(src1, true, NULL, min_bound, max_bound) );
ASSERT_TRUE( checkRange(src2, true, NULL, min_bound, max_bound) );
}
REGISTER_TYPED_TEST_CASE_P(Core_CheckRange, Negative, Positive, Bounds, Zero, One);
typedef ::testing::Types<signed char,unsigned char, signed short, unsigned short, signed int> mat_data_types;
INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Core_CheckRange, mat_data_types);