Blender V4.3
resection_test.cc
Go to the documentation of this file.
1// Copyright (c) 2009 libmv authors.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to
5// deal in the Software without restriction, including without limitation the
6// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7// sell copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19// IN THE SOFTWARE.
20
21#include <iostream>
22
28#include "testing/testing.h"
29
30namespace {
31
32using namespace libmv;
33using namespace libmv::resection;
34
35TEST(Resection, ThreeViews) {
36 int nviews = 5;
37 int npoints = 6;
38 NViewDataSet d = NRealisticCamerasFull(nviews, npoints);
39 for (int i = 0; i < nviews; ++i) {
40 Mat4X X(4, npoints);
41 X.block(0, 0, 3, npoints) = d.X;
42 X.row(3).setOnes();
43 const Mat2X& x = d.x[i];
44 Mat34 P;
45 Resection(x, X, &P);
46 Mat34 P_expected = d.P(i);
47
48 // Because the P matrices are homogeneous, it is necessary to be tricky
49 // about the scale factor to make them match.
50 P_expected *= 1 / P_expected.array().abs().sum();
51 P *= 1 / P.array().abs().sum();
52 if (!((P(0, 0) > 0 && P_expected(0, 0) > 0) ||
53 (P(0, 0) < 0 && P_expected(0, 0) < 0))) {
54 P *= -1;
55 }
56
57 EXPECT_MATRIX_NEAR(P_expected, P, 1e-9);
58 }
59}
60
61} // namespace
#define X
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
void Resection(const Matrix< T, 2, Dynamic > &x, const Matrix< T, 4, Dynamic > &X, Matrix< T, 3, 4 > *P)
Definition resection.h:37
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
Eigen::Matrix< double, 3, 4 > Mat34
Definition numeric.h:73
Eigen::Matrix< double, 4, Eigen::Dynamic > Mat4X
Definition numeric.h:93
NViewDataSet NRealisticCamerasFull(int nviews, int npoints, const nViewDatasetConfigator config)
Eigen::Matrix< double, 2, Eigen::Dynamic > Mat2X
Definition numeric.h:91
vector< Mat2X > x