From 70ade93a5802f97a3aa3a4e9937e654c5a5461f2 Mon Sep 17 00:00:00 2001 From: Eduardo Sousa Date: Mon, 20 May 2024 20:50:42 -0300 Subject: [PATCH] (FIX) Fixed minimum size check for initialized segments --- src/EdgeDrawer.cpp | 8 ++++++-- src/FullSegmentInfo.h | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/EdgeDrawer.cpp b/src/EdgeDrawer.cpp index 2b82a87..0b72d81 100644 --- a/src/EdgeDrawer.cpp +++ b/src/EdgeDrawer.cpp @@ -102,7 +102,7 @@ void EdgeDrawer::drawEdgeTreeStack(Pixel anchor, ImageEdge &initialPixels, bool // The index in the pixels array of the last segment we have tried to add uint8_t direction, gradDir, lineDirection; - int i, indexInArray, lastChekedPxIdx, initialPxIndex, indexInImage, nElements; + int i, indexInArray, lastChekedPxIdx, initialPxIndex, indexInImage, nElements, minSize; bool addPixelsForTheFirstSide, inlierOverwritten, popStack, firstBranch, isAnchorFirstPx, wasExtended; bool localSegInitialized, segment; Pixel px, lastPx; @@ -205,8 +205,12 @@ void EdgeDrawer::drawEdgeTreeStack(Pixel anchor, ImageEdge &initialPixels, bool // Mark the pixel as edge only if it is an inlier edgeImg[indexInArray] = UPM_ED_EDGE_PIXEL; + minSize = localSegInitialized + ? localSegment->getLastPixelIndex() + 1 + UPM_SKIP_EDGE_PT + : lastChekedPxIdx + minLineLength; + // If there are enough pixels try to fit a segment to them - if (pixels.size() - lastChekedPxIdx >= minLineLength) { + if (pixels.size() >= minSize) { //If we have already set the first minLineLength pixels, just add the new UPM_SKIP_EDGE_PT ones if (localSegInitialized) { localSegment->skipPositions(); diff --git a/src/FullSegmentInfo.h b/src/FullSegmentInfo.h index d08ab85..cb79498 100644 --- a/src/FullSegmentInfo.h +++ b/src/FullSegmentInfo.h @@ -76,6 +76,9 @@ class FullSegmentInfo { //Returns the Pixel in the first extreme of the segment inline const Pixel &getLastPixel() const { return lastPx; } + //Returns the index for Pixel in the second extreme of the segment + inline const int getLastPixelIndex() const { return lastPxIndex; } + // Returns a pointer to the first pixel of the segment inline const Pixel *begin() const { return &((*pixels)[firstPxIndex]); }