test_faps.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*M///////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
  4. //
  5. // By downloading, copying, installing or using the software you agree to this license.
  6. // If you do not agree to this license, do not download, install,
  7. // copy or use the software.
  8. //
  9. //
  10. // License Agreement
  11. // For Open Source Computer Vision Library
  12. //
  13. // Copyright (C) 2015, OpenCV Foundation, all rights reserved.
  14. // Third party copyrights are property of their respective owners.
  15. //
  16. // Redistribution and use in source and binary forms, with or without modification,
  17. // are permitted provided that the following conditions are met:
  18. //
  19. // * Redistribution's of source code must retain the above copyright notice,
  20. // this list of conditions and the following disclaimer.
  21. //
  22. // * Redistribution's in binary form must reproduce the above copyright notice,
  23. // this list of conditions and the following disclaimer in the documentation
  24. // and/or other materials provided with the distribution.
  25. //
  26. // * The name of the copyright holders may not be used to endorse or promote products
  27. // derived from this software without specific prior written permission.
  28. //
  29. // This software is provided by the copyright holders and contributors "as is" and
  30. // any express or implied warranties, including, but not limited to, the implied
  31. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  32. // In no event shall the Intel Corporation or contributors be liable for any direct,
  33. // indirect, incidental, special, exemplary, or consequential damages
  34. // (including, but not limited to, procurement of substitute goods or services;
  35. // loss of use, data, or profits; or business interruption) however caused
  36. // and on any theory of liability, whether in contract, strict liability,
  37. // or tort (including negligence or otherwise) arising in any way out of
  38. // the use of this software, even if advised of the possibility of such damage.
  39. //
  40. //M*/
  41. #include "test_precomp.hpp"
  42. #include <opencv2/structured_light/graycodepattern.hpp>
  43. #include <opencv2/structured_light/sinusoidalpattern.hpp>
  44. namespace opencv_test { namespace {
  45. const string STRUCTURED_LIGHT_DIR = "structured_light";
  46. const string FOLDER_DATA = "data";
  47. TEST( SinusoidalPattern, unwrapPhaseMap )
  48. {
  49. string folder = cvtest::TS::ptr()->get_data_path() + "/" + STRUCTURED_LIGHT_DIR + "/" + FOLDER_DATA + "/";
  50. Ptr<structured_light::SinusoidalPattern::Params> paramsPsp, paramsFtp, paramsFaps;
  51. paramsPsp = makePtr<structured_light::SinusoidalPattern::Params>();
  52. paramsFtp = makePtr<structured_light::SinusoidalPattern::Params>();
  53. paramsFaps = makePtr<structured_light::SinusoidalPattern::Params>();
  54. paramsFtp->methodId = 0;
  55. paramsPsp->methodId = 1;
  56. paramsFaps->methodId = 2;
  57. Ptr<structured_light::SinusoidalPattern> sinusPsp = structured_light::SinusoidalPattern::create(paramsPsp);
  58. Ptr<structured_light::SinusoidalPattern> sinusFtp = structured_light::SinusoidalPattern::create(paramsFtp);
  59. Ptr<structured_light::SinusoidalPattern> sinusFaps = structured_light::SinusoidalPattern::create(paramsFaps);
  60. vector<Mat> captures(3);
  61. Mat unwrappedPhaseMapPspRef, unwrappedPhaseMapFtpRef, unwrappedPhaseMapFapsRef;
  62. Mat shadowMask;
  63. Mat wrappedPhaseMap, unwrappedPhaseMap, unwrappedPhaseMap8;
  64. captures[0] = imread(folder + "capture_sin_0.jpg", IMREAD_GRAYSCALE);
  65. captures[1] = imread(folder + "capture_sin_1.jpg", IMREAD_GRAYSCALE);
  66. captures[2] = imread(folder + "capture_sin_2.jpg", IMREAD_GRAYSCALE);
  67. unwrappedPhaseMapPspRef = imread(folder + "unwrappedPspTest.jpg", IMREAD_GRAYSCALE);
  68. unwrappedPhaseMapFtpRef = imread(folder + "unwrappedFtpTest.jpg", IMREAD_GRAYSCALE);
  69. unwrappedPhaseMapFapsRef = imread(folder + "unwrappedFapsTest.jpg", IMREAD_GRAYSCALE);
  70. if( !captures[0].data || !captures[1].data || !captures[2].data || !unwrappedPhaseMapFapsRef.data
  71. || !unwrappedPhaseMapFtpRef.data || !unwrappedPhaseMapPspRef.data )
  72. {
  73. cerr << "invalid test data" << endl;
  74. }
  75. sinusPsp->computePhaseMap(captures, wrappedPhaseMap, shadowMask);
  76. sinusPsp->unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, Size(captures[0].cols, captures[1].rows), shadowMask);
  77. unwrappedPhaseMap.convertTo(unwrappedPhaseMap8, CV_8U, 1, 128);
  78. int sumOfDiff = 0;
  79. int count = 0;
  80. float ratio = 0;
  81. for( int i = 0; i < unwrappedPhaseMap8.rows; ++i )
  82. {
  83. for( int j = 0; j < unwrappedPhaseMap8.cols; ++j )
  84. {
  85. int ref = unwrappedPhaseMapPspRef.at<uchar>(i, j);
  86. int comp = unwrappedPhaseMap8.at<uchar>(i, j);
  87. sumOfDiff += (ref - comp);
  88. count ++;
  89. }
  90. }
  91. ratio = (float)(sumOfDiff / count);
  92. EXPECT_LE( ratio, 0.003 );
  93. sinusFtp->computePhaseMap(captures, wrappedPhaseMap, shadowMask);
  94. sinusFtp->unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, Size(captures[0].cols, captures[1].rows), shadowMask);
  95. unwrappedPhaseMap.convertTo(unwrappedPhaseMap8, CV_8U, 1, 128);
  96. sumOfDiff = 0;
  97. count = 0;
  98. ratio = 0;
  99. for( int i = 0; i < unwrappedPhaseMap8.rows; ++i )
  100. {
  101. for( int j = 0; j < unwrappedPhaseMap8.cols; ++j )
  102. {
  103. int ref = unwrappedPhaseMapFtpRef.at<uchar>(i, j);
  104. int comp = unwrappedPhaseMap8.at<uchar>(i, j);
  105. sumOfDiff += (ref - comp);
  106. count ++;
  107. }
  108. }
  109. ratio = (float)(sumOfDiff / count);
  110. EXPECT_LE( ratio, 0.003 );
  111. sinusFaps->computePhaseMap(captures, wrappedPhaseMap, shadowMask);
  112. sinusFaps->unwrapPhaseMap(wrappedPhaseMap, unwrappedPhaseMap, Size(captures[0].cols, captures[1].rows), shadowMask);
  113. unwrappedPhaseMap.convertTo(unwrappedPhaseMap8, CV_8U, 1, 128);
  114. sumOfDiff = 0;
  115. count = 0;
  116. ratio = 0;
  117. for( int i = 0; i < unwrappedPhaseMap8.rows; ++i )
  118. {
  119. for( int j = 0; j < unwrappedPhaseMap8.cols; ++j )
  120. {
  121. int ref = unwrappedPhaseMapFapsRef.at<uchar>(i, j);
  122. int comp = unwrappedPhaseMap8.at<uchar>(i, j);
  123. sumOfDiff += (ref - comp);
  124. count ++;
  125. }
  126. }
  127. ratio = (float)(sumOfDiff / count);
  128. EXPECT_LE( ratio, 0.003 );
  129. }
  130. }} // namespace