Skip to content

fix getUndistortRectangles() to ignore corners #27374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 4.x
Choose a base branch
from

Conversation

daishironishida
Copy link

@daishironishida daishironishida commented May 28, 2025

getUndistortRectangles() generates points along the image border, and uses the mapping of these points to determine the inscribed/circumscribed rectangles. However undistortPoints() is likely to fail in the image corners, and when it fails, it returns the input point. As a result, the inscribed rectangle cannot be greater than the input image size. This means that the result of getOptimalNewCameraMatrix() for alpha=0 has a smaller FOV than ideal.

Below image plots the points along the image border (Source Points) for a 1280x720 image, and the results of undistortPoints() for an AXIS M2035-LE camera.

Plot

I have edited getUndistortRectangles() to skip the image corners.
It is preferable to only ignore points where undistortPoints() failed, but that requires quite a bit of refactoring.

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
Copy link
Contributor

Related PR: #24927

@daishironishida
Copy link
Author

Looks like test_videoio in Linux x64 Debug timed out. Can I run again?

command timed out: 600 seconds without output running buildenv python ../4.x/opencv/modules/ts/misc/run.py --configuration=Debug --test_tag_skip=size_hd --gtest_output=xml:results_test_videoio.xml -t videoio -a --test_threads=2, attempting to kill
process killed by signal 15
program finished with exit code -1
elapsedTime=668.744162


commands lock was released

@asmorkalov
Copy link
Contributor

Please ignore it.

@asmorkalov asmorkalov requested a review from vpisarev June 10, 2025 12:03
@vpisarev
Copy link
Contributor

vpisarev commented Jun 10, 2025

@daishironishida, thank you for the contribution! Please, add the regression test that fails without your patch and succeeds after applying it.

@asmorkalov asmorkalov added the pr: needs test New functionality requires minimal tests set label Jun 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: calib3d pr: needs test New functionality requires minimal tests set
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy