Skip to content

USAC fix: GraphCut fails to allocate big dense matrices#23073

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
savuor:fix_graphcut_used_edges_dense
Jan 20, 2023
Merged

USAC fix: GraphCut fails to allocate big dense matrices#23073
asmorkalov merged 1 commit intoopencv:4.xfrom
savuor:fix_graphcut_used_edges_dense

Conversation

@savuor
Copy link
Copy Markdown
Contributor

@savuor savuor commented Jan 2, 2023

TODO:

  • rebase it on 4.x without other USAC code

Bug description

The bug arises in #22884 when setting a number of points to numbers like 60000 and bigger.
For N samples GraphCut tries to allocate an edge connectivity matrix of size NxN and segfaults on big numbers, see here.

Changes

The solution is to use std::set<int> instead of std::vector<bool>.
Despite theoretically longer read/write time, like O(log N) vs O(1), I've got +30% performance on my machine, probably because of CPU caching.

The bug reproducer is just a usac_testUsacParams.accuracy test with bigger pts_size.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Add `estimateSE2(...)`, `estimateSE3(...)`, `estimateSIM2(...)`, `estimateSIM3(...)` for estimating an geometric transformation with rotation and translation (with scaling for SIM) using USAC: as alternative for `estimateAffinePartial2D` and `estimateAffine3D`.

Modified test module.

Remove unused variables.

Remove initializer of unused variable.

Add interfaces to accept UsacParams() and corresponding test codes.

Revise test code.

PartialNd removed

Umeyama rewritten for code quality & speed

comments & minors

rise number of points

fix, and +30% faster!

only one number should be that big

remove USAC code, leave fix only

big number
@savuor savuor force-pushed the fix_graphcut_used_edges_dense branch from 2400eb7 to dbdd357 Compare January 18, 2023 01:13
@asmorkalov asmorkalov added backport is needed Label for maintainers. Authors of PR can ignore this and removed backport is needed Label for maintainers. Authors of PR can ignore this labels Jan 18, 2023
@asmorkalov asmorkalov added this to the 4.8.0 milestone Jan 20, 2023
@asmorkalov asmorkalov merged commit 3085fc6 into opencv:4.x Jan 20, 2023
@savuor savuor deleted the fix_graphcut_used_edges_dense branch January 24, 2023 02:38
@alalek alalek mentioned this pull request Jan 28, 2023
@asmorkalov asmorkalov mentioned this pull request May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants