test_affine3.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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) 2000-2008, Intel Corporation, all rights reserved.
  14. // Copyright (C) 2008-2013, Willow Garage Inc., all rights reserved.
  15. // Third party copyrights are property of their respective owners.
  16. //
  17. // Redistribution and use in source and binary forms, with or without modification,
  18. // are permitted provided that the following conditions are met:
  19. //
  20. // * Redistribution's of source code must retain the above copyright notice,
  21. // this list of conditions and the following disclaimer.
  22. //
  23. // * Redistribution's in binary form must reproduce the above copyright notice,
  24. // this list of conditions and the following disclaimer in the documentation
  25. // and / or other materials provided with the distribution.
  26. //
  27. // * The name of the copyright holders may not be used to endorse or promote products
  28. // derived from this software without specific prior written permission.
  29. //
  30. // This software is provided by the copyright holders and contributors "as is" and
  31. // any express or implied warranties, including, but not limited to, the implied
  32. // warranties of merchantability and fitness for a particular purpose are disclaimed.
  33. // In no event shall the Intel Corporation or contributors be liable for any direct,
  34. // indirect, incidental, special, exemplary, or consequential damages
  35. // (including, but not limited to, procurement of substitute goods or services;
  36. // loss of use, data, or profits; or business interruption) however caused
  37. // and on any theory of liability, whether in contract, strict liability,
  38. // or tort (including negligence or otherwise) arising in any way out of
  39. // the use of this software, even if advised of the possibility of such damage.
  40. //
  41. //M*/
  42. #include "test_precomp.hpp"
  43. #include "opencv2/core/affine.hpp"
  44. namespace opencv_test { namespace {
  45. TEST(Calib3d_Affine3f, accuracy)
  46. {
  47. const double eps = 1e-5;
  48. cv::Vec3d rvec(0.2, 0.5, 0.3);
  49. cv::Affine3d affine(rvec);
  50. cv::Mat expected;
  51. cv::Rodrigues(rvec, expected);
  52. ASSERT_LE(cvtest::norm(cv::Mat(affine.matrix, false).colRange(0, 3).rowRange(0, 3), expected, cv::NORM_L2), eps);
  53. ASSERT_LE(cvtest::norm(cv::Mat(affine.linear()), expected, cv::NORM_L2), eps);
  54. cv::Matx33d R = cv::Matx33d::eye();
  55. double angle = 50;
  56. R.val[0] = R.val[4] = std::cos(CV_PI*angle/180.0);
  57. R.val[3] = std::sin(CV_PI*angle/180.0);
  58. R.val[1] = -R.val[3];
  59. cv::Affine3d affine1(cv::Mat(cv::Vec3d(0.2, 0.5, 0.3)).reshape(1, 1), cv::Vec3d(4, 5, 6));
  60. cv::Affine3d affine2(R, cv::Vec3d(1, 1, 0.4));
  61. cv::Affine3d result = affine1.inv() * affine2;
  62. expected = cv::Mat(affine1.matrix.inv(cv::DECOMP_SVD)) * cv::Mat(affine2.matrix, false);
  63. cv::Mat diff;
  64. cv::absdiff(expected, result.matrix, diff);
  65. ASSERT_LT(cvtest::norm(diff, cv::NORM_INF), 1e-15);
  66. }
  67. TEST(Calib3d_Affine3f, accuracy_rvec)
  68. {
  69. cv::RNG rng;
  70. typedef float T;
  71. cv::Affine3<T>::Vec3 w;
  72. cv::Affine3<T>::Mat3 u, vt, R;
  73. for(int i = 0; i < 100; ++i)
  74. {
  75. rng.fill(R, cv::RNG::UNIFORM, -10, 10, true);
  76. cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A);
  77. R = u * vt;
  78. //double s = (double)cv::getTickCount();
  79. cv::Affine3<T>::Vec3 va = cv::Affine3<T>(R).rvec();
  80. //std::cout << "M:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;
  81. cv::Affine3<T>::Vec3 vo;
  82. //s = (double)cv::getTickCount();
  83. cv::Rodrigues(R, vo);
  84. //std::cout << "O:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;
  85. ASSERT_LT(cvtest::norm(va, vo, cv::NORM_L2), 1e-9);
  86. }
  87. }
  88. }} // namespace