Path: blob/master/modules/calib3d/test/test_compose_rt.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) 2009, 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"4344namespace opencv_test { namespace {4546class Differential47{48public:49typedef Mat_<double> mat_t;5051Differential(double eps_, const mat_t& rv1_, const mat_t& tv1_, const mat_t& rv2_, const mat_t& tv2_)52: rv1(rv1_), tv1(tv1_), rv2(rv2_), tv2(tv2_), eps(eps_), ev(3, 1) {}5354void dRv1(mat_t& dr3_dr1, mat_t& dt3_dr1)55{56dr3_dr1.create(3, 3); dt3_dr1.create(3, 3);5758for(int i = 0; i < 3; ++i)59{60ev.setTo(Scalar(0)); ev(i, 0) = eps;6162composeRT( rv1 + ev, tv1, rv2, tv2, rv3_p, tv3_p);63composeRT( rv1 - ev, tv1, rv2, tv2, rv3_m, tv3_m);6465dr3_dr1.col(i) = rv3_p - rv3_m;66dt3_dr1.col(i) = tv3_p - tv3_m;67}68dr3_dr1 /= 2 * eps; dt3_dr1 /= 2 * eps;69}7071void dRv2(mat_t& dr3_dr2, mat_t& dt3_dr2)72{73dr3_dr2.create(3, 3); dt3_dr2.create(3, 3);7475for(int i = 0; i < 3; ++i)76{77ev.setTo(Scalar(0)); ev(i, 0) = eps;7879composeRT( rv1, tv1, rv2 + ev, tv2, rv3_p, tv3_p);80composeRT( rv1, tv1, rv2 - ev, tv2, rv3_m, tv3_m);8182dr3_dr2.col(i) = rv3_p - rv3_m;83dt3_dr2.col(i) = tv3_p - tv3_m;84}85dr3_dr2 /= 2 * eps; dt3_dr2 /= 2 * eps;86}8788void dTv1(mat_t& drt3_dt1, mat_t& dt3_dt1)89{90drt3_dt1.create(3, 3); dt3_dt1.create(3, 3);9192for(int i = 0; i < 3; ++i)93{94ev.setTo(Scalar(0)); ev(i, 0) = eps;9596composeRT( rv1, tv1 + ev, rv2, tv2, rv3_p, tv3_p);97composeRT( rv1, tv1 - ev, rv2, tv2, rv3_m, tv3_m);9899drt3_dt1.col(i) = rv3_p - rv3_m;100dt3_dt1.col(i) = tv3_p - tv3_m;101}102drt3_dt1 /= 2 * eps; dt3_dt1 /= 2 * eps;103}104105void dTv2(mat_t& dr3_dt2, mat_t& dt3_dt2)106{107dr3_dt2.create(3, 3); dt3_dt2.create(3, 3);108109for(int i = 0; i < 3; ++i)110{111ev.setTo(Scalar(0)); ev(i, 0) = eps;112113composeRT( rv1, tv1, rv2, tv2 + ev, rv3_p, tv3_p);114composeRT( rv1, tv1, rv2, tv2 - ev, rv3_m, tv3_m);115116dr3_dt2.col(i) = rv3_p - rv3_m;117dt3_dt2.col(i) = tv3_p - tv3_m;118}119dr3_dt2 /= 2 * eps; dt3_dt2 /= 2 * eps;120}121122private:123const mat_t& rv1, tv1, rv2, tv2;124double eps;125Mat_<double> ev;126127Differential& operator=(const Differential&);128Mat rv3_m, tv3_m, rv3_p, tv3_p;129};130131class CV_composeRT_Test : public cvtest::BaseTest132{133public:134CV_composeRT_Test() {}135~CV_composeRT_Test() {}136protected:137138void run(int)139{140ts->set_failed_test_info(cvtest::TS::OK);141142Mat_<double> rvec1(3, 1), tvec1(3, 1), rvec2(3, 1), tvec2(3, 1);143144randu(rvec1, Scalar(0), Scalar(6.29));145randu(rvec2, Scalar(0), Scalar(6.29));146147randu(tvec1, Scalar(-2), Scalar(2));148randu(tvec2, Scalar(-2), Scalar(2));149150Mat rvec3, tvec3;151composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3);152153Mat rvec3_exp, tvec3_exp;154155Mat rmat1, rmat2;156cv::Rodrigues(rvec1, rmat1); // TODO cvtest157cv::Rodrigues(rvec2, rmat2); // TODO cvtest158cv::Rodrigues(rmat2 * rmat1, rvec3_exp); // TODO cvtest159160tvec3_exp = rmat2 * tvec1 + tvec2;161162const double thres = 1e-5;163if (cv::norm(rvec3_exp, rvec3) > thres || cv::norm(tvec3_exp, tvec3) > thres)164ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);165166const double eps = 1e-3;167Differential diff(eps, rvec1, tvec1, rvec2, tvec2);168169Mat dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2;170171composeRT(rvec1, tvec1, rvec2, tvec2, rvec3, tvec3,172dr3dr1, dr3dt1, dr3dr2, dr3dt2, dt3dr1, dt3dt1, dt3dr2, dt3dt2);173174Mat_<double> dr3_dr1, dt3_dr1;175diff.dRv1(dr3_dr1, dt3_dr1);176177if (cv::norm(dr3_dr1, dr3dr1) > thres || cv::norm(dt3_dr1, dt3dr1) > thres)178{179ts->printf( cvtest::TS::LOG, "Invalid derivates by r1\n" );180ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);181}182183Mat_<double> dr3_dr2, dt3_dr2;184diff.dRv2(dr3_dr2, dt3_dr2);185186if (cv::norm(dr3_dr2, dr3dr2) > thres || cv::norm(dt3_dr2, dt3dr2) > thres)187{188ts->printf( cvtest::TS::LOG, "Invalid derivates by r2\n" );189ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);190}191192Mat_<double> dr3_dt1, dt3_dt1;193diff.dTv1(dr3_dt1, dt3_dt1);194195if (cv::norm(dr3_dt1, dr3dt1) > thres || cv::norm(dt3_dt1, dt3dt1) > thres)196{197ts->printf( cvtest::TS::LOG, "Invalid derivates by t1\n" );198ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);199}200201Mat_<double> dr3_dt2, dt3_dt2;202diff.dTv2(dr3_dt2, dt3_dt2);203204if (cv::norm(dr3_dt2, dr3dt2) > thres || cv::norm(dt3_dt2, dt3dt2) > thres)205{206ts->printf( cvtest::TS::LOG, "Invalid derivates by t2\n" );207ts->set_failed_test_info(cvtest::TS::FAIL_BAD_ACCURACY);208}209}210};211212TEST(Calib3d_ComposeRT, accuracy) { CV_composeRT_Test test; test.safe_run(); }213214}} // namespace215216217