Path: blob/master/modules/calib3d/test/test_affine3.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.3//4// By downloading, copying, installing or using the software you agree to this license.5// If you do not agree to this license, do not download, install,6// copy or use the software.7//8//9// License Agreement10// For Open Source Computer Vision Library11//12// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.13// Copyright (C) 2008-2013, Willow Garage Inc., 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 documentation24// and / or other materials provided with the distribution.25//26// * The name of the copyright holders may not be used to endorse or promote products27// derived from this software without specific prior written permission.28//29// This software is provided by the copyright holders and contributors "as is" and30// any express or implied warranties, including, but not limited to, the implied31// 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 damages34// (including, but not limited to, procurement of substitute goods or services;35// loss of use, data, or profits; or business interruption) however caused36// and on any theory of liability, whether in contract, strict liability,37// or tort (including negligence or otherwise) arising in any way out of38// the use of this software, even if advised of the possibility of such damage.39//40//M*/4142#include "test_precomp.hpp"43#include "opencv2/core/affine.hpp"4445namespace opencv_test { namespace {4647TEST(Calib3d_Affine3f, accuracy)48{49const double eps = 1e-5;50cv::Vec3d rvec(0.2, 0.5, 0.3);51cv::Affine3d affine(rvec);5253cv::Mat expected;54cv::Rodrigues(rvec, expected);5556ASSERT_LE(cvtest::norm(cv::Mat(affine.matrix, false).colRange(0, 3).rowRange(0, 3), expected, cv::NORM_L2), eps);57ASSERT_LE(cvtest::norm(cv::Mat(affine.linear()), expected, cv::NORM_L2), eps);5859cv::Matx33d R = cv::Matx33d::eye();6061double angle = 50;62R.val[0] = R.val[4] = std::cos(CV_PI*angle/180.0);63R.val[3] = std::sin(CV_PI*angle/180.0);64R.val[1] = -R.val[3];656667cv::Affine3d affine1(cv::Mat(cv::Vec3d(0.2, 0.5, 0.3)).reshape(1, 1), cv::Vec3d(4, 5, 6));68cv::Affine3d affine2(R, cv::Vec3d(1, 1, 0.4));6970cv::Affine3d result = affine1.inv() * affine2;7172expected = cv::Mat(affine1.matrix.inv(cv::DECOMP_SVD)) * cv::Mat(affine2.matrix, false);737475cv::Mat diff;76cv::absdiff(expected, result.matrix, diff);7778ASSERT_LT(cvtest::norm(diff, cv::NORM_INF), 1e-15);79}8081TEST(Calib3d_Affine3f, accuracy_rvec)82{83cv::RNG rng;84typedef float T;8586cv::Affine3<T>::Vec3 w;87cv::Affine3<T>::Mat3 u, vt, R;8889for(int i = 0; i < 100; ++i)90{91rng.fill(R, cv::RNG::UNIFORM, -10, 10, true);92cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A);93R = u * vt;9495//double s = (double)cv::getTickCount();96cv::Affine3<T>::Vec3 va = cv::Affine3<T>(R).rvec();97//std::cout << "M:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;9899cv::Affine3<T>::Vec3 vo;100//s = (double)cv::getTickCount();101cv::Rodrigues(R, vo);102//std::cout << "O:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;103104ASSERT_LT(cvtest::norm(va, vo, cv::NORM_L2), 1e-9);105}106}107108}} // namespace109110111