Skip to content

Fix maxIter parameter in usac findEssentialMat #22967

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
stopmosk:usac-maxiters-bugfix
Dec 21, 2022
Merged

Fix maxIter parameter in usac findEssentialMat #22967
asmorkalov merged 1 commit intoopencv:4.xfrom
stopmosk:usac-maxiters-bugfix

Conversation

@stopmosk
Copy link
Copy Markdown
Contributor

@stopmosk stopmosk commented Dec 15, 2022

Added a default parameter maxIters to findEssentialMat and replaced the hardcoded value of 1000 in ransac_solvers.hpp. Fix for issue #22696

Test to check:

def roll():
    kpts0 = np.random.rand(2, 50)
    kpts1 = np.random.rand(2, 50)
    norm_thresh = .5
    conf = .5

    a = cv2.findEssentialMat(
        kpts0, kpts1, np.eye(3), threshold=norm_thresh, prob=conf, method=cv2.USAC_MAGSAC, maxIters = 1
    )

    b = cv2.findEssentialMat(
        kpts0, kpts1, np.eye(3), threshold=norm_thresh, prob=conf, method=cv2.USAC_MAGSAC, maxIters = 5000
    )
    return not (np.array_equal(a[0], b[0]) and np.array_equal(a[1], b[1]))


results_sum = sum([roll() for _ in range(10)])
print('Test failed' if results_sum == 0 else 'Test OK')

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

@asmorkalov asmorkalov added category: calib3d pr: needs test New functionality requires minimal tests set labels Dec 15, 2022
@asmorkalov
Copy link
Copy Markdown
Contributor

@stopmosk could you add simple test to prove the result.

@asmorkalov
Copy link
Copy Markdown
Contributor

@ivashmak Could you take a look?

@asmorkalov asmorkalov added this to the 4.7.0 milestone Dec 15, 2022
@asmorkalov asmorkalov requested a review from vpisarev December 16, 2022 10:15
@asmorkalov asmorkalov self-assigned this Dec 20, 2022
@asmorkalov asmorkalov added bug and removed pr: needs test New functionality requires minimal tests set labels Dec 20, 2022
@asmorkalov
Copy link
Copy Markdown
Contributor

@alalek could we merge the patch?

@ivashmak
Copy link
Copy Markdown
Contributor

@ivashmak Could you take a look?

Everything looks fine, but I would also suggest changing this line:
if (method >= 32 && method <= 38) in https://github.com/stopmosk/opencv/blob/usac-maxiters-bugfix/modules/calib3d/src/five-point.cpp#L436
By replacing 32 and 38 with USAC_ flags.

@asmorkalov
Copy link
Copy Markdown
Contributor

@ivashmak Thanks a lot for the review. I fixed your remark and squashed commits before merge.

@asmorkalov asmorkalov removed the request for review from vpisarev December 21, 2022 06:54
@asmorkalov asmorkalov merged commit 63b6b24 into opencv:4.x Dec 21, 2022
@alalek alalek mentioned this pull request Jan 8, 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.

3 participants