From 2e1e895157149197c4d87e9f833c61c3353141be Mon Sep 17 00:00:00 2001 From: even <philippe.even@loria.fr> Date: Tue, 7 May 2019 14:18:46 +0200 Subject: [PATCH] Better compatibility static / gMap --- Code/FBSD/BSTools/bsdetectionwidget.cpp | 39 +++++++++++++++++-------- Code/FBSD/BSTools/bsdetectionwidget.h | 27 +++++++++++------ Code/FBSD/BlurredSegment/bsdetector.cpp | 19 ++++++++++-- Code/FBSD/main.cpp | 4 +-- 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/Code/FBSD/BSTools/bsdetectionwidget.cpp b/Code/FBSD/BSTools/bsdetectionwidget.cpp index 979fe68..ff442b5 100755 --- a/Code/FBSD/BSTools/bsdetectionwidget.cpp +++ b/Code/FBSD/BSTools/bsdetectionwidget.cpp @@ -49,13 +49,17 @@ BSDetectionWidget::BSDetectionWidget (QWidget *parent) // Sets display parameters darkHighlightOn = false; - arlequinOn = true; + bscolorset = 0; selectionColor = Qt::red; bsColor = Qt::blue; bsHighColor = Qt::yellow; + bsColor2 = Qt::green; + bsHighColor2 = Qt::black; bsPointsVisible = true; boundColor = Qt::green; boundHighColor = Qt::magenta; + boundColor2 = Qt::green; + boundHighColor2 = Qt::black; maxWidth = 768; maxHeight = 512; @@ -339,7 +343,8 @@ void BSDetectionWidget::switchHighlightColors () void BSDetectionWidget::switchArlequin () { - arlequinOn = ! arlequinOn; + bscolorset ++; + if (bscolorset == 3) bscolorset = 0; } @@ -876,7 +881,11 @@ void BSDetectionWidget::keyPressEvent (QKeyEvent *event) case Qt::Key_Equal : switchArlequin (); - cout << "Random coloring " << (isArlequinOn () ? "on" : "off") << endl; + if (activeColorSet () == 0) + cout << "Random color blurred segments" << endl; + else if (activeColorSet () == 1) + cout << "Stylized color blurred segments" << endl; + else cout << "Neutral color blurred segments" << endl; displayDetectionResult (); break; @@ -1088,7 +1097,7 @@ void BSDetectionWidget::drawSelection (QPainter &painter, } -void BSDetectionWidget::drawBlurredSegment (QPainter &painter, +void BSDetectionWidget::drawBlurredSegment (QPainter &painter, bool style, BlurredSegment *bs, bool high) { if (bs != NULL) @@ -1100,11 +1109,15 @@ void BSDetectionWidget::drawBlurredSegment (QPainter &painter, if (dss != NULL) { dss->getBounds (bnd, 0, 0, width, height); - drawPoints (painter, bnd, high ? boundHighColor : boundColor); + drawPoints (painter, bnd, + high ? (style ? boundHighColor : boundHighColor2) + : (style ? boundColor : boundColor2)); } } if (bsPointsVisible) - drawPoints (painter, bs->getAllPoints (), high ? bsHighColor : bsColor); + drawPoints (painter, bs->getAllPoints (), + high ? (style ? bsHighColor : bsHighColor2) + : (style ? bsColor : bsColor2)); } } @@ -1247,7 +1260,8 @@ void BSDetectionWidget::displayDetectionResult () // cout << bss.size () << " blurred segments detected" << endl; // double bsw = 0.; // int bsc = 0; - if (arlequinOn && detector.getMaxDetections () == 0) srand (time (NULL)); + if (bscolorset == 0 && detector.getMaxDetections () == 0) + srand (time (NULL)); vector<BlurredSegment *>::const_iterator it = bss.begin (); while (it != bss.end ()) { @@ -1258,18 +1272,19 @@ void BSDetectionWidget::displayDetectionResult () // if (dss == NULL) cout << "DSS null" << endl; // else bsw += dss->width () / (double) dss->period (); // } - if (arlequinOn && detector.getMaxDetections () == 0) + if (bscolorset == 0 && detector.getMaxDetections () == 0) drawArlequinSegment (painter, *it); else - drawBlurredSegment (painter, *it, detector.getMaxDetections () == 0 - || *it == bss.back ()); + drawBlurredSegment (painter, bscolorset == 1, *it, + detector.getMaxDetections () == 0 || *it == bss.back ()); it++; } // cout << bsc << " effective blurred segments" << endl; // if (bsc != 0) cout << "Mean width is " << bsw / bsc << endl; } else - drawBlurredSegment (painter, detector.getBlurredSegment ()); + drawBlurredSegment (painter, bscolorset <= 1, + detector.getBlurredSegment ()); if (udef) drawSelection (painter, p1, p2); update (QRect (QPoint (0, 0), QPoint (width, height))); @@ -1309,7 +1324,7 @@ void BSDetectionWidget::displaySavedSegments () vector<ExtractedSegment>::iterator it = extractedSegments.begin (); while (it != extractedSegments.end ()) { - drawBlurredSegment (painter, it->bs); + drawBlurredSegment (painter, bscolorset <= 1, it->bs); drawSelection (painter, it->p1, it->p2); it ++; } diff --git a/Code/FBSD/BSTools/bsdetectionwidget.h b/Code/FBSD/BSTools/bsdetectionwidget.h index ae3daa4..5e1abe0 100755 --- a/Code/FBSD/BSTools/bsdetectionwidget.h +++ b/Code/FBSD/BSTools/bsdetectionwidget.h @@ -129,9 +129,9 @@ public: void switchHighlightColors (); /** - * \brief Returns whether random color display modality is set. + * \brief Returns the blurred segment color style for display. */ - inline bool isArlequinOn () const { return arlequinOn; } + inline int activeColorSet () const { return bscolorset; } /** * \brief Switches the random color display modality. @@ -243,20 +243,28 @@ private: /** Kind of highlight colors. */ bool darkHighlightOn; - /** Random color selection modality. */ - bool arlequinOn; + /** Color style to display blurred segments. */ + int bscolorset; /** Color of user selections. */ QColor selectionColor; - /** Color of blurred segments. */ + /** Stylized color of blurred segments. */ QColor bsColor; - /** Color of highlighted blurred segments. */ + /** Stylized color of highlighted blurred segments. */ QColor bsHighColor; + /** Neutral color of blurred segments. */ + QColor bsColor2; + /** Neutral color of highlighted blurred segments. */ + QColor bsHighColor2; /** Flag indicating whether blurred segments points are visible. */ bool bsPointsVisible; - /** Color of blurred segments bounds. */ + /** Stylized color of blurred segments bounds. */ QColor boundColor; - /** Color of highlighted blurred segments bounds. */ + /** Stylized color of highlighted blurred segments bounds. */ QColor boundHighColor; + /** Neutral color of blurred segments bounds. */ + QColor boundColor2; + /** Neutral color of highlighted blurred segments bounds. */ + QColor boundHighColor2; /** Flag indicating whether blurred segments bounds are visible. */ bool bsBoundsVisible; /** Background type. @@ -362,10 +370,11 @@ private: /** * \brief Draws a blurred segment. * @param painter Drawing device. + * @param style Flag indicating if specific drawing style is set. * @param bs Reference to the blurred segment to be drawn. * @param high Flag indicated whether the blurred segment is highlighted. */ - void drawBlurredSegment (QPainter &painter, + void drawBlurredSegment (QPainter &painter, bool style, BlurredSegment *bs, bool high = true); /** diff --git a/Code/FBSD/BlurredSegment/bsdetector.cpp b/Code/FBSD/BlurredSegment/bsdetector.cpp index 0872508..e4497d3 100755 --- a/Code/FBSD/BlurredSegment/bsdetector.cpp +++ b/Code/FBSD/BlurredSegment/bsdetector.cpp @@ -107,8 +107,9 @@ void BSDetector::setGradientMap (VMap *data) gMap = data; if (prelimDetectionOn) bst0->setGradientMap (data); if (staticDetOn) bstStatic->setGradientMap (data); - bst1->setGradientMap (data); - bst2->setGradientMap (data); + if (bst1) bst1->setGradientMap (data); + if (bst2) bst2->setGradientMap (data); + if (bstStatic) bstStatic->setGradientMap (data); } @@ -534,6 +535,18 @@ int BSDetector::staticDetect (const Pt2i &p1, const Pt2i &p2, bsf = bsf2; } + // Size test + //------------ + if (finalSizeTestOn) + { + // DigitalStraightSegment *dss = bsf->getSegment (); + if ((int) (bsf->getAllPoints().size ()) < finalMinSize) + { + // nbSmallBS ++; + return RESULT_FINAL_TOO_SMALL; + } + } + // Final sparsity test //----------------- if (finalSparsityTestOn) @@ -704,7 +717,7 @@ void BSDetector::setStaticDetector (bool status) else if (status && ! staticDetOn) { bstStatic = new BSTracker (); - bstStatic->setGradientMap (gMap); + if (gMap) bstStatic->setGradientMap (gMap); if (bstStatic->dynamicScansOn ()) bstStatic->toggleDynamicScans (); if (bstStatic->isAssignedThicknessControlOn ()) bstStatic->toggleAssignedThicknessControl (); diff --git a/Code/FBSD/main.cpp b/Code/FBSD/main.cpp index 0d98a82..867c417 100755 --- a/Code/FBSD/main.cpp +++ b/Code/FBSD/main.cpp @@ -122,12 +122,12 @@ int main (int argc, char *argv[]) } } BSDetector detector; - if (xt) detector.setStaticDetector (true); AbsRat x1, y1, x2, y2; VMap *gMap = NULL; if (gMap != NULL) delete gMap; gMap = new VMap (width, height, tabImage, VMap::TYPE_SOBEL_5X5); detector.setGradientMap (gMap); + if (xt) detector.setStaticDetector (true); // buildGradientImage (0); detector.detectAll (); ofstream outf ("naivelines.txt", ios::out); @@ -175,7 +175,6 @@ int main (int argc, char *argv[]) } } BSDetector detector; - if (xt) detector.setStaticDetector (true); clock_t start = clock (); VMap *gMap = NULL; for (int i = 0; i < repetitions; i++) @@ -183,6 +182,7 @@ int main (int argc, char *argv[]) if (gMap != NULL) delete gMap; gMap = new VMap (width, height, tabImage, VMap::TYPE_SOBEL_5X5); detector.setGradientMap (gMap); + if (xt) detector.setStaticDetector (true); // buildGradientImage (0); detector.detectAll (); } -- GitLab