Skip to content

Commit 1318118

Browse files
committed
Update edge_drawing.cpp
1 parent 45ec9ad commit 1318118

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

modules/ximgproc/src/edge_drawing.cpp

+16-14
Original file line numberDiff line numberDiff line change
@@ -2466,51 +2466,53 @@ void EdgeDrawingImpl::TestSegment(int i, int index1, int index2)
24662466
TestSegment(i, start, index2);
24672467
}
24682468

2469-
//----------------------------------------------------------------------------------------------
2470-
// After the validation of the edge segments, extracts the valid ones
2471-
// In other words, updates the valid segments' pixel arrays and their lengths
2469+
// After validating the edge segments, this function extracts the valid ones.
2470+
// Specifically, it updates the valid segments' pixel arrays and their lengths based on validation.
24722471
void EdgeDrawingImpl::ExtractNewSegments()
24732472
{
24742473
vector< vector<Point> > validSegments;
2475-
int noSegments = 0;
24762474

24772475
for (int i = 0; i < segmentNos; i++) {
24782476
int start = 0;
24792477
while (start < (int)segmentPoints[i].size()) {
24802478

2479+
// Find the first valid start point
24812480
while (start < (int)segmentPoints[i].size()) {
24822481
int r = segmentPoints[i][start].y;
24832482
int c = segmentPoints[i][start].x;
24842483

2485-
if (edgeImg[r * width + c]) break;
2484+
if (edgeImg[r * width + c]) break; // Found valid point
24862485
start++;
24872486
}
24882487

24892488
int end = start + 1;
2489+
2490+
// Find the end of the valid segment
24902491
while (end < (int)segmentPoints[i].size()) {
24912492
int r = segmentPoints[i][end].y;
24922493
int c = segmentPoints[i][end].x;
24932494

2494-
if (edgeImg[r * width + c] == 0) break;
2495+
if (edgeImg[r * width + c] == 0) break; // End of segment
24952496
end++;
24962497
}
24972498

2499+
// Length of the segment
24982500
int len = end - start;
2501+
2502+
// Only accept segments of length >= 10
24992503
if (len >= 10) {
2500-
// A new segment. Accepted only only long enough (whatever that means)
2501-
//segments[noSegments].pixels = &map->segments[i].pixels[start];
2502-
//segments[noSegments].noPixels = len;
2503-
validSegments.push_back(vector<Point>());
2504-
vector<Point> subVec(&segmentPoints[i][start], &segmentPoints[i][end]);
2505-
validSegments[noSegments] = subVec;
2506-
noSegments++;
2504+
vector<Point> subVec(segmentPoints[i].begin() + start, segmentPoints[i].begin() + end); // Safer bounds
2505+
validSegments.push_back(subVec); // Add to valid segments
25072506
}
2507+
2508+
// Move start to next unprocessed point
25082509
start = end + 1;
25092510
}
25102511
}
25112512

2513+
// Replace the old segments with valid segments
25122514
segmentPoints = validSegments;
2513-
segmentNos = noSegments;
2515+
segmentNos = validSegments.size(); // Update number of segments
25142516
}
25152517

25162518
double EdgeDrawingImpl::NFA(double prob, int len)

0 commit comments

Comments
 (0)