47 #include <Base/Math/Random.hh>
48 #include <Geometry/AbsoluteOrientation.hh>
49 #include <Geometry/AbsoluteOrientationRANSAC.hh>
50 #include <Utils/Param.hh>
58 int main(
int argc,
char *argv[])
62 int* numParam = params.
AddParamInt(
"num",
"Number of 3D points", 10, 3,
63 std::numeric_limits<int>::max(),
'n', 0);
64 double* rangeParam = params.
AddParamDouble(
"range",
"Max. distance of 3D points "
65 "(in m)", 10.0, 1.e-8, 1e16,
'r', 0);
66 double* errorParam = params.
AddParamDouble(
"error",
"Max. error on 3D points "
67 "(in percent)", 0.01, 0.0, 1.0,
'e', 0);
68 bool* helpParam = params.
AddParamBool(
"help",
"Show help about parameters",
70 std::vector<std::string> methods;
71 std::vector<int> methodIDs;
72 methods.push_back(
"HORN");
73 methods.push_back(
"KABSCH");
76 int* methodParam = params.
AddParamEnum(
"method",
"Rotation estimation algorithm "
77 "(HORN, KABSCH)", methods, methodIDs[0],
86 unsigned int num = *numParam;
87 double range = *rangeParam;
88 double noise = *errorParam;
90 std::vector< BIAS::Vector3<double> > X;
91 std::vector< BIAS::Vector3<double> > Y;
95 cout <<
"- Compute absolute orientation from " << num <<
" 3D points";
96 if (noise > 0) cout <<
" with noise of " << 100.0*noise <<
"% using ";
98 cout <<
"Horn's method";
100 cout <<
"Kabsch algorithm";
102 cout <<
"undefined method";
103 cout <<
" for rotation estimation" << endl;
113 for (
unsigned int k = 0; k < 3; k++) {
122 cout <<
"- Rotation dR = " << dphi*180.0/M_PI <<
" degree around axis ("
123 << dr[0] <<
", " << dr[1] <<
", " << dr[2] <<
")" << endl;
124 cout <<
"- Translation dt = (" << dt[0] <<
", " << dt[1] <<
", "
125 << dt[2] <<
")" << endl;
126 cout <<
"- Scale ds = " << ds << endl;
133 for (
unsigned int i = 0; i < num; i++) {
134 for (
unsigned int k = 0; k < 3; k++) {
141 for (
unsigned int k = 0; k < 3; k++) {
150 cout <<
" [" << i+1 <<
"] X = (" << x[0] <<
", " << x[1] <<
", "
151 << x[2] <<
"), Y = (" << y[0] <<
", " << y[1] <<
", " << y[2] <<
")";
153 cout <<
", errors = " << errx.
NormL2() <<
" and " << erry.NormL2();
164 int res = estimator.
Compute(X, Y, estR, estt, ests);
166 cout <<
"[ERROR] Estimation failed!" << endl << endl;
173 double errphi, error;
174 std::vector<double> errors;
177 cout <<
"- Estimated rotation dR = " << estphi*180.0/M_PI
178 <<
" degree around axis (" << estr[0] <<
", " << estr[1] <<
", "
179 << estr[2] <<
")" <<
", error = " << errphi*180.0/M_PI
180 <<
" degree (" << 100.0*fabs(errphi-dphi)/dphi <<
"%)" << endl;
181 cout <<
"- Estimated translation dt = (" << estt[0] <<
", " << estt[1]
182 <<
", " << estt[2] <<
"), error = " << (estt-dt).NormL2() <<
" ("
183 << 100.0*(estt-dt).NormL2()/dt.
NormL2() <<
"%)" << endl;
184 cout <<
"- Estimated scale ds = " << ests <<
", error = "
185 << fabs(ests-ds) <<
" (" << 100.0*fabs(ests-ds)/ds <<
"%)" << endl;
186 cout <<
"- Average residual error of solution = "
187 << sqrt(error/(
double)num) << endl << endl;
Computes similarity transformation between 3D point sets.
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
double * AddParamDouble(const std::string &name, const std::string &help, double deflt=0.0, double min=-DBL_MAX, double max=DBL_MAX, char cmdshort=0, int Group=GRP_NOSHOW)
int * AddParamEnum(const std::string &name, const std::string &help, const std::vector< std::string > &enums, const int deflt=0, const std::vector< int > *IDs=NULL, const char cmdshort=0, const int Group=GRP_NOSHOW)
double GetUniformDistributed(const double min, const double max)
on succesive calls return uniform distributed random variable between min and max ...
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
void AddIP(const T &scalar)
Addition (in place) of an scalar.
double GetResidualErrors(std::vector< double > &errors, const std::vector< Vector3< double > > &X, const std::vector< Vector3< double > > &Y, const RMatrix &dR, const Vector3< double > &dt, const double &ds=1.0, const std::vector< double > &w=std::vector< double >(0))
Computes residual errors of 3D point sets X and Y with respect to given rotation dR, translation dt and isometric scale ds.
void SetFromAxisAngle(Vector3< ROTATION_MATRIX_TYPE > w)
Set from rotation axis * angle (modified Rodrigues vector)
This class Param provides generic support for parameters.
int SetGroupName(const int group_id, const std::string &name)
sets the name for a group
Matrix3x3< T > Transpose() const
returns transposed matrix tested 12.06.2002
void Reset()
calls srand() with a seed generated from system call time, also initializes some other variables ...
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
int GetRotationAxisAngle(Vector3< ROTATION_MATRIX_TYPE > &axis, ROTATION_MATRIX_TYPE &angle) const
Calculates angle and rotation axis representation for this rotation matrix.
double GetNormalDistributed(const double mean, const double sigma)
on succesive calls return normal distributed random variable with mean and standard deviation sigma ...
RotationEstimationMethod
Methods for rotation estimation.
void SetRotationAlgorithm(RotationEstimationMethod algorithm)
Set algorithm used for rotation estimation.
Vector3< T > & Normalize()
normalize this vector to length 1
class for producing random numbers from different distributions
double NormL2() const
the L2 norm sqrt(a^2 + b^2 + c^2)
int Compute(const std::vector< Vector3< double > > &X, const std::vector< Vector3< double > > &Y, RMatrix &dR, Vector3< double > &dt, double &ds, const std::vector< double > &w=std::vector< double >(0))
Computes rotation dR, translation dt and isometric scale ds between coordinate systems from correspon...