Skip to content

Commit

Permalink
Before export extract line to CERN
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed Oct 25, 2024
1 parent 2f44d94 commit 167ba2b
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 21 deletions.
44 changes: 44 additions & 0 deletions MMVII/Doc/Methods/Line-Detection-Theory.tex
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,50 @@ \subsection{Selection of \emph{best} lines}
\end{itemize}


%-----------------------------------------------------------------------
%-----------------------------------------------------------------------
%-----------------------------------------------------------------------

\section{The \PPP command }

The command for line extraction is {\tt ExtractLine}. It takes $4$ mandatory parameters in the following order :


\begin{itemize}
\item the set of images where the line must be extracted ;
\item a boolean indicate if the wire is white (used when orientation of line is meaningfull like computing neighboorhouds
or matching anti parallel line);
\item a folder indicating the location of an existing calibration \footnote{it is planned to be able to use
it w/o calibration using the key word {\tt NONE}, by the way it is still not fully working};
\item a folder where storing the results.
\end{itemize}

For example :

\begin{verbatim}
MMVII ExtractLine AllImFil.xml true BA_311_C Fils
MMVII ExtractLine (.*)_0158.tif true BA_311_C Fils
MMVII ExtractLine 043_0158.tif true BA_311_C Fils
\end{verbatim}

For example with last command :

\begin{itemize}
\item we will extract white line on image {\tt 043\_0158.tif};

\item for distorsion correction we will look for intrisic calibration in
folder {\tt MMVII-PhgrProj/Ori/BA\_311\_/} ;

\item the result will be stored in folder {\tt MMVII-PhgrProj/PointsMeasure/Fils};
\end{itemize}

The result will be stored in two way :

\begin{itemize}
\item a xml file by image, that is used by \PPP ;
\item a global file {\tt Lines.csv} that is generated for convenient use by external software.
\end{itemize}


% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% \subsubsection{AAA}
Expand Down
4 changes: 3 additions & 1 deletion MMVII/include/MMVII_ExtractLines.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class cHoughPS // : public cMemCheck
const tREAL8 & Rho() const; ///< Accessor
const tSeg & Seg() const ; ///< Accessor
const tREAL8 & Cumul() const; ///< Accessor
const tREAL8 & SigmaL() const; ///< Accessor
eCodeHPS Code() const ; ///< Accessor
void SetCode(eCodeHPS); ///< Modifior
const cHoughTransform * HT() const; ///< Accessor
Expand All @@ -45,14 +46,15 @@ class cHoughPS // : public cMemCheck
bool Match(const cHoughPS &,bool IsDark,tREAL8 aMaxTeta,tREAL8 aDMin,tREAL8 aDMax) const;
static std::vector<std::pair<int,int>> GetMatches(const std::vector<cHoughPS>& mVPS,bool IsLight,tREAL8 aMaxTeta,tREAL8 aDMin,tREAL8 aDMax);

void UpdateSegImage(const tSeg & aNewSeg,tREAL8 aNewCumul);
void UpdateSegImage(const tSeg & aNewSeg,tREAL8 aNewCumul,tREAL8 aSigmaL);

protected :
void UpdateMatch(cHoughPS *,tREAL8 aDist);

const cHoughTransform * mHT;
cPt2dr mTetaRho;
tREAL8 mCumul;
tREAL8 mSigmaL;
tSeg mSegE;
eCodeHPS mCode;
};
Expand Down
11 changes: 9 additions & 2 deletions MMVII/include/MMVII_Geom3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,15 @@ template <class Type> class cRotation3D
//// Compute a normal repair, first vector being colinear to P1, second in the plane P1,P2
// static cRotation3D<Type> CompleteRON(const tPt & aP0,const tPt & aP1);

// Extract Axes of a rotation and compute its angle
void ExtractAxe(tPt & anAxe,Type & aTeta);
/// Extract Axes of a rotation and compute its angle
void ExtractAxe(tPt & anAxe,Type & aTeta) const;
/// More modern interface to ExtractAxe
std::pair<tPt,Type> ExtractAxe() const;

/// Convenient if you only need Angle, but slow else
Type Angle() const;
/// Convenient if you only need Axe, but slow else
tPt Axe() const;

