Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4009bca

Browse files
authored
Merge pull request#23025 from savuor:backport3_stddev_calib_fix
Backport of#22992 to 3.4### Pull Request Readiness ChecklistSee details athttps://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request- [x] I agree to contribute to the project under Apache 2 License.- [x] 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- [x] The PR is proposed to the proper branch- [x] There is a reference to the original bug report and related work- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name.- [x] The feature is well documented and sample code can be built with the project CMake
1 parentb71a168 commit4009bca

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

‎modules/calib3d/src/calibration.cpp‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,6 +1549,12 @@ static double cvCalibrateCamera2Internal( const CvMat* objectPoints,
15491549
}
15501550
}
15511551

1552+
Mat mask =cvarrToMat(solver.mask);
1553+
int nparams_nz =countNonZero(mask);
1554+
if (nparams_nz >=2 * total)
1555+
CV_Error_(CV_StsBadArg,
1556+
("There should be less vars to optimize (having %d) than the number of residuals (%d = 2 per point)", nparams_nz,2 * total));
1557+
15521558
// 2. initialize extrinsic parameters
15531559
for( i =0, pos =0; i < nimages; i++, pos += ni )
15541560
{
@@ -1651,27 +1657,24 @@ static double cvCalibrateCamera2Internal( const CvMat* objectPoints,
16511657
{
16521658
if( stdDevs )
16531659
{
1654-
Mat mask =cvarrToMat(solver.mask);
1655-
int nparams_nz =countNonZero(mask);
16561660
Mat JtJinv, JtJN;
16571661
JtJN.create(nparams_nz, nparams_nz, CV_64F);
16581662
subMatrix(cvarrToMat(_JtJ), JtJN, mask, mask);
16591663
completeSymm(JtJN,false);
16601664
cv::invert(JtJN, JtJinv, DECOMP_SVD);
1661-
//sigma2 is deviation of the noise
1662-
//see any papers about variance of the least squares estimator for
1663-
//detailed description of the variance estimation methods
1664-
double sigma2 =norm(allErrors, NORM_L2SQR) / (total - nparams_nz);
1665+
// an explanation of that denominator correction can be found here:
1666+
// R. Hartley, A. Zisserman, Multiple View Geometry in Computer Vision, 2004, section 5.1.3, page 134
1667+
// see the discussion for more details: https://github.com/opencv/opencv/pull/22992
1668+
int nErrors =2 * total - nparams_nz;
1669+
double sigma2 =norm(allErrors, NORM_L2SQR) / nErrors;
16651670
Mat stdDevsM =cvarrToMat(stdDevs);
16661671
int j =0;
16671672
for (int s =0; s < nparams; s++ )
1673+
{
1674+
stdDevsM.at<double>(s) = mask.data[s] ?std::sqrt(JtJinv.at<double>(j,j) * sigma2) :0.0;
16681675
if( mask.data[s] )
1669-
{
1670-
stdDevsM.at<double>(s) =std::sqrt(JtJinv.at<double>(j,j) * sigma2);
16711676
j++;
1672-
}
1673-
else
1674-
stdDevsM.at<double>(s) =0.;
1677+
}
16751678
}
16761679
break;
16771680
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp