1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
// Copyright (c) 2020 libmv authors.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
#ifndef LIBMV_SIMPLE_PIPELINE_PACKED_INTRINSICS_H_
#define LIBMV_SIMPLE_PIPELINE_PACKED_INTRINSICS_H_
#include "libmv/base/array.h"
namespace libmv {
// Intrinsics parameters packed into a single continuous block of memory.
// Used in cases like minimization problems which involves camera intrinsics
// as a minimizing parameters.
//
// It keeps track of which parameters has been specified explicitly, which
// allows to mark parameters which are not used by distortion model as constant,
// which improves minimization quality.
class PackedIntrinsics {
public:
// Offsets of corresponding parameters in the array of all parameters.
enum {
// Camera calibration values.
OFFSET_FOCAL_LENGTH,
OFFSET_PRINCIPAL_POINT_X,
OFFSET_PRINCIPAL_POINT_Y,
// Distortion model coefficients.
OFFSET_K1,
OFFSET_K2,
OFFSET_K3,
OFFSET_K4,
OFFSET_P1,
OFFSET_P2,
// Number of parameters which are to be stored in the block.
NUM_PARAMETERS,
};
PackedIntrinsics();
void SetFocalLength(double focal_length);
double GetFocalLength() const;
void SetPrincipalPoint(double x, double y);
double GetPrincipalPointX() const;
double GetPrincipalPointY() const;
// TODO(sergey): Consider adding vectorized (Vec2) accessors for the principal
// point.
#define DEFINE_PARAMETER(parameter_name) \
void Set ## parameter_name(double value) { \
SetParameter(OFFSET_ ## parameter_name, value); \
} \
double Get ## parameter_name() const { \
return GetParameter(OFFSET_ ## parameter_name); \
} \
DEFINE_PARAMETER(K1)
DEFINE_PARAMETER(K2)
DEFINE_PARAMETER(K3)
DEFINE_PARAMETER(K4)
DEFINE_PARAMETER(P1)
DEFINE_PARAMETER(P2)
#undef DEFINE_PARAMETER
double* GetParametersBlock() { return parameters_.data(); }
const double* GetParametersBlock() const { return parameters_.data(); }
private:
void SetParameter(int index, double value);
double GetParameter(int index) const;
// All intrinsics parameters packed into a single block.
// Use OFFSET_FOO indexes to access corresponding values.
array<double, NUM_PARAMETERS> parameters_;
// Indexed by parameter offset, set to truth if the value of the parameter is
// explicitly specified.
array<bool, NUM_PARAMETERS> known_parameters_;
};
} // namespace libmv
#endif // LIBMV_SIMPLE_PIPELINE_PACKED_INTRINSICS_H_
|