/// conversion to Omega Phi Kapa
static cRotation3D<Type> RotFromWPK(const tPt & aWPK);
Expand Down
2 changes: 1 addition & 1 deletion MMVII/include/MMVII_MeasuresIm.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class cOneLineAntiParal
tREAL8 mWidth;
tREAL8 mCumul;
tREAL8 mRadHom;
tREAL8 mSimgaLine;
tREAL8 mSigmaLine;
};
void AddData(const cAuxAr2007 & anAux,cOneLineAntiParal & anEx);

Expand Down
9 changes: 8 additions & 1 deletion MMVII/include/cMMVII_Appli.h
Original file line number Diff line number Diff line change
Expand Up @@ -531,14 +531,19 @@ class cMMVII_Appli : public cMMVII_Ap_NameManip,
std::string DirReport();
std::string DirSubPReport(const std::string &anId);
std::string NameTmpReport(const std::string &anId,const std::string &anImg);
/// If we want to create a subdir inside the report, to have multiple reports
void SetReportSubDir(const std::string &);
/// Redirect the file in NewDir, typically when mecanism is used for exporting in csv, and not for report
void SetReportRedir(const std::string &anId,const std::string & aNewDir);

/// Mehod called when the report is finished, usefull when the report is used to memorize problem
virtual void OnCloseReport(int aNbLine,const std::string & anIdent,const std::string & aNameFile) const;

void InitReport(const std::string &anId,const std::string & aPost,bool IsMul,const std::vector<std::string> & aHeader={});
/// Generate a new entry for report "anId", IsMul -> indicate if we are in multi process (for merge at end)
void InitReport(const std::string &anId,const std::string & aPostfix,bool IsMul,const std::vector<std::string> & aHeader={});
// void AddTopReport(const std::string &anId,const std::string & VecMsg);


void AddOneReportCSV(const std::string &anId,const std::vector<std::string> & VecMsg);
/// Add a header line, do it only it at top-level
void AddHeaderReportCSV(const std::string &anId,const std::vector<std::string> & VecMsg);
Expand Down Expand Up @@ -729,6 +734,8 @@ class cMMVII_Appli : public cMMVII_Ap_NameManip,
char mCSVSep; ///< separator in csv file, for now hard coded to ","
std::map<std::string,std::string> mMapIdFilesReport; ///< For a given id memorize the post fix, as "csv"
std::map<std::string,std::string> mMapIdPostReport; ///< For a given id , memorize the file (Global of Tmp in sub process)
/// If finally, we want to store finall result is another Dir (when report is used for generating data in csv as export)
std::map<std::string,std::string> mMapIdRedirect;
std::set<std::string> mReport2Merge; ///< Memorize all the report identifier that must be merged
std::string mReportSubDir; ///< In case we want to write in separate subdir (like with GCP)

Expand Down
14 changes: 13 additions & 1 deletion MMVII/src/Appli/cMMVII_Appli_MakeReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ void cMMVII_Appli::SetReportSubDir(const std::string & aSubDir)
mReportSubDir = aSubDir;
}

void cMMVII_Appli::SetReportRedir(const std::string &anId,const std::string & aNewDir)
{
CreateDirectories(aNewDir,false);
mMapIdRedirect[anId] = aNewDir;
}


std::string cMMVII_Appli::DirSubPReport(const std::string &anId)
{
return DirReport() + "Tmp-" + anId + StringDirSeparator();
Expand Down Expand Up @@ -161,13 +168,18 @@ void cMMVII_Appli::DoMergeReport()
}
}
RemoveRecurs(DirSubPReport(anId),false,false);

}
OnCloseReport(aNbLines,anIt.first,anIt.second);
}
if (MapBoolFind(mMapIdRedirect,anIt.first) && (LevelCall()==0))
{
std::string aNewFile = mMapIdRedirect[anIt.first] + FileOfPath(anIt.second);
RenameFiles(anIt.second,aNewFile);
}
}
}


