Repository navigation
Conversation
Adds UniformRandomGenerator::setGlobalSeed(seed) / clearGlobalSeed(), mirroring cv::setRNGSeed. When a seed is set, every subsequently constructed generator is seeded deterministically (std::mt19937(seed)) instead of from std::random_device; clearing restores nondeterministic behavior. Default behavior is unchanged. This makes RANSAC sampling reproducible for debugging. All URG-based samplers (Uniform, PROSAC, Progressive-NAPSAC, Importance) construct their generator via the default constructor, so they all honor the seed with no per-sampler change. Samplers/solvers that use std::rand()/Eigen::Random (AdaptiveReordering, PnP bundle adjustment, DLS/SIFT) are made reproducible by the caller via std::srand(seed). Enables the seed parameter exposed in the pymagsac Python API (companion magsac PR).
f-dy
added a commit
to f-dy/magsac
that referenced
this pull request
May 31, 2026
Adds a 'seed' argument (default -1 = nondeterministic) to all 14 find* estimators. When seed >= 0 the run is reproducible: a shared helper (applyMagsacSeed) sets UniformRandomGenerator::setGlobalSeed(seed) for all URG-based samplers and std::srand(seed) for the std::rand()/Eigen::Random solver paths. Bumps the graph-cut-ransac submodule to include setGlobalSeed/clearGlobalSeed. Combines danini#48 (seed for the pre-existing estimators) and danini/graph-cut-ransac#51 (the seed mechanism), extended to the new estimators added in danini#45 (incl. findPlane3D).
f-dy
marked this pull request as ready for review
May 31, 2026 22:21
f-dy
marked this pull request as draft
May 31, 2026 22:41
…seeds With a seed, every generator got the same one, so P-NAPSAC's three generators (its own and those of its two nested PROSAC samplers) produced the same stream. They now get seed, seed + 1, seed + 2, ... The seed is per thread (thread_local), so threads don't race on the counter. Test: tests/cpp/test_uniform_random_generator.cpp (CMake option BUILD_TESTS, run with ctest). It fails on the previous version.
f-dy
marked this pull request as ready for review
November 14, 2026 08:57
f-dy
added a commit
to f-dy/magsac
that referenced
this pull request
Nov 14, 2026
…lable (73b2f5a) It merges upstream master and danini/graph-cut-ransac#51 (random seed, used by danini#48), danini#52 (line solver's null sample, needed by danini#45, danini#52 and danini#55), danini#53, danini#56, danini#59 and danini#61. The commit is only on the fork, hence .gitmodules' fork URL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Each sampler (uniform, PROSAC, P-NAPSAC, NAPSAC, importance) seeds its random generator,
UniformRandomGenerator, fromstd::random_device, so runs can't be repeated. This PR addsUniformRandomGenerator<size_t>::setGlobalSeed(seed): the generators created afterwards are seeded withseed,seed + 1,seed + 2, …, so a run started after the same seed draws the same samples.clearGlobalSeed()goes back tostd::random_device. Without a call to either, nothing changes.danini/magsac#48 uses it to add a
seedargument to MAGSAC's Python estimators.Changes
uniform_random_generator.h: the seed of the next generator, used and incremented by the constructor.thread_local): a seed set in one thread doesn't affect generators created in others, and threads don't race on the counter.std::rand(the AR-Sampler) aren't affected: callers seed them withstd::srand.Testing
tests/cpp/test_uniform_random_generator.cpp, built with the new CMake optionBUILD_TESTS(off by default) and run withctest. It checks that two generators created after one seed differ, that the same seed gives them again, that P-NAPSAC's own generator doesn't repeat the stream its first PROSAC sampler gets, and that unseeded generators differ. It passes, and fails on the previous version of this PR, where every generator got the same seed.The other open PRs of this repository (#50, #52, #53, #56) touch other files and merge cleanly with this one, in any order.
Updates after review: the comment of
setGlobalSeednow says that the seed applies only to the generators created in the calling thread.