Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/calib3d/test/test_affine3.cpp
16337 views
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
46
namespace opencv_test { namespace {
47
48
TEST(Calib3d_Affine3f, accuracy)
49
{
50
const double eps = 1e-5;
51
cv::Vec3d rvec(0.2, 0.5, 0.3);
52
cv::Affine3d affine(rvec);
53
54
cv::Mat expected;
55
cv::Rodrigues(rvec, expected);
56
57
ASSERT_LE(cvtest::norm(cv::Mat(affine.matrix, false).colRange(0, 3).rowRange(0, 3), expected, cv::NORM_L2), eps);
58
ASSERT_LE(cvtest::norm(cv::Mat(affine.linear()), expected, cv::NORM_L2), eps);
59
60
cv::Matx33d R = cv::Matx33d::eye();
61
62
double angle = 50;
63
R.val[0] = R.val[4] = std::cos(CV_PI*angle/180.0);
64
R.val[3] = std::sin(CV_PI*angle/180.0);
65
R.val[1] = -R.val[3];
66
67
68
cv::Affine3d affine1(cv::Mat(cv::Vec3d(0.2, 0.5, 0.3)).reshape(1, 1), cv::Vec3d(4, 5, 6));
69
cv::Affine3d affine2(R, cv::Vec3d(1, 1, 0.4));
70
71
cv::Affine3d result = affine1.inv() * affine2;
72
73
expected = cv::Mat(affine1.matrix.inv(cv::DECOMP_SVD)) * cv::Mat(affine2.matrix, false);
74
75
76
cv::Mat diff;
77
cv::absdiff(expected, result.matrix, diff);
78
79
ASSERT_LT(cvtest::norm(diff, cv::NORM_INF), 1e-15);
80
}
81
82
TEST(Calib3d_Affine3f, accuracy_rvec)
83
{
84
cv::RNG rng;
85
typedef float T;
86
87
cv::Affine3<T>::Vec3 w;
88
cv::Affine3<T>::Mat3 u, vt, R;
89
90
for(int i = 0; i < 100; ++i)
91
{
92
rng.fill(R, cv::RNG::UNIFORM, -10, 10, true);
93
cv::SVD::compute(R, w, u, vt, cv::SVD::FULL_UV + cv::SVD::MODIFY_A);
94
R = u * vt;
95
96
//double s = (double)cv::getTickCount();
97
cv::Affine3<T>::Vec3 va = cv::Affine3<T>(R).rvec();
98
//std::cout << "M:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;
99
100
cv::Affine3<T>::Vec3 vo;
101
//s = (double)cv::getTickCount();
102
cv::Rodrigues(R, vo);
103
//std::cout << "O:" <<(cv::getTickCount() - s)*1000/cv::getTickFrequency() << std::endl;
104
105
ASSERT_LT(cvtest::norm(va, vo, cv::NORM_L2), 1e-9);
106
}
107
}
108
109
}} // namespace
110
111