Make LineSegmentDetector deterministic by using stable_sort for ordering keypoints prior to region growing

This makes LineSegmentDetector deterministic by using stable_sort for ordering points by norm. Without this change the region growing in LSD is non-determinstic and thus the returned lines are changing between invocations.

This is a replacement for https://github.com/opencv/opencv/pull/23370
pull/23388/head
Simon Lynen 2 years ago committed by GitHub
parent a924bbfc30
commit 6033599c88
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      modules/imgproc/src/lsd.cpp

@ -592,8 +592,8 @@ void LineSegmentDetectorImpl::ll_angle(const double& threshold,
}
}
// Sort
std::sort(ordered_points.begin(), ordered_points.end(), compare_norm);
// Use stable sort to ensure deterministic region growing and thus overall LSD result determinism.
std::stable_sort(ordered_points.begin(), ordered_points.end(), compare_norm);
}
void LineSegmentDetectorImpl::region_grow(const Point2i& s, std::vector<RegionPoint>& reg,

Loading…
Cancel
Save