perf_moments.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. // Copyright (C) 2014, Itseez, Inc., all rights reserved.
  5. // Third party copyrights are property of their respective owners.
  6. #include "perf_precomp.hpp"
  7. namespace opencv_test {
  8. typedef tuple<Size, MatDepth, bool> MomentsParams_t;
  9. typedef perf::TestBaseWithParam<MomentsParams_t> MomentsFixture_val;
  10. PERF_TEST_P(MomentsFixture_val, Moments1,
  11. ::testing::Combine(
  12. testing::Values(TYPICAL_MAT_SIZES),
  13. testing::Values(CV_16U, CV_16S, CV_32F, CV_64F),
  14. testing::Bool()))
  15. {
  16. const MomentsParams_t params = GetParam();
  17. const Size srcSize = get<0>(params);
  18. const MatDepth srcDepth = get<1>(params);
  19. const bool binaryImage = get<2>(params);
  20. cv::Moments m;
  21. Mat src(srcSize, srcDepth);
  22. declare.in(src, WARMUP_RNG);
  23. TEST_CYCLE() m = cv::moments(src, binaryImage);
  24. int len = (int)sizeof(cv::Moments) / sizeof(double);
  25. cv::Mat mat(1, len, CV_64F, (void*)&m);
  26. //adding 1 to moments to avoid accidental tests fail on values close to 0
  27. mat += 1;
  28. SANITY_CHECK_MOMENTS(m, 2e-4, ERROR_RELATIVE);
  29. }
  30. } // namespace