// By default nothing to do
void cMMVII_Appli::OnCloseReport(int aNbLine,const std::string & anIdent,const std::string & aNameFile) const
{
Expand Down
20 changes: 19 additions & 1 deletion MMVII/src/Geom3D/cRotation3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ template <class Type> cRotation3D<Type> cRotation3D<Type>::RandomRot(const Type
}


template <class Type> void cRotation3D<Type>::ExtractAxe(tPt & anAxe,Type & aTeta)
template <class Type> void cRotation3D<Type>::ExtractAxe(tPt & anAxe,Type & aTeta) const
{
cDenseVect<Type> aDVAxe = mMat.EigenVect(1.0);
anAxe = cPtxd<Type,3>::FromVect(aDVAxe);
Expand All @@ -430,6 +430,24 @@ template <class Type> void cRotation3D<Type>::ExtractAxe(tPt & anAxe,Type & aTet
aTeta = aRhoTeta.y();
}

template <class Type> std::pair<cPtxd<Type,3>,Type> cRotation3D<Type>::ExtractAxe() const
{
tPt anAxe;
Type aTeta;
ExtractAxe(anAxe,aTeta);
return std::pair<cPtxd<Type,3>,Type> (anAxe,aTeta);
}

template <class Type> cPtxd<Type,3> cRotation3D<Type>::Axe() const { return ExtractAxe().first; }
template <class Type> Type cRotation3D<Type>::Angle() const { return ExtractAxe().second; }



/*
*/



/* WPK = Rx(W) Ry(P) Rz(K)
* YPR = Rz(Y) Ry(P) Rx(R)
*
Expand Down
27 changes: 23 additions & 4 deletions MMVII/src/ImagesInfoExtract/cAppliExtractLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ class cAppliExtractLine : public cMMVII_Appli
bool mGTHasSeg; ///< Does the GT "says" that here is no valid segment
std::optional<tSeg2dr> mSegGT;
cTimerSegm mTimeSeg;

std::string mIdExportCSV; ///< used of export lines in CSV files
};


cAppliExtractLine::cAppliExtractLine(const std::vector<std::string> & aVArgs,const cSpecMMVII_Appli & aSpec) :
cMMVII_Appli (aVArgs,aSpec),
mPhProj (*this),
mGenVisu (1),
mGenVisu (0),
mParamMatch {6e-4,2.0,7.0},
mCalib (nullptr),
// mCalDUD (nullptr),
Expand All @@ -165,7 +167,8 @@ cAppliExtractLine::cAppliExtractLine(const std::vector<std::string> & aVArgs,con
mHoughSeuilAng (0.20),
mWithGT (false),
mGTHasSeg (false),
mTimeSeg (this)
mTimeSeg (this),
mIdExportCSV ("Lines")
{
}

Expand All @@ -179,14 +182,14 @@ cCollecSpecArg2007 & cAppliExtractLine::ArgObl(cCollecSpecArg2007 & anArgObl)
return anArgObl
<< Arg2007(mPatImage,"Name of input Image", {eTA2007::FileDirProj,{eTA2007::MPatFile,"0"}})
<< Arg2007(mLineIsWhite," True : its a light line , false dark ")
<< mPhProj.DPOrient().ArgDirInMand()
<< mPhProj.DPPointsMeasures().ArgDirOutMand()
;
}

cCollecSpecArg2007 & cAppliExtractLine::ArgOpt(cCollecSpecArg2007 & anArgOpt)
{
return anArgOpt
<< mPhProj.DPOrient().ArgDirInOpt("","Folder for calibration to integrate distorsion")
<< AOpt2007(mAccurateHough,"AccurateHough","Accurate/Quick hough",{eTA2007::HDV})
<< AOpt2007(mGenVisu,"GenVisu","Generate Visu 0 none, 1 déroulé, 2 image wire, 3",{eTA2007::HDV})
<< AOpt2007(mZoomImL,"ZoomImL","Zoom for images of line",{eTA2007::HDV})
Expand All @@ -200,7 +203,7 @@ cCollecSpecArg2007 & cAppliExtractLine::ArgOpt(cCollecSpecArg2007 & anArgOpt)
std::vector<std::string> cAppliExtractLine::Samples() const
{
return {
"MMVII ExtractLine 'DSC_.*.JPG' ShowSteps=1 InOri=FB"
"MMVII ExtractLine AllImFil.xml true BA_311_C Fils"
};
}

Expand Down Expand Up @@ -425,6 +428,19 @@ void cAppliExtractLine::DoOneImage(const std::string & aNameIm)
*/
}
mPhProj.SaveLines(aExAllLines);

for (const auto & aLine : aExAllLines.mLines)
{
cPt2dr aP1 = aLine.mSeg.P1();
cPt2dr aP2 = aLine.mSeg.P2();
std::vector<std::string> aVS { aNameIm,
ToStr(aP1.x()),ToStr(aP1.y()),ToStr(aP2.x()),ToStr(aP2.y()),
ToStr(aLine.mWidth),ToStr(aLine.mSigmaLine)
};
AddOneReportCSV(mIdExportCSV,aVS);
}
// InitReport(mIdExportCSV,"csv",true,{"NameIm","X1","Y1","X2","Y2","Witdh","Sigma"});
// AddOneReportCSV(mNameReportByLine,{mNameCurIm,ToStr(aEx1L.mAng),ToStr(aEx1L.mWidth),ToStr(aEx1L.mCumul),ToStr(aHS1->RadHom())});
}

