1 // This file is part of OpenCV project. 2 // It is subject to the license terms in the LICENSE file found in the top-level directory 3 // of this distribution and at http://opencv.org/license.html. 4 5 // Copyright (C) 2014, Itseez, Inc., all rights reserved. 6 // Third party copyrights are property of their respective owners. 7 8 #include "perf_precomp.hpp" 9 10 using namespace std; 11 using namespace cv; 12 using namespace perf; 13 using namespace testing; 14 using std::tr1::make_tuple; 15 using std::tr1::get; 16 17 typedef std::tr1::tuple<Size, MatDepth, bool> MomentsParams_t; 18 typedef perf::TestBaseWithParam<MomentsParams_t> MomentsFixture_val; 19 20 PERF_TEST_P(MomentsFixture_val, Moments1, 21 ::testing::Combine( 22 testing::Values(TYPICAL_MAT_SIZES), 23 testing::Values(CV_16U, CV_16S, CV_32F, CV_64F), 24 testing::Bool())) 25 { 26 const MomentsParams_t params = GetParam(); 27 const Size srcSize = get<0>(params); 28 const MatDepth srcDepth = get<1>(params); 29 const bool binaryImage = get<2>(params); 30 31 cv::Moments m; 32 Mat src(srcSize, srcDepth); 33 declare.in(src, WARMUP_RNG); 34 35 TEST_CYCLE() m = cv::moments(src, binaryImage); 36 37 int len = (int)sizeof(cv::Moments) / sizeof(double); 38 cv::Mat mat(1, len, CV_64F, (void*)&m); 39 //adding 1 to moments to avoid accidental tests fail on values close to 0 40 mat += 1; 41 42 43 SANITY_CHECK_MOMENTS(m, 2e-4, ERROR_RELATIVE); 44 } 45