mirror of
https://github.com/opencv/opencv.git
synced 2024-12-12 07:09:12 +08:00
perViewErr fix
This commit is contained in:
parent
8bfb419b0f
commit
b1020639f1
@ -566,10 +566,11 @@ static double calibrateCameraInternal( const Mat& objectPoints,
|
|||||||
|
|
||||||
// 3. run the optimization
|
// 3. run the optimization
|
||||||
|
|
||||||
auto calibCameraLMCallback = [matM, _m, npoints, &allErrors, aspectRatio, &perViewErrors, flags, releaseObject]
|
Mat perViewErr = perViewErrors ? *perViewErrors : Mat();
|
||||||
|
auto calibCameraLMCallback = [matM, _m, npoints, &allErrors, aspectRatio, &perViewErr, flags, releaseObject]
|
||||||
(InputOutputArray _param, OutputArray JtErr, OutputArray JtJ, double& errnorm) -> bool
|
(InputOutputArray _param, OutputArray JtErr, OutputArray JtJ, double& errnorm) -> bool
|
||||||
{
|
{
|
||||||
Mat jterr = JtErr.getMat(), jtj = JtJ.getMat(), perViewErr = perViewErrors ? *perViewErrors : Mat();
|
Mat jterr = JtErr.getMat(), jtj = JtJ.getMat();
|
||||||
Mat mparam = _param.getMat();
|
Mat mparam = _param.getMat();
|
||||||
cameraCalcJErr(matM, _m, npoints, allErrors, mparam, /* calcJ */ JtErr.needed() && JtJ.needed(),
|
cameraCalcJErr(matM, _m, npoints, allErrors, mparam, /* calcJ */ JtErr.needed() && JtJ.needed(),
|
||||||
jterr, jtj, errnorm,
|
jterr, jtj, errnorm,
|
||||||
@ -588,12 +589,13 @@ static double calibrateCameraInternal( const Mat& objectPoints,
|
|||||||
|
|
||||||
//std::cout << "single camera calib. param after LM: " << param0.t() << "\n";
|
//std::cout << "single camera calib. param after LM: " << param0.t() << "\n";
|
||||||
|
|
||||||
|
// If solver failed, then the last calculated perViewErr can be wrong & should be recalculated
|
||||||
Mat JtErr(nparams, 1, CV_64F), JtJ(nparams, nparams, CV_64F), JtJinv, JtJN;
|
Mat JtErr(nparams, 1, CV_64F), JtJ(nparams, nparams, CV_64F), JtJinv, JtJN;
|
||||||
double reprojErr = 0;
|
double reprojErr = 0;
|
||||||
JtErr.setZero(); JtJ.setZero(); Mat dummy;
|
JtErr.setZero(); JtJ.setZero();
|
||||||
cameraCalcJErr(matM, _m, npoints, allErrors, param0, (stdDevs != nullptr),
|
cameraCalcJErr(matM, _m, npoints, allErrors, param0, (stdDevs != nullptr),
|
||||||
JtErr, JtJ, reprojErr,
|
JtErr, JtJ, reprojErr,
|
||||||
aspectRatio, dummy, flags, releaseObject);
|
aspectRatio, perViewErr, flags, releaseObject);
|
||||||
if (stdDevs)
|
if (stdDevs)
|
||||||
{
|
{
|
||||||
int nparams_nz = countNonZero(mask0);
|
int nparams_nz = countNonZero(mask0);
|
||||||
@ -1078,6 +1080,12 @@ static double stereoCalibrateImpl(
|
|||||||
// geodesic not supported for normal callbacks
|
// geodesic not supported for normal callbacks
|
||||||
LevMarq::Report r = solver.optimize();
|
LevMarq::Report r = solver.optimize();
|
||||||
|
|
||||||
|
// If solver failed, then the last calculated perViewErr can be wrong & should be recalculated
|
||||||
|
if (!r.found && !perViewErr.empty())
|
||||||
|
{
|
||||||
|
lmcallback(param, noArray(), noArray(), reprojErr);
|
||||||
|
}
|
||||||
|
|
||||||
reprojErr = r.energy;
|
reprojErr = r.energy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user