#if (0)
Expand Down Expand Up @@ -563,6 +579,9 @@ int cAppliExtractLine::Exe()
InitReport(mNameReportByLine,"csv",true,{"NameIm","Paral","Larg","Score","RadHom"});
InitReport(mNameReportByIm,"csv",true,{"NameIm","CodeResult"});

InitReport(mIdExportCSV,"csv",true,{"NameIm","X1","Y1","X2","Y2","Witdh","Sigma"});
SetReportRedir(mIdExportCSV,mPhProj.DPPointsMeasures().FullDirOut());

// AddHeaderReportCSV(mNameReportByLine,{"NameIm","Paral","Larg","Cumul"});
// AddHeaderReportCSV(mNameReportByIm,{"NameIm","CodeResult"});
if (RunMultiSet(0,0))
Expand Down
3 changes: 2 additions & 1 deletion MMVII/src/ImagesInfoExtract/cExtractLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,8 @@ template <class Type> void cExtractLines<Type>::RefineLineInSpace(cHoughPS & aH
}
// StdOut() << "RefineLineInSpacellll " << __LINE__ << "\n";

aHPS.UpdateSegImage(aNewSeg,aSumNumbering.back());
aHPS.UpdateSegImage(aNewSeg,aSumNumbering.back(),aVStat.back().QuadAvg());
// StdOut() << "RESSSS " << aVStat.at(aKIter+1).QuadAvg() << "\n";
}


Expand Down
6 changes: 5 additions & 1 deletion MMVII/src/ImagesInfoExtract/cHoughTransform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ cOneLineAntiParal cParalLine::GetLAP(const cPerspCamIntrCalib & aCalib) const
aOLAP.mRadHom = mRadHom;
aOLAP.mWidth = mWidth;
aOLAP.mCumul = mScoreMatch;
aOLAP.mSigmaLine = (mVHS.at(0).SigmaL() + mVHS.at(1).SigmaL()) / 2.0;

return aOLAP;
}
Expand Down Expand Up @@ -231,14 +232,16 @@ cHoughPS::cHoughPS(const cHoughTransform * aHT,const cPt2dr & aTR,tREAL8 aCumul,
mHT (aHT),
mTetaRho (aTR),
mCumul (aCumul),
mSigmaL (-1), // undef
mSegE (aP1,aP2),
mCode (eCodeHPS::Ok)
{
}

void cHoughPS::UpdateSegImage(const tSeg & aNewSeg,tREAL8 aNewCumul)
void cHoughPS::UpdateSegImage(const tSeg & aNewSeg,tREAL8 aNewCumul,tREAL8 aSigma)
{
mCumul = aNewCumul;
mSigmaL = aSigma;
mSegE = aNewSeg;
mTetaRho = mHT->Line2PtInit(aNewSeg);
}
Expand All @@ -260,6 +263,7 @@ const cPt2dr & cHoughPS::TetaRho() const {return mTetaRho;}
const tREAL8 & cHoughPS::Teta() const {return mTetaRho.x();}
const tREAL8 & cHoughPS::Rho() const {return mTetaRho.y();}
const tREAL8 & cHoughPS::Cumul() const {return mCumul;}
const tREAL8 & cHoughPS::SigmaL() const {return mSigmaL;}
// cHoughPS * cHoughPS::Matched() const {return mMatched;}
eCodeHPS cHoughPS::Code() const {return mCode;}
void cHoughPS::SetCode(eCodeHPS aCode) { mCode = aCode;}
Expand Down
2 changes: 1 addition & 1 deletion MMVII/src/ImportFormat/ImportLines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ int cAppli_ImportLines::Exe()
aLine.mSeg = tSeg2dr(aP1,aP2);

if (WithSigma)
aLine.mSimgaLine = aNRFS.GetFloat(mNameSigma,aK);
aLine.mSigmaLine = aNRFS.GetFloat(mNameSigma,aK);
if (WithWidth)
aLine.mWidth = aNRFS.GetFloat(mNameWidth,aK);

Expand Down
Loading

0 comments on commit 167ba2b

Please sign in to comment.