perf_cvround.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "perf_precomp.hpp"
  2. namespace opencv_test
  3. {
  4. using namespace perf;
  5. #define DECL_ROUND_TEST(NAME, OP, EXTRA) \
  6. template <typename T> \
  7. static void OP ## Mat(const cv::Mat & src, cv::Mat & dst) \
  8. { \
  9. for (int y = 0; y < dst.rows; ++y) \
  10. { \
  11. const T * sptr = src.ptr<T>(y); \
  12. int * dptr = dst.ptr<int>(y); \
  13. \
  14. for (int x = 0; x < dst.cols; ++x) \
  15. dptr[x] = OP(sptr[x]) EXTRA; \
  16. } \
  17. } \
  18. \
  19. PERF_TEST_P(Size_MatType, CvRound_Float ## NAME, \
  20. testing::Combine(testing::Values(TYPICAL_MAT_SIZES), \
  21. testing::Values(CV_32FC1, CV_64FC1))) \
  22. { \
  23. Size size = get<0>(GetParam()); \
  24. int type = get<1>(GetParam()), depth = CV_MAT_DEPTH(type); \
  25. \
  26. cv::Mat src(size, type), dst(size, CV_32SC1); \
  27. \
  28. declare.in(src, WARMUP_RNG).out(dst); \
  29. \
  30. if (depth == CV_32F) \
  31. { \
  32. TEST_CYCLE() \
  33. OP ## Mat<float>(src, dst); \
  34. } \
  35. else if (depth == CV_64F) \
  36. { \
  37. TEST_CYCLE() \
  38. OP ## Mat<double>(src, dst); \
  39. } \
  40. \
  41. SANITY_CHECK_NOTHING(); \
  42. }
  43. DECL_ROUND_TEST(,cvRound,)
  44. DECL_ROUND_TEST(_Ceil,cvCeil,)
  45. DECL_ROUND_TEST(_Floor,cvFloor,)
  46. /* For FP classification tests, try to test them in way which uses
  47. branching logic and avoids extra FP logic. */
  48. DECL_ROUND_TEST(_NaN,cvIsNaN, ? 1 : 2)
  49. DECL_ROUND_TEST(_Inf,cvIsInf, ? 1 : 2)
  50. } // namespace