From baab7fcfc0cba6b278f0159f84dffa800f6b22d5 Mon Sep 17 00:00:00 2001 From: Peihong Guo Date: Thu, 4 Feb 2016 23:28:08 -0600 Subject: [PATCH] Multi image reconstruction with subset selection finished. --- multiimagereconstructor.h | 43 +++++++++++++++++++++++++++++++-------- statsutils.h | 28 +++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 11 deletions(-) diff --git a/multiimagereconstructor.h b/multiimagereconstructor.h index 6278fb7..d5e3c3d 100644 --- a/multiimagereconstructor.h +++ b/multiimagereconstructor.h @@ -149,10 +149,13 @@ bool MultiImageReconstructor::Reconstruct() { vector identity_weights_history; vector identity_weights_centroid_history; + vector consistent_set(num_images); + for(int i=0;i::Reconstruct() { identity_weights_history.push_back(identity_weights); // Remove outliers - vector consistent_set = StatsUtils::FindConsistentSet(identity_weights, 0.5); + #if 1 + const double ratios[] = {0.0, 0.2, 0.4, 0.6}; + consistent_set = StatsUtils::FindConsistentSet(identity_weights, 0.5, ratios[iters_main_loop] * num_images, &identity_centroid); assert(consistent_set.size() > 0); - + for(auto i : consistent_set) { + cout << i << ' '; + } + cout << endl; + #else // Compute the centroid of the consistent set identity_centroid = VectorXd::Zero(param_sets[0].model.Wid.rows()); for(auto i : consistent_set) { + cout << i << endl; identity_centroid += param_sets[i].model.Wid; } identity_centroid /= consistent_set.size(); + #endif // Update the identity weights for all images for(auto& param : param_sets) { @@ -215,10 +226,19 @@ bool MultiImageReconstructor::Reconstruct() { } // Joint reconstruction step, obtain refined identity weights - const int num_iters_joint_optimization = 3; - for(int i=0;i::Reconstruct() { } } + if((iters_joint_optimization == num_iters_joint_optimization - 1) && (iters_main_loop == max_iters_main_loop)) { + // In the final iteration, no need to refine the identity weights anymore + break; + } + // [Joint reconstruction] step 2: estimate identity weights jointly { ceres::Problem problem; VectorXd params = param_sets[0].model.Wid; // Add constraints from each image - for(int i=0;i model_projected_i(param_sets[i].indices.size()); for(int j=0;j::Reconstruct() { ceres::DynamicNumericDiffCostFunction *prior_cost_function = new ceres::DynamicNumericDiffCostFunction( new PriorCostFunction(prior.Wid_avg, prior.inv_sigma_Wid, - prior.weight_Wid * num_images)); + prior.weight_Wid * consistent_set.size())); prior_cost_function->AddParameterBlock(params.size()); prior_cost_function->SetNumResiduals(1); problem.AddResidualBlock(prior_cost_function, NULL, params.data()); @@ -352,7 +377,7 @@ bool MultiImageReconstructor::Reconstruct() { } // Visualize the final reconstruction results - for(size_t i=0;iBindConstraints(image_points_pairs[i].second); diff --git a/statsutils.h b/statsutils.h index 21cdc3f..795f6ff 100644 --- a/statsutils.h +++ b/statsutils.h @@ -78,7 +78,7 @@ static vector FindConsistentSet(const MatrixXd& x, double h, int k, while(!done && iters < max_iters) { for(int i=0;i FindConsistentSet(const MatrixXd& x, double h, int k, vector d(nsamples, 0); for(int i=0;i max_d) { + max_d = d[i]; + max_idx = i; + } + } + + VectorXd centroid = y.col(max_idx); if(centroid_out != nullptr) { // Write the centroid to the output + *centroid_out = centroid; } // Compute the distance between the centroid and each input point + vector> dists(nsamples); + for(int i=0;i& a, const pair& b) { + return a.second < b.second; + }); // Pick the k nearest points as the consistent set + vector consistent_set; + for(int i=0;i