From fdb4fa4ddbe697be3743bcb57e5e57699e8e407d Mon Sep 17 00:00:00 2001 From: even <philippe.even@loria.fr> Date: Tue, 18 Dec 2018 13:49:54 +0100 Subject: [PATCH] Initial orientation test --- Article/method.tex | 9 +++++---- Code/Seg/BSTools/bsdetectionwidget.cpp | 3 +++ Code/Seg/BlurredSegment/bsdetector.cpp | 25 ++++++++++++++++++++---- Code/Seg/BlurredSegment/bsdetector.h | 2 ++ Code/Seg/BlurredSegment/bstracker.cpp | 2 +- Code/Seg/ImageTools/vmap.cpp | 12 ++++++------ Code/Seg/ImageTools/vmap.h | 17 ++++++++-------- Code/Seg/ImageTools/vr2i.cpp | 8 ++++++++ Code/Seg/ImageTools/vr2i.h | 16 +++++++++++---- Methode/methode.tex | 27 +++++++++++++++++++------- 10 files changed, 87 insertions(+), 34 deletions(-) diff --git a/Article/method.tex b/Article/method.tex index 7b5c1a2..355e76c 100755 --- a/Article/method.tex +++ b/Article/method.tex @@ -43,10 +43,11 @@ The initial detection consists in building and extending a blurred segment $\mathcal{B}$ based on the highest gradient points found in each scan of a static directional scanner based on an input segment $AB$. -Validity tests aiming at rejecting too short or too sparse blurred segments -are applied to decide of the detection poursuit. In case of positive response, -the position $C$ and direction $\vec{D}$ of this initial blurred segment -are extracted. +Validity tests are then applied to decide of the detection poursuit. +They aim at rejecting a too short or too sparse blurred segment, or a +blurred segment with a close orientation to the input segment $AB$. +In case of positive response, the position $C$ and direction $\vec{D}$ +of this initial blurred segment are extracted. The fine tracking step consists on building and extending a blurred segment $\mathcal{B}'$ based on points that correspond to local maxima of the diff --git a/Code/Seg/BSTools/bsdetectionwidget.cpp b/Code/Seg/BSTools/bsdetectionwidget.cpp index 85b7745..6a6254a 100755 --- a/Code/Seg/BSTools/bsdetectionwidget.cpp +++ b/Code/Seg/BSTools/bsdetectionwidget.cpp @@ -1017,6 +1017,9 @@ void BSDetectionWidget::writeDetectionStatus () else if (res == BSDetector::RESULT_INITIAL_TOO_MANY_OUTLIERS) cout << "Extraction : unsuccessful filter test at initial detection." << endl; + else if (res == BSDetector::RESULT_INITIAL_CLOSE_ORIENTATION) + cout << "Extraction : initial detection of a too closely oriented segment." + << endl; else if (res == BSDetector::RESULT_FINAL_NO_DETECTION) cout << "Extraction : no final detection (bsini == NULL)." << endl; else if (res == BSDetector::RESULT_FINAL_TOO_FEW) diff --git a/Code/Seg/BlurredSegment/bsdetector.cpp b/Code/Seg/BlurredSegment/bsdetector.cpp index b988af8..a31b1ff 100755 --- a/Code/Seg/BlurredSegment/bsdetector.cpp +++ b/Code/Seg/BlurredSegment/bsdetector.cpp @@ -14,6 +14,7 @@ const int BSDetector::RESULT_INITIAL_NO_DETECTION = 11; const int BSDetector::RESULT_INITIAL_TOO_FEW = 12; const int BSDetector::RESULT_INITIAL_TOO_SPARSE = 13; const int BSDetector::RESULT_INITIAL_TOO_MANY_OUTLIERS = 14; +const int BSDetector::RESULT_INITIAL_CLOSE_ORIENTATION = 15; const int BSDetector::RESULT_FINAL_NO_DETECTION = 21; const int BSDetector::RESULT_FINAL_TOO_FEW = 22; const int BSDetector::RESULT_FINAL_TOO_SPARSE = 23; @@ -219,6 +220,15 @@ void BSDetector::olddetect (const Pt2i &p1, const Pt2i &p2, } */ + // Orientation test for automatic extractions + //------------------------------------------- + Vr2i bsinidir = bsini->getSupportVector(); + if (bsinidir.orientedAs (inip1.vectorTo (inip2))) + { + resultValue = RESULT_INITIAL_CLOSE_ORIENTATION; + return; + } + // Gradient reference selection //----------------------------- Pt2i pCenter = bsini->getCenter (); @@ -234,8 +244,7 @@ void BSDetector::olddetect (const Pt2i &p1, const Pt2i &p2, // Finer detection based on gradient maxima with orientation constraint //--------------------------------------------------------------------- - bsf = bstold->fineTrack (pCenter, bsini->getSupportVector(), - scanwidth, bswidth, gRef); + bsf = bstold->fineTrack (pCenter, bsinidir, scanwidth, bswidth, gRef); if (bsf == NULL || bsf->size () < bsMinSize) { resultValue = (bsf == NULL ? RESULT_FINAL_NO_DETECTION @@ -379,6 +388,15 @@ void BSDetector::detect (const Pt2i &p1, const Pt2i &p2, return; } + // Orientation test for automatic extractions + //------------------------------------------- + Vr2i bsinidir = bsini->getSupportVector(); + if (bsinidir.orientedAs (inip1.vectorTo (inip2))) + { + resultValue = RESULT_INITIAL_CLOSE_ORIENTATION; + return; + } + // Gradient reference selection //----------------------------- Pt2i pCenter = bsini->getCenter (); @@ -400,8 +418,7 @@ void BSDetector::detect (const Pt2i &p1, const Pt2i &p2, // Finer detection based on gradient maxima with orientation constraint //--------------------------------------------------------------------- - bsf = bst2->fineTrack (pCenter, bsini->getSupportVector(), - scanwidth, bswidth, gRef); + bsf = bst2->fineTrack (pCenter, bsinidir, scanwidth, bswidth, gRef); if (bsf == NULL || bsf->size () < bsMinSize) { resultValue = (bsf == NULL ? RESULT_FINAL_NO_DETECTION diff --git a/Code/Seg/BlurredSegment/bsdetector.h b/Code/Seg/BlurredSegment/bsdetector.h index 7d4f93f..8784144 100755 --- a/Code/Seg/BlurredSegment/bsdetector.h +++ b/Code/Seg/BlurredSegment/bsdetector.h @@ -40,6 +40,8 @@ public: static const int RESULT_INITIAL_TOO_SPARSE; /** Extraction result : unsuccessful filter test at initial detection. */ static const int RESULT_INITIAL_TOO_MANY_OUTLIERS; + /** Extraction result : initial detection of a closely oriented segment. */ + static const int RESULT_INITIAL_CLOSE_ORIENTATION; /** Extraction result : no final detection (bsf == NULL). */ static const int RESULT_FINAL_NO_DETECTION; /** Extraction result : too few points at final detection. */ diff --git a/Code/Seg/BlurredSegment/bstracker.cpp b/Code/Seg/BlurredSegment/bstracker.cpp index 6ac9c1c..4462ab3 100755 --- a/Code/Seg/BlurredSegment/bstracker.cpp +++ b/Code/Seg/BlurredSegment/bstracker.cpp @@ -209,7 +209,7 @@ BlurredSegment *BSTracker::fineTrack (const Pt2i ¢er, const Vr2i &scandir, // Gets detected segment normal vector Vr2i normal = scandir.orthog (); - if (! normal.orientedAs (gref)) normal.invert (); + if (! normal.directedAs (gref)) normal.invert (); fail = 0; diff --git a/Code/Seg/ImageTools/vmap.cpp b/Code/Seg/ImageTools/vmap.cpp index 142b3b5..a4b85a2 100755 --- a/Code/Seg/ImageTools/vmap.cpp +++ b/Code/Seg/ImageTools/vmap.cpp @@ -534,8 +534,8 @@ int VMap::keepContrastedMax (int *lmax, int n, int *in) const } -int VMap::keepOrientedElementsIn (const vector<Pt2i> &pix, - const Vr2i &ref, int n, int *ind) const +int VMap::keepDirectedElementsAs (const vector<Pt2i> &pix, + int n, int *ind, const Vr2i &ref) const { int vx = ref.x (); int vy = ref.y (); @@ -550,8 +550,8 @@ int VMap::keepOrientedElementsIn (const vector<Pt2i> &pix, } -int VMap::keepDirectedElementsIn (const vector<Pt2i> &pix, - const Vr2i &ref, int n, int *ind) const +int VMap::keepOrientedElementsAs (const vector<Pt2i> &pix, + int n, int *ind, const Vr2i &ref) const { int vx = ref.x (); int vy = ref.y (); @@ -613,10 +613,10 @@ int VMap::localMax (int *lmax, const vector<Pt2i> &pix, const Vr2i &gref) const // Prunes the candidates with opposite gradient if (orientedGradient) - count = keepOrientedElementsIn (pix, gref, count, lmax); + count = keepDirectedElementsAs (pix, count, lmax, gref); // Prunes the candidates wrongly oriented - count = keepDirectedElementsIn (pix, gref, count, lmax); + count = keepOrientedElementsAs (pix, count, lmax, gref); // Sorts candidates by gradient magnitude sortMax (lmax, count, gn); diff --git a/Code/Seg/ImageTools/vmap.h b/Code/Seg/ImageTools/vmap.h index 4c43e13..6e4d482 100755 --- a/Code/Seg/ImageTools/vmap.h +++ b/Code/Seg/ImageTools/vmap.h @@ -164,28 +164,29 @@ public: int keepContrastedMax (int *lmax, int n, int *in) const; /** - * Keeps elements that are oriented along a reference vector - * in a selection of points. + * Keeps elements with the same direction as a reference vector + * in a selection of points (positive scalar product). * Returns the number of remaining elements in the selection. * @param pix Input array of scanned points. - * @param ref The reference vector. * @param n Initial size of the selection of points. * @param ind Selection of points. + * @param ref The reference vector. */ - int keepOrientedElementsIn (const vector<Pt2i> &pix, - const Vr2i &ref, int n, int *ind) const; + int keepDirectedElementsAs (const vector<Pt2i> &pix, + int n, int *ind, const Vr2i &ref) const; /** * Keeps elements with gradient value near a reference vector * in a selection of points. + * Relies on angleThreshold value for the test. * Returns the number of remaining elements in the selection. * @param pix Input array of scanned points. - * @param ref The reference vector. * @param n Initial size of the selection of points. * @param ind Selection of points. + * @param ref The reference vector. */ - int keepDirectedElementsIn (const vector<Pt2i> &pix, - const Vr2i &ref, int n, int *ind) const; + int keepOrientedElementsAs (const vector<Pt2i> &pix, + int n, int *ind, const Vr2i &ref) const; /** * \brief Gets filtered and sorted local gradient maxima. diff --git a/Code/Seg/ImageTools/vr2i.cpp b/Code/Seg/ImageTools/vr2i.cpp index 5f0ab4d..32f3398 100755 --- a/Code/Seg/ImageTools/vr2i.cpp +++ b/Code/Seg/ImageTools/vr2i.cpp @@ -28,6 +28,14 @@ Vr2i Vr2i::orthog () const } +bool Vr2i::orientedAs (const Vr2i &ref) const +{ + int ps = xv * ref.xv + yv * ref.yv; + return (4 * ps * ps > 3 * (xv * xv + yv * yv) + * (ref.xv * ref.xv + ref.yv * ref.yv)); +} + + bool *Vr2i::steps (int *n) const { int x2 = (xv > 0 ? xv : - xv); diff --git a/Code/Seg/ImageTools/vr2i.h b/Code/Seg/ImageTools/vr2i.h index 35cca7a..cac1af7 100755 --- a/Code/Seg/ImageTools/vr2i.h +++ b/Code/Seg/ImageTools/vr2i.h @@ -121,11 +121,19 @@ public: inline void setOrthog () { int tmp = xv; xv = - yv; yv = tmp; } /** - * @fn bool orientedAs (Vr2i v) - * \brief Returns true if v has the same orientation as the vector. + * @fn bool directedAs (Vr2i ref) + * \brief Returns true if v has the same direction as a reference. + * @param ref The reference vector. */ - inline bool orientedAs (Vr2i v) const { - return (xv * v.xv + yv * v.yv >= 0); } + inline bool directedAs (const Vr2i &ref) const { + return (xv * ref.xv + yv * ref.yv >= 0); } + + /** + * @fn bool orientedAs (Vr2i ref) + * \brief Returns true if v has the same orientation as a reference. + * @param ref The reference vector. + */ + bool orientedAs (const Vr2i &ref) const; /** * @fn void invert () diff --git a/Methode/methode.tex b/Methode/methode.tex index 9fccb59..230285a 100755 --- a/Methode/methode.tex +++ b/Methode/methode.tex @@ -16,7 +16,7 @@ \section*{S\'equencement de la d\'etection} -\begin{picture}(150,160)(0,0) +\begin{picture}(150,170)(0,0) \put(40,0){\framebox(70,10){FILTRAGE}} \put(75,20){\vector(0,-1){10}} \put(40,20){\framebox(70,10){TEST DE CONNEXITE}} @@ -28,17 +28,19 @@ \put(75,60){\vector(0,-1){10}} \put(40,60){\framebox(70,10){RECENTRAGE}} \put(75,80){\vector(0,-1){10}} -\put(40,80){\framebox(70,10){PRE-FILTRAGE}} +\put(40,80){\framebox(70,10){TEST D'ORIENTATION}} \put(75,100){\vector(0,-1){10}} -\put(40,100){\framebox(70,10){TEST DE DENSITE}} +\put(40,100){\framebox(70,10){PRE-FILTRAGE}} \put(75,120){\vector(0,-1){10}} +\put(40,120){\framebox(70,10){TEST DE DENSITE}} +\put(75,140){\vector(0,-1){10}} \thicklines -\put(40,120){\framebox(70,10){\bf \large SUIVI RAPIDE}} -\put(42,122){\framebox(66,6)} +\put(40,140){\framebox(70,10){\bf \large SUIVI RAPIDE}} +\put(42,142){\framebox(66,6)} \thinlines -\put(75,140){\vector(0,-1){10}} +\put(75,160){\vector(0,-1){10}} \thicklines -\put(40,140){\framebox(70,10){\bf \large SUIVI PRELIMINAIRE}} +\put(40,160){\framebox(70,10){\bf \large SUIVI PRELIMINAIRE}} \thinlines \end{picture} @@ -126,6 +128,17 @@ isol\'es \`a l'\'ecart du segment. \end{itemize} \end{itemize} +\subsection*{Test d'orientation} + +\begin{itemize} +\item Etat par d\'efaut : activ\'e. +\item Fonctionnement : +\begin{itemize} +\item V\'erifie que l'orientation du segment n'est pas trop proche de +celle de la barre de balayage $P_1P_2$ ($30^o$). +\end{itemize} +\end{itemize} + \subsection*{Recentrage} \begin{itemize} -- GitLab