/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, // copy or use the software. // // // License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009, Willow Garage Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // Redistribution and use in source and binary forms, with or without modification, // are permitted provided that the following conditions are met: // // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistribution's in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * The name of the copyright holders may not be used to endorse or promote products // derived from this software without specific prior written permission. // // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. // In no event shall the Intel Corporation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused // and on any theory of liability, whether in contract, strict liability, // or tort (including negligence or otherwise) arising in any way out of // the use of this software, even if advised of the possibility of such damage. // //M*/ #include "test_precomp.hpp" namespace opencv_test { namespace { typedef testing::TestWithParam > HasNonZeroAllZeros; TEST_P(HasNonZeroAllZeros, hasNonZeroAllZeros) { const int type = std::get<0>(GetParam()); const Size size = std::get<1>(GetParam()); Mat m = Mat::zeros(size, type); EXPECT_FALSE(hasNonZero(m)); } INSTANTIATE_TEST_CASE_P(Core, HasNonZeroAllZeros, testing::Combine( testing::Values(CV_8UC1, CV_8SC1, CV_16UC1, CV_16SC1, CV_32SC1, CV_32FC1, CV_64FC1), testing::Values(Size(1, 1), Size(320, 240), Size(127, 113), Size(1, 113)) ) ); typedef testing::TestWithParam > HasNonZeroNegZeros; TEST_P(HasNonZeroNegZeros, hasNonZeroNegZeros) { const int type = std::get<0>(GetParam()); const Size size = std::get<1>(GetParam()); Mat m = Mat(size, type); m.setTo(Scalar::all(-0.)); EXPECT_FALSE(hasNonZero(m)); } INSTANTIATE_TEST_CASE_P(Core, HasNonZeroNegZeros, testing::Combine( testing::Values(CV_32FC1, CV_64FC1, CV_16FC1, CV_16BFC1), testing::Values(Size(1, 1), Size(320, 240), Size(127, 113), Size(1, 113)) ) ); typedef testing::TestWithParam > HasNonZeroLimitValues; TEST_P(HasNonZeroLimitValues, hasNonZeroLimitValues) { const int type = std::get<0>(GetParam()); const Size size = std::get<1>(GetParam()); Mat m = Mat(size, type); m.setTo(Scalar::all(std::numeric_limits::infinity())); EXPECT_TRUE(hasNonZero(m)); m.setTo(Scalar::all(-std::numeric_limits::infinity())); EXPECT_TRUE(hasNonZero(m)); m.setTo(Scalar::all(std::numeric_limits::quiet_NaN())); EXPECT_TRUE(hasNonZero(m)); m.setTo((CV_MAT_DEPTH(type) == CV_64F) ? Scalar::all(std::numeric_limits::epsilon()) : Scalar::all(std::numeric_limits::epsilon())); EXPECT_TRUE(hasNonZero(m)); m.setTo((CV_MAT_DEPTH(type) == CV_64F) ? Scalar::all(std::numeric_limits::min()) : Scalar::all(std::numeric_limits::min())); EXPECT_TRUE(hasNonZero(m)); m.setTo((CV_MAT_DEPTH(type) == CV_64F) ? Scalar::all(std::numeric_limits::denorm_min()) : Scalar::all(std::numeric_limits::denorm_min())); EXPECT_TRUE(hasNonZero(m)); } INSTANTIATE_TEST_CASE_P(Core, HasNonZeroLimitValues, testing::Combine( testing::Values(CV_32FC1, CV_64FC1), testing::Values(Size(1, 1), Size(320, 240), Size(127, 113), Size(1, 113)) ) ); typedef testing::TestWithParam > HasNonZeroRandom; TEST_P(HasNonZeroRandom, hasNonZeroRandom) { const int type = std::get<0>(GetParam()); const Size size = std::get<1>(GetParam()); RNG& rng = theRNG(); const size_t N = std::min(100, size.area()); for(size_t i = 0 ; i > HasNonZeroNd; TEST_P(HasNonZeroNd, hasNonZeroNd) { const int type = get<0>(GetParam()); const int ndims = get<1>(GetParam()); const bool continuous = get<2>(GetParam()); RNG& rng = theRNG(); const size_t N = 10; for(size_t i = 0 ; i steps(ndims); std::vector sizes(ndims); size_t totalBytes = 1; for(int dim = 0 ; dim(length))*CV_ELEM_SIZE(type); sizes[dim] = (isFirstDim || continuous) ? length : rng.uniform(1, length); totalBytes *= steps[dim]*static_cast(sizes[dim]); } std::vector buffer(totalBytes); void* data = buffer.data(); Mat m = Mat(ndims, sizes.data(), type, data, steps.data()); std::vector nzRange(ndims); for(int dim = 0 ; dim0), hasNonZero(m)); } } INSTANTIATE_TEST_CASE_P(Core, HasNonZeroNd, testing::Combine( testing::Values(CV_8UC1), testing::Values(2, 3), testing::Values(true, false) ) ); }} // namespace