Path: blob/master/modules/calib3d/test/test_homography_decomp.cpp
16337 views
/*M///////////////////////////////////////////////////////////////////////////////////////1//2// This is a test file for the function decomposeHomography contributed to OpenCV3// by Samson Yilma.4//5// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.6//7// By downloading, copying, installing or using the software you agree to this license.8// If you do not agree to this license, do not download, install,9// copy or use the software.10//11//12// License Agreement13// For Open Source Computer Vision Library14//15// Copyright (C) 2014, Samson Yilma ([email protected]), all rights reserved.16//17// Third party copyrights are property of their respective owners.18//19// Redistribution and use in source and binary forms, with or without modification,20// are permitted provided that the following conditions are met:21//22// * Redistribution's of source code must retain the above copyright notice,23// this list of conditions and the following disclaimer.24//25// * Redistribution's in binary form must reproduce the above copyright notice,26// this list of conditions and the following disclaimer in the documentation27// and/or other materials provided with the distribution.28//29// * The name of the copyright holders may not be used to endorse or promote products30// derived from this software without specific prior written permission.31//32// This software is provided by the copyright holders and contributors "as is" and33// any express or implied warranties, including, but not limited to, the implied34// warranties of merchantability and fitness for a particular purpose are disclaimed.35// In no event shall the Intel Corporation or contributors be liable for any direct,36// indirect, incidental, special, exemplary, or consequential damages37// (including, but not limited to, procurement of substitute goods or services;38// loss of use, data, or profits; or business interruption) however caused39// and on any theory of liability, whether in contract, strict liability,40// or tort (including negligence or otherwise) arising in any way out of41// the use of this software, even if advised of the possibility of such damage.42//43//M*/4445#include "test_precomp.hpp"4647namespace opencv_test { namespace {4849class CV_HomographyDecompTest: public cvtest::BaseTest {5051public:52CV_HomographyDecompTest()53{54buildTestDataSet();55}5657protected:58void run(int)59{60vector<Mat> rotations;61vector<Mat> translations;62vector<Mat> normals;6364decomposeHomographyMat(_H, _K, rotations, translations, normals);6566//there should be at least 1 solution67ASSERT_GT(static_cast<int>(rotations.size()), 0);68ASSERT_GT(static_cast<int>(translations.size()), 0);69ASSERT_GT(static_cast<int>(normals.size()), 0);7071ASSERT_EQ(rotations.size(), normals.size());72ASSERT_EQ(translations.size(), normals.size());7374ASSERT_TRUE(containsValidMotion(rotations, translations, normals));7576decomposeHomographyMat(_H, _K, rotations, noArray(), noArray());77ASSERT_GT(static_cast<int>(rotations.size()), 0);78}7980private:8182void buildTestDataSet()83{84_K = Matx33d(640, 0.0, 320,850, 640, 240,860, 0, 1);8788_H = Matx33d(2.649157564634028, 4.583875997496426, 70.694447785121326,89-1.072756858861583, 3.533262150437228, 1513.656999614321649,900.001303887589576, 0.003042206876298, 1.00000000000000091);9293//expected solution for the given homography and intrinsic matrices94_R = Matx33d(0.43307983549125, 0.545749113549648, -0.717356090899523,95-0.85630229674426, 0.497582023798831, -0.138414255706431,960.281404038139784, 0.67421809131173, 0.682818960388909);9798_t = Vec3d(1.826751712278038, 1.264718492450820, 0.195080809998819);99_n = Vec3d(0.244875830334816, 0.480857890778889, 0.841909446789566);100}101102bool containsValidMotion(std::vector<Mat>& rotations,103std::vector<Mat>& translations,104std::vector<Mat>& normals105)106{107double max_error = 1.0e-3;108109vector<Mat>::iterator riter = rotations.begin();110vector<Mat>::iterator titer = translations.begin();111vector<Mat>::iterator niter = normals.begin();112113for (;114riter != rotations.end() && titer != translations.end() && niter != normals.end();115++riter, ++titer, ++niter) {116117double rdist = cvtest::norm(*riter, _R, NORM_INF);118double tdist = cvtest::norm(*titer, _t, NORM_INF);119double ndist = cvtest::norm(*niter, _n, NORM_INF);120121if ( rdist < max_error122&& tdist < max_error123&& ndist < max_error )124return true;125}126127return false;128}129130Matx33d _R, _K, _H;131Vec3d _t, _n;132};133134TEST(Calib3d_DecomposeHomography, regression) { CV_HomographyDecompTest test; test.safe_run(); }135136}} // namespace137138139