Skip to content

Fix intrinsics processing in case USAC parameters#21166

Merged
alalek merged 2 commits intoopencv:4.xfrom
rayonnant14:issue_21105
Dec 13, 2021
Merged

Fix intrinsics processing in case USAC parameters#21166
alalek merged 2 commits intoopencv:4.xfrom
rayonnant14:issue_21105

Conversation

@rayonnant14
Copy link
Copy Markdown
Contributor

@rayonnant14 rayonnant14 commented Nov 30, 2021

fixes #21105
relates #17683

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Please add simple regression tests case based on code from the issue.

void Utils::calibratePoints (const Mat &K1, const Mat &K2, const Mat &points, Mat &calib_points) {
const auto * const points_ = (float *) points.data;
const auto * const k1 = (double *) K1.data;
const auto * const k1 = K1.isContinuous() ? (double *) K1.data : (double *) K1.clone().data;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K1.clone().data

Don't use dangling pointers.
This expression creates temporary object which is disposed before the next line.


To declare assumptions of this code we should have several checks:

  • CV_Assert(K1.isContinuous());
  • CV_CheckDepthEQ(K1.depth(), CV_32F, ""); due to assumption (double *) K1.data
  • CV_CheckEQ(K1.total(), (size_t)9, "");
  • and similar for other types.

To avoid such "void" interface checks it is better to use const Matx33d& K1 parameters in internal API.


.clone() should be done by caller function of this function (or convert to Matx33d).

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you 👍

@alalek alalek merged commit 456137f into opencv:4.x Dec 13, 2021
@alalek alalek mentioned this pull request Dec 30, 2021
@alalek alalek mentioned this pull request Feb 22, 2022
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
Fix intrinsics processing in case USAC parameters

* fixed USAC intrinsics processing

* change mat to matx33d, added test
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.

solvePnPRansac with USAC returns empty inlier cv::Mat

2 participants