Home | History | Annotate | Download | only in test
      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 
     43 #include "test_precomp.hpp"
     44 #include "opencv2/core/affine.hpp"
     45 #include "opencv2/calib3d.hpp"
     46 #include <iostream>
     47 
     48 TEST(Calib3d_Affine3f, accuracy)
     49 {
     50     cv::Vec3d rvec(0.2, 0.5, 0.3);
     51     cv::Affine3d affine(rvec);
     52 
     53     cv::Mat expected;
     54     cv::Rodrigues(rvec, expected);
     55 
     56 
     57     ASSERT_EQ(0, cvtest::norm(cv::Mat(affine.matrix, false).colRange(0, 3).rowRange(0, 3) != expected, cv::NORM_L2));
     58     ASSERT_EQ(0, cvtest::norm(cv::Mat(affine.linear()) != expected, cv::NORM_L2));
     59 
     60 
     61     cv::Matx33d R = cv::Matx33d::eye();
     62 
     63     double angle = 50;
     64     R.val[0] = R.val[4] = std::cos(CV_PI*angle/180.0);
     65     R.val[3] = std::sin(CV_PI*angle/180.0);
     66     R.val[1] = -R.val[3];
     67 
     68 
     69     cv::Affine3d affine1(cv::Mat(cv::Vec3d(0.2, 0.5, 0.3)).reshape(1, 1), cv::Vec3d(4, 5, 6));
     70     cv::Affine3d affine2(R, cv::Vec3d(1, 1, 0.4));
     71 
     72     cv::Affine3d result = affine1.inv() * affine2;
     73 
     74     expected = cv::Mat(affine1.matrix.inv(cv::DECOMP_SVD)) * cv::Mat(affine2.matrix, false);
     75 
     76 
     77     cv::Mat diff;
     78     cv::absdiff(expected, result.matrix, diff);
     79 
     80     ASSERT_LT(cvtest::norm(diff, cv::NORM_INF), 1e-15);
     81 }
     82 
     83 TEST(Calib3d_Affine3f, accuracy_rvec)
     84 {
     85     cv::RNG rng;
     86     typedef float T;
     87 
     88     cv::Affine3<T>::Vec3 w;
     89     cv::Affine3<T>::Mat3 u, vt, R;
     90 
     91     for(int i = 0; i < 100; ++i)
     92     {
     93         rng.fill(R, cv::RNG::UNIFORM, -10, 10, true);
     94         cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A);
     95         R = u * vt;
     96 
     97         //double s = (double)cv::getTickCount();
     98         cv::Affine3<T>::Vec3 va = cv::Affine3<T>(R).rvec();
     99         //std::cout << "M:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;
    100 
    101         cv::Affine3<T>::Vec3 vo;
    102         //s = (double)cv::getTickCount();
    103         cv::Rodrigues(R, vo);
    104         //std::cout << "O:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;
    105 
    106         ASSERT_LT(cvtest::norm(va, vo, cv::NORM_L2), 1e-9);
    107     }
    108 }
    109