Skip to content

calib3d: Fix calibrateCamera() misleading error. - #13803

Merged
opencv-pushbot merged 1 commit into
opencv:3.4from
thangktran:thangktran/fix-misleading-runtime-assertion-calibrateCamera
Feb 12, 2019
Merged

opencv-pushbot merged 1 commit into
opencv:3.4from
thangktran:thangktran/fix-misleading-runtime-assertion-calibrateCamera

Conversation

@thangktran

Copy link
Copy Markdown
Contributor

objectPoints and imagePoints are not checked whether they're empty and
cause checkVector() to fail, thus result in a wrong error message.

Fixes: #6002

This pullrequest changes

  • build successfully locally
  • make test successfully

@thangktran
thangktran force-pushed the thangktran/fix-misleading-runtime-assertion-calibrateCamera branch from 9dfb41a to 59e88e1 Compare February 12, 2019 06:17
Comment thread modules/calib3d/src/calibration.cpp Outdated
ni = objectPoint.checkVector(3, CV_32F);
if ( objectPoint.empty() )
CV_Error(CV_StsBadSize, "objectPoints should not contain empty vector of vectors of points");
else if( ni <= 0 )

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.

BTW,
CV_Error() doesn't return (throws exception), so "else if" is not necessary here.

Something like this:

Mat objectPoint = objectPoints.getMat(i);
if (objectPoint.empty())
    CV_Error(...)
ni = objectPoint.checkVector(3, CV_32F);
if (ni <= 0)
    CV_Error(...)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alalek I think the else if makes more sense.
E.g. if the objectPoint is indeed empty, 2 errors will be printed:

  1. OpenCV Error: The input/output structure size is incorrect (objectPoints should not contain empty vector of vectors of points) in collectCalibrationData
  2. OpenCV Error: Unsupported format or combination of formats (objectPoints should contain vector of vectors of points of type Point3f) in collectCalibrationData

In this case i think it's better that only error no. 1 be printed.
What is your opinion about this?

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.

makes more sense

I understand your point from the code.
But it is correct in case if CV_Error() prints message, but CV_Error()

throws exception

So, there is no way to see both messages and else if is not required here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@alalek You're right. I will fix it.

objectPoints and imagePoints are not checked whether they're empty and
cause checkVector() to fail, thus result in a wrong error message.

Fixes: opencv#6002

@alalek alalek left a comment

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.

Thank you 👍

@opencv-pushbot
opencv-pushbot merged commit a1f4e65 into opencv:3.4 Feb 12, 2019
opencv-pushbot pushed a commit that referenced this pull request Feb 12, 2019
@alalek alalek mentioned this pull request Feb 12, 2019
@thangktran

Copy link
Copy Markdown
Contributor Author

Thank you

@alalek Thank you.

@thangktran
thangktran deleted the thangktran/fix-misleading-runtime-assertion-calibrateCamera branch February 12, 2019 15:43
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
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