From 6033599c88f7e100338002a15a080cd54ab0d92e Mon Sep 17 00:00:00 2001 From: Simon Lynen Date: Wed, 22 Mar 2023 04:12:51 +0100 Subject: [PATCH] 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 --- modules/imgproc/src/lsd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/imgproc/src/lsd.cpp b/modules/imgproc/src/lsd.cpp index 2f13c5a8a0..8d26a016ab 100644 --- a/modules/imgproc/src/lsd.cpp +++ b/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& reg,