added handling of camera parameters estimation errors (#3122)

This commit is contained in:
Alexey Spizhevoy
2013-07-03 15:20:14 +04:00
parent 70deda354a
commit 37ea872204
5 changed files with 65 additions and 22 deletions

View File

@@ -101,8 +101,10 @@ void calcDeriv(const Mat &err1, const Mat &err2, double h, Mat res)
namespace cv {
namespace detail {
void HomographyBasedEstimator::estimate(const std::vector<ImageFeatures> &features, const std::vector<MatchesInfo> &pairwise_matches,
std::vector<CameraParams> &cameras)
bool HomographyBasedEstimator::estimate(
const std::vector<ImageFeatures> &features,
const std::vector<MatchesInfo> &pairwise_matches,
std::vector<CameraParams> &cameras)
{
LOGLN("Estimating rotations...");
#if ENABLE_LOG
@@ -164,12 +166,13 @@ void HomographyBasedEstimator::estimate(const std::vector<ImageFeatures> &featur
}
LOGLN("Estimating rotations, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
return true;
}
//////////////////////////////////////////////////////////////////////////////
void BundleAdjusterBase::estimate(const std::vector<ImageFeatures> &features,
bool BundleAdjusterBase::estimate(const std::vector<ImageFeatures> &features,
const std::vector<MatchesInfo> &pairwise_matches,
std::vector<CameraParams> &cameras)
{
@@ -245,7 +248,21 @@ void BundleAdjusterBase::estimate(const std::vector<ImageFeatures> &features,
LOGLN_CHAT("Bundle adjustment, final RMS error: " << std::sqrt(err.dot(err) / total_num_matches_));
LOGLN_CHAT("Bundle adjustment, iterations done: " << iter);
obtainRefinedCameraParams(cameras);
// Check if all camera parameters are valid
bool ok = true;
for (int i = 0; i < cam_params_.rows; ++i)
{
if (isnan(cam_params_.at<double>(i,0)) ||
isinf(cam_params_.at<double>(i,0)))
{
ok = false;
break;
}
}
if (!ok)
return false;
obtainRefinedCameraParams(cameras);
// Normalize motion to center image
Graph span_tree;
@@ -256,6 +273,7 @@ void BundleAdjusterBase::estimate(const std::vector<ImageFeatures> &features,
cameras[i].R = R_inv * cameras[i].R;
LOGLN_CHAT("Bundle adjustment, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
return true;
}