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;
}

View File

@@ -102,7 +102,8 @@ Stitcher::Status Stitcher::estimateTransform(InputArray images, const std::vecto
if ((status = matchImages()) != OK)
return status;
estimateCameraParams();
if ((status = estimateCameraParams()) != OK)
return status;
return OK;
}
@@ -442,10 +443,11 @@ Stitcher::Status Stitcher::matchImages()
}
void Stitcher::estimateCameraParams()
Stitcher::Status Stitcher::estimateCameraParams()
{
detail::HomographyBasedEstimator estimator;
estimator(features_, pairwise_matches_, cameras_);
if (!estimator(features_, pairwise_matches_, cameras_))
return ERR_HOMOGRAPHY_EST_FAIL;
for (size_t i = 0; i < cameras_.size(); ++i)
{
@@ -456,7 +458,8 @@ void Stitcher::estimateCameraParams()
}
bundle_adjuster_->setConfThresh(conf_thresh_);
(*bundle_adjuster_)(features_, pairwise_matches_, cameras_);
if (!(*bundle_adjuster_)(features_, pairwise_matches_, cameras_))
return ERR_CAMERA_PARAMS_ADJUST_FAIL;
// Find median focal length and use it as final image scale
std::vector<double> focals;
@@ -481,6 +484,8 @@ void Stitcher::estimateCameraParams()
for (size_t i = 0; i < cameras_.size(); ++i)
cameras_[i].R = rmats[i];
}
return OK;
}
} // namespace cv