Skip to content

Commit 0af92d1

Browse files
author
deseilligny
committed
In doc several stuffs ...
1 parent 8886215 commit 0af92d1

File tree

6 files changed

+120
-63
lines changed

6 files changed

+120
-63
lines changed

MMVII/include/MMVII_Matrix.h

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,28 +1114,47 @@ template<class Type> cDenseVect<Type> EigenSolveLsqGC
11141114
int aNbVar
11151115
);
11161116

1117-
class cParamCtrNLsq
1117+
/** @brief class cParamCtrWeightedLSq : Parameter of control for Non Linear Square
1118+
*
1119+
* Make a decision of stop based on evolution of residual.
1120+
*/
1121+
1122+
class cParamCtrWeightedLSq
11181123
{
11191124
public :
11201125
/// Memorize a new error , and eventualy indicate statbility
11211126
bool StabilityAfterNextError(double) ;
1122-
cParamCtrNLsq();
1127+
1128+
/// constructor , default parameters for compatibility
1129+
cParamCtrWeightedLSq(tREAL8 aErrRelStop=1e-4,int aNbIterMax=10,int aNbIterMin=2);
11231130
private :
1124-
double GainRel(int aK1,int aK2) const; // ex GainRel(1,2)
1125-
inline double ValBack(int aK) const; // ex GainRel(1,2)
1126-
std::vector<double> mVER;
1131+
inline double ValBack(int aK) const; //< K the last value, ex : back for K=0
1132+
double GainRel(int aK1,int aK2) const; // relative gain for ValBack K1/K2
1133+
1134+
std::vector<double> mVER; //< Vector of accumumated errors
1135+
1136+
tREAL8 mErrRelStop; //< theshold for residual
1137+
int mNbIterMax; //< number max of iter after
1138+
int mNbIterMin; //< number in of iter after
1139+
11271140
};
11281141

1142+
/** Parameter for "global" control of optimizers, used for
1143+
* 2 step optimization :
1144+
* - first : initiall robust solution with Ransac
1145+
* - second : refinement with weighted least sqaures
1146+
*/
11291147
class cParamCtrlOpt
11301148
{
11311149
public :
1132-
cParamCtrlOpt(const cParamRansac &,const cParamCtrNLsq &);
1150+
cParamCtrlOpt(const cParamRansac &,const cParamCtrWeightedLSq &);
1151+
11331152
const cParamRansac & ParamRS() const;
1134-
const cParamCtrNLsq & ParamLSQ() const;
1153+
const cParamCtrWeightedLSq & ParamLSQ() const;
11351154
static cParamCtrlOpt Default();
11361155
private :
1137-
cParamRansac mParamRS;
1138-
cParamCtrNLsq mParamLSQ;
1156+
cParamRansac mParamRS; //< Parameter for the ransac part
1157+
cParamCtrWeightedLSq mParamLSQ;
11391158
};
11401159

11411160

MMVII/include/MMVII_util.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,23 @@ class cSetIExtension
410410
/** Generate Q subset of cardinal K [0,N], all different, if Q too big, truncated */
411411
void GenRanQsubCardKAmongN(std::vector<cSetIExtension> & aRes,int aQ,int aK,int aN);
412412

413+
/** Class to compute the number of test of Ransac, assumming :
414+
* o independance of errors
415+
* o a known probability of error of each sample
416+
* o a known target of acceptable global error
417+
* Also, all this hypothesis are questionnable, it's better than nothing ...
418+
*/
419+
413420
class cParamRansac
414421
{
415422
public :
416-
423+
/// given the number of sample required to compute a solution, return the number of tests to do
417424
int NbTestOfErrAdm(int aNbSample) const;
425+
/// constructor pretty basic
418426
cParamRansac(double aProba1Err,double anErrAdm);
419427
private :
420-
double mProba1Err;
421-
double mErrAdm;
428+
double mProba1Err; //< probability of error of each samples, assumed to be globally independant
429+
double mErrAdm; //< admissible global error
422430
};
423431

424432

