forked from bkarwoski/pnp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpnp_ransac.h
116 lines (91 loc) · 2.4 KB
/
pnp_ransac.h
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
105
106
107
108
109
110
111
112
113
#pragma once
/* ********************************* FILE ************************************/
/** \file klas.pnp.h
*
* \brief This header contains a standard RANSAC pnp solver wrapping the p3p solver by klas.
*
*
* Single refinement of the minimal case solution with a maximum number of inliers or lowest total cutoff error(MLESAC)
*
*
* \remark
* - c++11
* - can fail
* - tested by test_pnp.cpp
*
* Dependencies:
* - ceres solver
*
* \todo
* -losac
* -pose priors
*
*
*
* \author Mikael Persson
* \date 2016-04-01
* \note MIT licence
*
******************************************************************************/
#include <utils/cvl/pose.h>
#include <parameters.h>
namespace cvl {
/**
* @brief pnp_ransac returns Pcw such that X_cam=Pcw*X_world
* @param xs 3d point in world coordinates
* @param yns normalized camera measurements
* @param params, note adjust threshold if neccesary
* @return
*/
PoseD pnp_ransac(const std::vector<cvl::Vector3D>& xs,
const std::vector<cvl::Vector2D>& yns,
const PnpParams& params);
/**
* @brief The PNP class A basic RANSAC PNP solver
*
* Result=est.compute()
* Pcw=Result.best_pose
* X_c=Pcw*X_w
*/
class PNP{
public:
/**
* @brief PNP constructor given a PnpParam object
* @param params
* @param xs 3d points
* @param yns pinhole normalized 2d measurements
*
* copy is cheap, but if this is really the problem, fix later...
*/
PNP(const std::vector<cvl::Vector3D>& xs,
const std::vector<cvl::Vector2D>& yns,
PnpParams params ):xs(xs), yns(yns),params(params){}
uint total_iters=0;
/// attempts to compute the solution
PoseD compute();
std::vector<int> const& getInliers() const
{
if (inliers.empty())
{
// return nullptr;
}
return inliers;
}
protected:
/// refine a given pose given the stored data, @param pose
void refine();
// initialize
/// the known 3d positions in world coordinates
std::vector<cvl::Vector3D> xs;
/// the pinhole normalized measurements corresp to xs
std::vector<cvl::Vector2D> yns;
// inlier indices
std::vector<int> inliers;
/// parmeter block
PnpParams params;
/// number of inliers of best solution
uint best_inliers=0;
/// the best pose so far
cvl::PoseD best_pose;
};
} // end namespace cvl