161
|
1 /**
|
|
2 * Stone of Orthanc
|
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
|
|
4 * Department, University Hospital of Liege, Belgium
|
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
|
|
6 *
|
|
7 * This program is free software: you can redistribute it and/or
|
|
8 * modify it under the terms of the GNU Affero General Public License
|
|
9 * as published by the Free Software Foundation, either version 3 of
|
|
10 * the License, or (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful, but
|
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 * Affero General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU Affero General Public License
|
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 **/
|
|
20
|
|
21
|
|
22 #pragma once
|
|
23
|
|
24 #include "LinearAlgebra.h"
|
|
25
|
|
26 namespace OrthancStone
|
|
27 {
|
|
28 // Reference: "Multiple View Geometry in Computer Vision (2nd Edition)"
|
|
29 class FiniteProjectiveCamera : public boost::noncopyable
|
|
30 {
|
|
31 private:
|
|
32 Matrix p_; // 3x4 matrix - Equation (6.11) - page 157
|
|
33 Matrix k_; // 3x3 matrix of intrinsic parameters - Equation (6.10) - page 157
|
|
34 Matrix r_; // 3x3 rotation matrix in 3D space
|
|
35 Vector c_; // 3x1 vector in 3D space corresponding to camera center
|
|
36 Matrix minv_; // Inverse of the M = P(1:3,1:3) submatrix
|
|
37
|
|
38 void ComputeMInverse();
|
|
39
|
|
40 void Setup(const Matrix& k,
|
|
41 const Matrix& r,
|
|
42 const Vector& c);
|
|
43
|
|
44 void Setup(const Matrix& p);
|
|
45
|
|
46 public:
|
|
47 FiniteProjectiveCamera(const Matrix& k,
|
|
48 const Matrix& r,
|
|
49 const Vector& c)
|
|
50 {
|
|
51 Setup(k, r, c);
|
|
52 }
|
|
53
|
|
54 FiniteProjectiveCamera(const Matrix& p)
|
|
55 {
|
|
56 Setup(p);
|
|
57 }
|
|
58
|
|
59 FiniteProjectiveCamera(const double k[9],
|
|
60 const double r[9],
|
|
61 const double c[3]);
|
|
62
|
|
63 FiniteProjectiveCamera(const double p[12]);
|
|
64
|
|
65 const Matrix& GetMatrix() const
|
|
66 {
|
|
67 return p_;
|
|
68 }
|
|
69
|
|
70 const Matrix& GetRotation() const
|
|
71 {
|
|
72 return r_;
|
|
73 }
|
|
74
|
|
75 const Vector& GetCenter() const
|
|
76 {
|
|
77 return c_;
|
|
78 }
|
|
79
|
|
80 const Matrix& GetIntrinsicParameters() const
|
|
81 {
|
|
82 return k_;
|
|
83 }
|
|
84
|
|
85 // Computes the 3D vector that represents the direction from the
|
|
86 // camera center to the (x,y) imaged point
|
|
87 Vector GetRayDirection(double x,
|
|
88 double y) const;
|
|
89
|
|
90 // Apply the camera to a 3D point "v" that is not at infinity. "v"
|
|
91 // can be encoded either as a non-homogeneous vector (3
|
|
92 // components), or as a homogeneous vector (4 components).
|
|
93 void ApplyFinite(double& x,
|
|
94 double& y,
|
|
95 const Vector& v) const;
|
|
96
|
|
97 // Apply the camera to a 3D point "v" that is possibly at
|
|
98 // infinity. The result is a 2D point in homogeneous coordinates.
|
|
99 Vector ApplyGeneral(const Vector& v) const;
|
|
100 };
|
|
101 }
|