MMVII/src/Geoms/GeomsMapEstimate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ template <class TypeMap>
201201
)
202202
{
203203
TypeMap aMap = RansacL1Estimate(aVIn,aVOut,aParam.ParamRS().NbTestOfErrAdm(TypeMap::NbPtsMin));
204-
cParamCtrNLsq aPLSq= aParam.ParamLSQ();
204+
cParamCtrWeightedLSq aPLSq= aParam.ParamLSQ();
205205

206206
tTypeElem aResidual;
207207
if (aPtrRes==nullptr)

MMVII/src/Perso/cMMVII_CatVideo.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ of concatenating video (in fact media mp4, mp3 ...).
1414
namespace MMVII
1515
{
1616

17+
template <class T1> class cTlpT1T2
18+
{
19+
public :
20+
template <class T2> void Test(const T2 & aT2);
21+
};
22+
23+
template <class T1> template <class T2>
24+
void cTlpT1T2<T1>::Test(const T2 & aT2)
25+
{
26+
StdOut() << " T2=" << aT2 << " T1=" << (T1) aT2 << "\n";
27+
}
28+
29+
void Test_T1T2()
30+
{
31+
cTlpT1T2<int> aTI;
32+
aTI.Test(3.14);
33+
}
34+
1735

1836
/* ==================================================== */
1937
/* */

MMVII/src/SymbDerGen/Formulas_BlockRigid.h

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88

99
// RIGIDBLOC : all file is concerned
1010

11+
namespace MMVII
12+
{
13+
using namespace NS_SymbolicDerivative;
1114

12-
/** Class for generating the bloc rigid equation :
15+
/**
16+
* @brief The cFormulaBlocRigid class, generate the equation for "rigid-pose".
17+
*
18+
* Class for generating the bloc rigid equation :
1319
*
1420
* Let PA and PB be two pose acquired with the rigid camera bloc,
1521
* Let P1 and P2 be the, "unknown", value of rigid bloc, we note {CA;RA}
@@ -50,10 +56,6 @@
5056
* {tRA(CB-CA); tRA*RB} = {tR1(C2-C1) ; tR1 * R2}
5157
*
5258
*/
53-
using namespace NS_SymbolicDerivative;
54-
55-
namespace MMVII
56-
{
5759

5860

5961
class cFormulaBlocRigid
@@ -63,79 +65,84 @@ class cFormulaBlocRigid
6365
std::string FormulaName() const { return "BlocRigid";}
6466

6567
std::vector<std::string> VNamesUnknowns() const
66-
{
67-
// We have 4 pose A,B,1 en 2; each has 6 unknown : 3 for centers,3 for axiator
68-
// We could write explicitely a 24 size vector like {"CxA","CyA","CzA","WxA" .....,"Wy2","Wz2"}
69-
// We prefer to use the facility "NamesPose"
70-
return Append(NamesPose("CA","WA"),NamesPose("CB","WB"),NamesPose("C1","W1"),NamesPose("C2","W2"));
68+
{
69+
// We have 4 pose A,B,1 en 2; each has 6 unknown : 3 for centers,3 for axiator
70+
// We could write explicitely a 24 size vector like {"CxA","CyA","CzA","WxA" .....,"Wy2","Wz2"}
71+
// We prefer to use the facility "NamesPose"
7172

72-
// Append NamesPose("CA","WA")
73-
}
73+
return Append
74+
(
75+
NamesPose("CA","WA"),
76+
NamesPose("CB","WB"),
77+
NamesPose("C1","W1"),
78+
NamesPose("C2","W2")
79+
);
80+
// Append NamesPose("CA","WA")
81+
}
7482

7583
std::vector<std::string> VNamesObs() const
7684
{
7785
// we have 4 pose, and for each we have the 3x3 current rotation matrix as "observation/context"
7886
// we coul wite explicitely the 36 size vector {"mA_00","mA_10" ... "m1_12","m_22"}
7987
// we prefer to use the facility ",NamesMatr"
8088
return Append(NamesMatr("mA",cPt2di(3,3)),NamesMatr("mB",cPt2di(3,3)),NamesMatr("m1",cPt2di(3,3)),NamesMatr("m2",cPt2di(3,3)));
81-
// Append NamesMatr("mA",cPt2di(3,3)),
89+
// Append NamesMatr("mA",cPt2di(3,3)),
8290
}
83-
static constexpr size_t NbUk =6;
84-
static constexpr size_t NbObs=9;
91+
static constexpr size_t NbUk =6;
92+
static constexpr size_t NbObs=9;
8593

86-
template <typename tUk>
94+
template <typename tUk>
8795
std::vector<tUk> formula
8896
(
8997
const std::vector<tUk> & aVUk,
9098
const std::vector<tUk> & aVObs
9199
) const
92100
{
101+
// create the 4 formal poses, using unkonw (C/W) and obs
93102
cPoseF<tUk> aPoseA(aVUk,0*NbUk,aVObs,0*NbObs,true);
94103
cPoseF<tUk> aPoseB(aVUk,1*NbUk,aVObs,1*NbObs,true);
95104
cPoseF<tUk> aPose1(aVUk,2*NbUk,aVObs,2*NbObs,true);
96105
cPoseF<tUk> aPose2(aVUk,3*NbUk,aVObs,3*NbObs,true);
97106

107+
// compute relative poses B/A and 2/1
98108
cPoseF<tUk> aRelAB = aPoseA.PoseRel(aPoseB);
99109
cPoseF<tUk> aRel12 = aPose1.PoseRel(aPose2);
100110

111+
// compute difference of centers and matrices
101112
cPtxd<tUk,3> aDeltaC = aRelAB.mCenter-aRel12.mCenter;
102113
cMatF<tUk> aDeltaR = aRelAB.mIJK-aRel12.mIJK;
103114

104-
105-
// ...
106-
// extract PoseA,PoseB,pose1, pose2
107-
108-
// compute pose rel B to A, pose rel 2 to 1
109-
// compute the difference
110-
111-
112-
return Append(ToVect(aDeltaC),aDeltaR.ToVect());
113-
114-
// cPoseF<tUk> aPose1(aVUk,2*NbUk,aVObs,2*NbObs);
115-
// cPoseF<tUk> aRelAB = aPoseA.PoseRel(aPoseB);
116-
// (ToVect(aDeltaC),aDeltaM.ToVect()
117-
}
118-
119-
120-
115+
// return the differences as a size-12 vector
116+
return Append
117+
(
118+
ToVect(aDeltaC),
119+
aDeltaR.ToVect()
120+
);
121+
}
121122
private :
122123
};
123124

125+
/**
126+
* @brief The cFormulaRattBRExist class for generating the conservation of a pose to a known value
127+
*
128+
* It is used in Block Rigid because the relative pose PA being an unknown we just have to write :
129+
* PA = P1
130+
* where P1 is the known value
131+
*/
132+
124133
class cFormulaRattBRExist
125134
{
126135
public :
127136

128-
std::string FormulaName() const { return "BlocRigid_RE";}
137+
std::string FormulaName() const { return "BlocRigid_RE";}
129138

130139
std::vector<std::string> VNamesUnknowns() const
131-
{
140+
{
132141
// We have 4 pose A,B,1 en 2; each has 6 unknown : 3 for centers,3 for axiator
133142
// We could write explicitely a 24 size vector like {"CxA","CyA","CzA","WxA" .....,"Wy2","Wz2"}
134-
// We prefer to use the facility "NamesPose"
143+
// We prefer to use the facility "NamesPose"
135144
return NamesPose("CA","WA");
136-
137-
// Append NamesPose("CA","WA")
138-
}
145+
}
139146

140147
std::vector<std::string> VNamesObs() const
141148
{

MMVII/src/UtiMaths/uti_stat.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -145,38 +145,43 @@ int cParamRansac::NbTestOfErrAdm(int aNbSample) const
145145
/* */
146146
/* *************************************** */
147147

148-
cParamCtrNLsq::cParamCtrNLsq()
148+
cParamCtrWeightedLSq::cParamCtrWeightedLSq(tREAL8 aErrRelStop,int aNbIterMax,int aNbIterMin) :
149+
mErrRelStop (aErrRelStop),
150+
mNbIterMax (aNbIterMax),
151+
mNbIterMin (std::max(2,aNbIterMin)) // whatever user require, need 2 to estimate variation
149152
{
150153
}
151154

152-
double cParamCtrNLsq::ValBack(int aK) const
155+
double cParamCtrWeightedLSq::ValBack(int aK) const
153156
{
154157
return mVER.at(mVER.size()-1-aK);
155158
}
156159

157160

158-
double cParamCtrNLsq::GainRel(int aK1,int aK2) const
161+
double cParamCtrWeightedLSq::GainRel(int aK1,int aK2) const
159162
{
160163
return (ValBack(aK2)-ValBack(aK1)) / ValBack(aK2);
161164
}
162165

163166

164-
bool cParamCtrNLsq::StabilityAfterNextError(double anErr)
167+
bool cParamCtrWeightedLSq::StabilityAfterNextError(double anErr)
165168
{
166169
// Err can decrease, stop now to avoid / by 0
167170
if (anErr<=0)
168171
return true;
169172

170173
mVER.push_back(anErr);
171174

172-
int aNb = mVER.size() ; // If less 2 value, cannot estimate variation
173-
if (aNb>10)
175+
int aNb = mVER.size() ;
176+
// too many test
177+
if (aNb>mNbIterMax)
174178
return true;
175179

176-
if (aNb<2)
180+
// not enough error
181+
if (aNb<mNbIterMin)
177182
return false;
178183

179-
if (GainRel(0,1)<1e-4) // if err increase or almosr stable
184+
if (GainRel(0,1)<1e-4) // if error almost stable (Ok) or increase (dangerous ...)
180185
return true;
181186

182187
return false;
@@ -189,20 +194,20 @@ bool cParamCtrNLsq::StabilityAfterNextError(double anErr)
189194
/* *************************************** */
190195

191196

192-
cParamCtrlOpt::cParamCtrlOpt(const cParamRansac & aPRS,const cParamCtrNLsq & aPLS) :
197+
cParamCtrlOpt::cParamCtrlOpt(const cParamRansac & aPRS,const cParamCtrWeightedLSq & aPLS) :
193198
mParamRS (aPRS),
194199
mParamLSQ (aPLS)
195200
{
196201
}
197202
const cParamRansac & cParamCtrlOpt::ParamRS() const {return mParamRS;}
198-
const cParamCtrNLsq & cParamCtrlOpt::ParamLSQ() const {return mParamLSQ;}
203+
const cParamCtrWeightedLSq & cParamCtrlOpt::ParamLSQ() const {return mParamLSQ;}
199204

200205
cParamCtrlOpt cParamCtrlOpt::Default()
201206
{
202207
return cParamCtrlOpt
203208
(
204209
cParamRansac(0.5,1e-6),
205-
cParamCtrNLsq()
210+
cParamCtrWeightedLSq()
206211
);
207212
}
208213

0 commit comments

Comments
 (0)