test_unwrapping.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include "test_precomp.hpp"
  5. namespace opencv_test { namespace {
  6. class CV_Unwrapping : public cvtest::BaseTest
  7. {
  8. public:
  9. CV_Unwrapping();
  10. ~CV_Unwrapping();
  11. protected:
  12. void run(int);
  13. };
  14. CV_Unwrapping::CV_Unwrapping(){}
  15. CV_Unwrapping::~CV_Unwrapping(){}
  16. void CV_Unwrapping::run( int )
  17. {
  18. int rows = 600;
  19. int cols = 800;
  20. int max = 50;
  21. Mat ramp(rows, cols, CV_32FC1);
  22. Mat wrappedRamp(rows, cols, CV_32FC1);
  23. Mat unwrappedRamp;
  24. Mat rowValues(1, cols, CV_32FC1);
  25. Mat wrappedRowValues(1, cols, CV_32FC1);
  26. for( int i = 0; i < cols; ++i )
  27. {
  28. float v = (float)i*(float)max/(float)cols;
  29. rowValues.at<float>(0, i) = v;
  30. wrappedRowValues.at<float>(0, i) = atan2(sin(v), cos(v));
  31. }
  32. for( int i = 0; i < rows; ++i )
  33. {
  34. rowValues.row(0).copyTo(ramp.row(i));
  35. wrappedRowValues.row(0).copyTo(wrappedRamp.row(i));
  36. }
  37. phase_unwrapping::HistogramPhaseUnwrapping::Params params;
  38. params.width = cols;
  39. params.height = rows;
  40. Ptr<phase_unwrapping::HistogramPhaseUnwrapping> phaseUnwrapping = phase_unwrapping::HistogramPhaseUnwrapping::create(params);
  41. phaseUnwrapping->unwrapPhaseMap(wrappedRamp, unwrappedRamp);
  42. for(int i = 0; i < rows; ++i )
  43. {
  44. for( int j = 0; j < cols; ++ j )
  45. {
  46. EXPECT_NEAR(ramp.at<float>(i, j), unwrappedRamp.at<float>(i, j), 0.001);
  47. }
  48. }
  49. }
  50. TEST( HistogramPhaseUnwrapping, unwrapPhaseMap )
  51. {
  52. CV_Unwrapping test;
  53. test.safe_run();
  54. }
  55. }} // namespace