44#include " MMVII_Tpl_Images.h"
55#include " MMVII_HeuristikOpt.h"
66#include " MMVII_DeclareAllCmd.h"
7+ #include " MMVII_Random.h"
78
89namespace MMVII
910{
@@ -99,6 +100,8 @@ class cEstimatePosRel2Im : public cOptimizeRotAndVUnit // Herit for combinatori
99100
100101 cEstimatePosRel2Im
101102 (
103+ const std::string & aIm1,
104+ const std::string & aIm2,
102105 cPerspCamIntrCalib & aCalib1,
103106 cPerspCamIntrCalib & aCalib12,
104107 const cSetHomogCpleIm & aSetHomFull,
@@ -176,6 +179,8 @@ class cEstimatePosRel2Im : public cOptimizeRotAndVUnit // Herit for combinatori
176179
177180
178181 // -------- Data for camera -------------------
182+ std::string mIm1 ;
183+ std::string mIm2 ;
179184 cPerspCamIntrCalib & mCalib1 ; // /< Calib of first image
180185 tREAL8 mFoc1 ; // /< Foc first image
181186 cPerspCamIntrCalib & mCalib2 ; // /< Calib second image
@@ -224,6 +229,8 @@ class cEstimatePosRel2Im : public cOptimizeRotAndVUnit // Herit for combinatori
224229
225230cEstimatePosRel2Im::cEstimatePosRel2Im
226231(
232+ const std::string& aIm1,
233+ const std::string& aIm2,
227234 cPerspCamIntrCalib & aCalib1,
228235 cPerspCamIntrCalib & aCalib2,
229236 const cSetHomogCpleIm & aSetHomFull,
@@ -233,6 +240,8 @@ cEstimatePosRel2Im::cEstimatePosRel2Im
233240 cTimerSegm * aTimeSegm
234241) :
235242 cOptimizeRotAndVUnit (5 ,4 ,false ),
243+ mIm1 (aIm1),
244+ mIm2 (aIm2),
236245 mCalib1 (aCalib1),
237246 mFoc1 (mCalib1 .F()),
238247 mCalib2 (aCalib2),
@@ -604,12 +613,30 @@ cCdtFinalPoseRel2Im cEstimatePosRel2Im::MakeDecision(bool Show)
604613 SortOnCriteria (aVBest,[](const auto & aCdt){return aCdt.mScore ;});
605614
606615
616+ if (Show)
617+ {
618+ StdOut () << " ======== Select solution in each mode ================\n " ;
619+ for (auto & aCdt : aVBest )
620+ {
621+ if (mWithGT )
622+ {
623+ tREAL8 aDTr = Norm2 (aCdt.mPose .Tr ()-mGTPose .Tr ());
624+ tREAL8 aDRot = aCdt.mPose .Rot ().Dist (mGTPose .Rot ());
625+ aCdt.mScorePixGT = cPt2dr (aDTr,aDRot)*mFocMoy ;
626+ }
627+ ShowSol (aCdt.mPose ,aCdt.mMsg );
628+ }
629+ }
630+
631+
607632 if (aVBest.back ().mMode ==eModePE2I::eRansac)
608633 {
609634 // Worst sol in ransac
610635 // in this case, probably the scene is planar and the two planary solution
611636 // can not be separated at this step, we maintain them
612637 aVBest.resize (2 );
638+
639+ // if (mWithGT && (aVBest.at(0).
613640 }
614641 else
615642 {
@@ -640,6 +667,17 @@ cCdtFinalPoseRel2Im cEstimatePosRel2Im::MakeDecision(bool Show)
640667 StdOut () << " \n " ;
641668 }
642669 }
670+ if (mWithGT && (aVBest.size ()>=2 ))
671+ {
672+ tREAL8 aSc0 = Norm2 (aVBest.at (0 ).mScorePixGT .value ());
673+ tREAL8 aSc1 = Norm2 (aVBest.at (1 ).mScorePixGT .value ());
674+ if (aSc1<aSc0)
675+ {
676+ StdOut () << " ===== For Images " << mIm1 << " " << mIm2 << " \n " ;
677+ for (const auto & aCdt : aVBest)
678+ ShowSol (aCdt.mPose ,aCdt.mMsg );
679+ }
680+ }
643681
644682 return aRes;
645683}
@@ -751,6 +789,7 @@ class cAppli_OriRelPairOfIm : public cMMVII_Appli
751789
752790 cTimerSegm * mTimeSegm ;
753791 std::vector<const tNamePair *> mVecPairs ;
792+ int mKSaveOri ;
754793
755794};
756795
@@ -773,7 +812,8 @@ cAppli_OriRelPairOfIm::cAppli_OriRelPairOfIm(const std::vector<std::string> & aV
773812 mUseOri4GT (false ),
774813 mGTPose (tPoseR::Identity()),
775814 mPC1GT (nullptr ),
776- mPC2GT (nullptr )
815+ mPC2GT (nullptr ),
816+ mKSaveOri (0 )
777817{
778818}
779819
@@ -811,7 +851,7 @@ cCollecSpecArg2007 & cAppli_OriRelPairOfIm::ArgObl(cCollecSpecArg2007 & anArgObl
811851
812852cCollecSpecArg2007 & cAppli_OriRelPairOfIm::ArgOpt (cCollecSpecArg2007 & anArgOpt)
813853{
814- return anArgOpt
854+ anArgOpt
815855 << mPhProj .DPTieP ().ArgDirInOpt ()
816856 << mPhProj .DPGndPt2D ().ArgDirInOpt ()
817857 << mPhProj .DPMulTieP ().ArgDirInOpt ()
@@ -829,6 +869,14 @@ cCollecSpecArg2007 & cAppli_OriRelPairOfIm::ArgOpt(cCollecSpecArg2007 & anArgOpt
829869 << AOpt2007 (mParamOutLayer ," OutLayers" ," Param for generating outlayers [Nb,Sigma]" ,{{eTA2007::ISizeV," [2,2]" }})
830870 << AOpt2007 (mShow ," Show" ," Show messages" ,{eTA2007::HDV})
831871 ;
872+
873+ if (mModeCompute ==0 )
874+ {
875+ anArgOpt << mPhProj .DPOrient ().ArgDirOutOpt (" OriOut" ," For saving relative or as orientations" )
876+ << AOpt2007 (mKSaveOri ," KSaveOri" ," Num of sol to save" ,{eTA2007::HDV}) ;
877+ }
878+
879+ return anArgOpt;
832880}
833881
834882
@@ -858,6 +906,8 @@ std::vector<std::string> cAppli_OriRelPairOfIm::Samples() const
858906
859907int cAppli_OriRelPairOfIm::Exe ()
860908{
909+
910+
861911 mTimeSegm = mShow ? new cTimerSegm (this ) : nullptr ;
862912 mPhProj .FinishInit ();
863913
@@ -923,6 +973,8 @@ int cAppli_OriRelPairOfIm::DoPairsOf1Im()
923973 {
924974 if (aPair->V1 () == mIm1 )
925975 {
976+ if (mShow )
977+ StdOut () << " ====== DoPairsOf1Im, V2=" << aPair->V2 () << " ========\n " ;
926978 tRes1Pair aRes = EstimatePose2IM (aPair->V1 (), aPair->V2 ());
927979 aRes.second .mIm1 = mIm1 ;
928980 aRes.second .mIm2 = aPair->V2 ();
@@ -951,6 +1003,10 @@ int cAppli_OriRelPairOfIm::DoPairsOf1Im()
9511003cAppli_OriRelPairOfIm::tRes1Pair
9521004 cAppli_OriRelPairOfIm::EstimatePose2IM (const std::string& aIm1,const std::string& aIm2)
9531005{
1006+ // For debuging/tuning we must have the same behaviour when we run 1 pair or multiple pair,
1007+ // so to have the same random number in ransac we re initialize the number generator at each pair
1008+ cRandGenerator::TheOne ()->setSeed (42 );
1009+
9541010 mIm1 = aIm1;
9551011 mIm2 = aIm2;
9561012 OrderMinMax (mIm1 ,mIm2 );
@@ -1024,7 +1080,8 @@ cAppli_OriRelPairOfIm::tRes1Pair
10241080 mCalib1 = mPhProj .InternalCalibFromImage (mIm1 );
10251081 mCalib2 = mPhProj .InternalCalibFromImage (mIm2 );
10261082
1027- mEstimatePose = new cEstimatePosRel2Im (*mCalib1 ,*mCalib2 ,mCpleHFull ,mCpleHAvg ,mCpleHSmall ,mDensitySol ,mTimeSegm );
1083+ mEstimatePose = new cEstimatePosRel2Im
1084+ (aIm1,aIm2,*mCalib1 ,*mCalib2 ,mCpleHFull ,mCpleHAvg ,mCpleHSmall ,mDensitySol ,mTimeSegm );
10281085 if (mUseOri4GT )
10291086 mEstimatePose ->SetGT (mGTPose );
10301087
@@ -1036,6 +1093,18 @@ cAppli_OriRelPairOfIm::tRes1Pair
10361093 if (mDo5Pts )
10371094 Generate5Pts (aCdt.mVCdt .at (0 ).mPose );
10381095
1096+ if (mPhProj .DPOrient ().DirOutIsInit ())
1097+ {
1098+ StdOut () << " OUT=" << mPhProj .DPOrient ().DirOut () << " \n " ;
1099+ const auto & aC = aCdt.mVCdt .at (mKSaveOri );
1100+
1101+ cSensorCamPC aCam1 (mIm1 ,tPoseR::Identity (),mCalib1 );
1102+ cSensorCamPC aCam2 (mIm2 ,aC.mPose ,mCalib2 );
1103+ mPhProj .SaveCamPC (aCam1);
1104+ mPhProj .SaveCamPC (aCam2);
1105+
1106+ }
1107+
10391108 /* if (mUseOri4GT && mShow)
10401109 mEstimatePose->ShowSol(mGTPose,"GroundTruh");*/
10411110
0 commit comments