diff --git a/src/BaseApp.h b/src/BaseApp.h index ef29dde..70c093d 100644 --- a/src/BaseApp.h +++ b/src/BaseApp.h @@ -388,10 +388,10 @@ class BaseApp /* Output routines */ /* IO routines */ - void ReadGeometricConstraints(char *filename); - void WriteGeometricConstraints(char *filename); - void WriteTracksForSameer(char *filename); + void ReadGeometricConstraints(const char *filename); + void WriteGeometricConstraints(const char *filename); void WriteTracks(char *filename); + void WriteTracks2(char *filename); void ReadCameraConstraints(); void ReadPointConstraints(); void ReadIntrinsicsFile(); @@ -405,12 +405,12 @@ class BaseApp void ReadKeyColors(); /* Read in information about the world */ - void ReadBundleFile(char *filename); - void ReloadBundleFile (char *filename); + void ReadBundleFile(const char *filename); + void ReloadBundleFile (const char *filename); /* Read/write line segments */ - void ReadLines3D(char *filename); - void WriteLines3D(char *filename); + void ReadLines3D(const char *filename); + void WriteLines3D(const char *filename); /* Clear the current model */ void ClearModel(); @@ -448,14 +448,14 @@ class BaseApp #ifndef __DEMO__ /* Write point files to a ply file */ - void DumpPointsToPly(char *output_directory, char *filename, + void DumpPointsToPly(const char *output_directory, const char *filename, int num_points, int num_cameras, v3_t *points, v3_t *colors, camera_params_t *cameras /*bool reflect = true*/); /* Dump an output file containing information about the current * state of the world */ - void DumpOutputFile(char *output_dir, char *filename, + void DumpOutputFile(const char *output_dir, const char *filename, int num_images, int num_cameras, int num_points, int *added_order, camera_params_t *cameras, v3_t *points, v3_t *colors, @@ -578,14 +578,14 @@ class BaseApp bool m_bundle_provided; /* Was a bundle adjustment file given? */ char *m_bundle_file; /* Bundle file */ - char *m_match_directory; /* Which directory are the matches - * stored in? */ - char *m_match_index_dir; /* Which directory are match indexes - * stored in? */ - char *m_match_table; /* File where match table is stored */ - char *m_key_directory; - char *m_image_directory; - char *m_sift_binary; /* Where can we find the sift binary? */ + const char *m_match_directory; /* Which directory are the matches + * stored in? */ + const char *m_match_index_dir; /* Which directory are match indexes + * stored in? */ + const char *m_match_table; /* File where match table is stored */ + const char *m_key_directory; + const char *m_image_directory; + const char *m_sift_binary; /* Where can we find the sift binary? */ bool m_estimate_up_vector_szeliski; /* Estimate the up vector * using Rick's method? */ diff --git a/src/BaseGeometry.cpp b/src/BaseGeometry.cpp index db38033..e117ff3 100644 --- a/src/BaseGeometry.cpp +++ b/src/BaseGeometry.cpp @@ -99,7 +99,7 @@ void BaseApp::WriteTrackPairs(const char *filename) fclose(f); } -void BaseApp::ReadGeometricConstraints(char *filename) { +void BaseApp::ReadGeometricConstraints(const char *filename) { FILE *f = fopen(filename, "r"); int num_images; // = GetNumImages(); @@ -270,7 +270,7 @@ void BaseApp::ReadGeometricConstraints(char *filename) { // WriteGeometricConstraints("constraints_test.txt"); } -void BaseApp::WriteGeometricConstraints(char *filename) { +void BaseApp::WriteGeometricConstraints(const char *filename) { FILE *f = fopen(filename, "w"); if (f == NULL) { @@ -392,7 +392,8 @@ void BaseApp::WriteTracks(char *filename) fclose(f); } -void BaseApp::WriteTracksForSameer(char *filename) { +void BaseApp::WriteTracks2(char *filename) +{ FILE *f = fopen(filename, "w"); if (f == NULL) { diff --git a/src/Bundle.cpp b/src/Bundle.cpp index 1b91ec7..6d23814 100644 --- a/src/Bundle.cpp +++ b/src/Bundle.cpp @@ -437,8 +437,9 @@ void BundlerApp::ReRunSFM(double *S, double *U, double *V, double *W) num_images, num_init_cams, num_pts, added_order, cameras, init_pts, colors, pt_views); - RunSFM(num_pts, num_init_cams, 0, false, cameras, init_pts, added_order, - colors, pt_views, 0.0 /*eps2*/, S, U, V, W); + RunSFM(num_pts, num_init_cams, 0, false, cameras, + init_pts, added_order, colors, pt_views, + 0, 0, 0, 0.0 /*eps2*/, S, U, V, W); /* Save the camera parameters and points */ @@ -530,13 +531,50 @@ static int compare_doubles(const void *d1, const void *d2) return 0; } - double BundlerApp::RunSFM(int num_pts, int num_cameras, int start_camera, - bool fix_points, camera_params_t *init_camera_params, + bool fix_points, + camera_params_t *init_camera_params, v3_t *init_pts, int *added_order, v3_t *colors, - std::vector &pt_views, double eps2, + std::vector &pt_views, + int max_iter, int max_iter2, + int verbosity, double eps2, double *S, double *U, double *V, double *W, - bool remove_outliers) + bool remove_outliers, bool final_bundle, + bool write_intermediate) +{ +#ifdef __USE_CERES__ + if (!m_use_ceres) { + return + RunSFM_SBA(num_pts, num_cameras, start_camera, fix_points, + init_camera_params, init_pts, + added_order, colors, pt_views, eps2, S, U, V, W, + remove_outliers); + } else { /* use_ceres */ + return + RunSFM_Ceres(num_pts, num_cameras, start_camera, fix_points, + init_camera_params, init_pts, added_order, colors, pt_views, + max_iter, max_iter2, verbosity, eps2, S, U, V, W, + remove_outliers, final_bundle, write_intermediate); + } +#else + /* Just use SBA */ + return + RunSFM_SBA(num_pts, num_cameras, start_camera, fix_points, + init_camera_params, init_pts, + added_order, colors, pt_views, + max_iter, max_iter2, verbosity, eps2, S, U, V, W, + remove_outliers, final_bundle, write_intermediate); +#endif +} + +double BundlerApp::RunSFM_SBA(int num_pts, int num_cameras, int start_camera, + bool fix_points, + camera_params_t *init_camera_params, + v3_t *init_pts, int *added_order, v3_t *colors, + std::vector &pt_views, + double eps2, + double *S, double *U, double *V, double *W, + bool remove_outliers) { #define MIN_POINTS 20 int num_outliers = 0; @@ -547,6 +585,8 @@ double BundlerApp::RunSFM(int num_pts, int num_cameras, int start_camera, int *remap = new int [num_pts]; v3_t *nz_pts = new v3_t[num_pts]; + const int MIN_OUTLIERS = 40; + do { if (num_pts - total_outliers < MIN_POINTS) { printf("[RunSFM] Too few points remaining, exiting!\n"); @@ -863,7 +903,7 @@ double BundlerApp::RunSFM(int num_pts, int num_cameras, int start_camera, if (!remove_outliers) break; - } while (num_outliers > 0); + } while (num_outliers > MIN_OUTLIERS); delete [] remap; delete [] nz_pts; @@ -1862,11 +1902,9 @@ void BundlerApp::EstimateIgnoredCameras(int &curr_num_cameras, } } -#if 1 - /* TEST */ RunSFM(curr_num_pts, curr_num_cameras, 0, true, - cameras, points, added_order, colors, pt_views, 1.0e-20 /*eps*/); -#endif + cameras, points, added_order, colors, pt_views, + 1.0e-20 /*eps*/); int pt_count = BundleAdjustAddAllNewPoints(curr_num_pts, curr_num_cameras, @@ -1916,11 +1954,8 @@ void BundlerApp::EstimateIgnoredCameras(int &curr_num_cameras, #endif } -#if 1 - /* TEST */ RunSFM(curr_num_pts, curr_num_cameras, 0, true, - cameras, points, added_order, colors, pt_views, 1.0e-20); -#endif + cameras, points, added_order, colors, pt_views, 1.0e-20); pt_count = BundleAdjustAddAllNewPoints(curr_num_pts, curr_num_cameras, @@ -2103,8 +2138,8 @@ void BundlerApp::BundleAdjust() double *S = new double[2 * 2 * cnp * cnp]; double error0; error0 = RunSFM(curr_num_pts, 2, 0, false, - cameras, points, added_order, colors, pt_views, 0.0, - S, NULL, NULL, NULL, !m_fix_necker); + cameras, points, added_order, colors, pt_views, + 0, 0, 0, 0.0, S, NULL, NULL, NULL, !m_fix_necker); delete [] S; @@ -2332,7 +2367,7 @@ void BundlerApp::BundleAdjust() /* Run sfm again to update parameters */ RunSFM(curr_num_pts, round + 1, 0, false, - cameras, points, added_order, colors, pt_views); + cameras, points, added_order, colors, pt_views); /* Remove bad points and cameras */ RemoveBadPointsAndCameras(curr_num_pts, curr_num_cameras + 1, @@ -3528,7 +3563,7 @@ void BundlerApp::BundleInitializeImageFullBundle(int image_idx, int parent_idx, if (!m_skip_full_bundle) { /* Run sfm again to update parameters */ RunSFM(num_points, num_cameras + 1, 0, false, - cameras, points, added_order, colors, pt_views); + cameras, points, added_order, colors, pt_views); } } diff --git a/src/Bundle2PMVS.cpp b/src/Bundle2PMVS.cpp index 09a35f0..c8813ea 100644 --- a/src/Bundle2PMVS.cpp +++ b/src/Bundle2PMVS.cpp @@ -23,7 +23,7 @@ typedef struct } point_t; -void ReadListFile(char *list_file, std::vector &files) +void ReadListFile(const char *list_file, std::vector &files) { FILE *f = fopen(list_file, "r"); @@ -41,7 +41,7 @@ void ReadListFile(char *list_file, std::vector &files) fclose(f); } -void ReadBundleFile(char *bundle_file, +void ReadBundleFile(const char *bundle_file, std::vector &cameras, std::vector &points, double &bundle_version) { @@ -141,7 +141,8 @@ void ReadBundleFile(char *bundle_file, fclose(f); } -void WritePMVS(const char *output_path, char *list_file, char *bundle_file, +void WritePMVS(const char *output_path, + const char *list_file, const char *bundle_file, std::vector images, std::vector &cameras) { @@ -261,9 +262,9 @@ int main(int argc, char **argv) return 1; } - char *list_file = argv[1]; - char *bundle_file = argv[2]; - char *output_path = "pmvs"; + const char *list_file = argv[1]; + const char *bundle_file = argv[2]; + const char *output_path = "pmvs"; if (argc == 4) output_path = argv[3]; diff --git a/src/BundleCeres.cpp b/src/BundleCeres.cpp index 71ffef3..33f33d0 100644 --- a/src/BundleCeres.cpp +++ b/src/BundleCeres.cpp @@ -799,8 +799,8 @@ double BundlerApp::RunSFM_Ceres(int num_pts, int num_cameras, printf("[RunSFM] %d points completely removed\n", num_dead); RemoveBadPointsAndCameras(num_pts, num_cameras, - added_order, init_camera_params, init_pts, colors, - pt_views); + added_order, init_camera_params, + init_pts, colors, pt_views); } else if (round == 0) { RemoveBadPointsAndCameras(num_pts, num_cameras, added_order, init_camera_params, diff --git a/src/BundleFast.cpp b/src/BundleFast.cpp index e34ea90..9bc797b 100644 --- a/src/BundleFast.cpp +++ b/src/BundleFast.cpp @@ -272,14 +272,20 @@ void BundlerApp::BundleAdjustFast() if (max_matches < m_min_max_matches) break; /* No more connections */ - /* Find all images with 90% of the matches of the maximum */ + /* Find all images with 75% of the matches of the maximum + * (unless overruled by m_num_points_add_camera) */ std::vector image_set; - if (false && max_matches < 48) { + if (false && max_matches < 48) { /* disabling this */ image_set.push_back(ImagePair(max_cam, parent_idx)); } else { - // int nMatches = MIN(100, iround(0.75 /* 0.9 */ * max_matches)); - int nMatches = iround(0.75 /* 0.9 */ * max_matches); + int nMatches = iround(0.75 * max_matches); + + if (m_num_matches_add_camera > 0) { + /* Alternate threshold based on user parameter */ + nMatches = std::min(nMatches, m_num_matches_add_camera); + } + image_set = FindCamerasWithNMatches(nMatches, curr_num_cameras, curr_num_pts, @@ -312,10 +318,11 @@ void BundlerApp::BundleAdjustFast() bool success = false; camera_params_t camera_new = BundleInitializeImage(m_image_data[next_idx], - next_idx, curr_num_cameras + image_count, + next_idx, + curr_num_cameras + image_count, curr_num_cameras, curr_num_pts, added_order, points, - NULL /*cameras + parent_idx*/, cameras, + NULL, cameras, pt_views, &success); if (success) { @@ -497,7 +504,6 @@ void BundlerApp::BundleAdjustFast() #else pdata.m_views = pt_views[i]; #endif - // pdata.m_views = pt_views[i]; m_point_data.push_back(pdata); } diff --git a/src/BundleIO.cpp b/src/BundleIO.cpp index 383c918..1c4651f 100644 --- a/src/BundleIO.cpp +++ b/src/BundleIO.cpp @@ -428,7 +428,7 @@ void BaseApp::LoadImageNamesFromFile(FILE *f) } /* Read in information about the world */ -void BaseApp::ReadBundleFile(char *filename) +void BaseApp::ReadBundleFile(const char *filename) { printf("[ReadBundleFile] Reading file...\n"); @@ -620,7 +620,7 @@ void BaseApp::ReadBundleFile(char *filename) num_min_views_points, num_points); } -void BaseApp::ReloadBundleFile(char *filename) +void BaseApp::ReloadBundleFile(const char *filename) { #ifndef __DEMO__ /* Count the old number of cameras */ @@ -741,7 +741,7 @@ void BaseApp::ClearModel() #ifndef __DEMO__ /* Dump an output file containing information about the current * state of the world */ -void BaseApp::DumpOutputFile(char *output_dir, char *filename, +void BaseApp::DumpOutputFile(const char *output_dir, const char *filename, int num_images, int num_cameras, int num_points, int *added_order, camera_params_t *cameras, @@ -914,7 +914,7 @@ void BaseApp::WriteCamerasXML(const char *filename) } fprintf(f, "\n\n"); - char *url_base = + const char *url_base = "http://grail.cs.cornell.edu/projects/phototour/trevi/images"; fprintf(f, " %s \n", url_base); @@ -1134,7 +1134,8 @@ static char ply_header[] = "end_header\n"; /* Write point files to a ply file */ -void BaseApp::DumpPointsToPly(char *output_directory, char *filename, +void BaseApp::DumpPointsToPly(const char *output_directory, + const char *filename, int num_points, int num_cameras, v3_t *points, v3_t *colors, camera_params_t *cameras @@ -1441,12 +1442,12 @@ void BaseApp::InitializeImagesFromFile(FILE *f) UnscaleCameras(num_images); } -void BaseApp::ReadLines3D(char *filename) +void BaseApp::ReadLines3D(const char *filename) { - + /* Not implemented... */ } -void BaseApp::WriteLines3D(char *filename) +void BaseApp::WriteLines3D(const char *filename) { - + /* Not implemented... */ } diff --git a/src/BundleTwo.cpp b/src/BundleTwo.cpp index 15f1f83..2391b2a 100644 --- a/src/BundleTwo.cpp +++ b/src/BundleTwo.cpp @@ -854,9 +854,10 @@ double BundlerApp::RunSFMNecker(int i1, int i2, int added_order[2] = { i1, i2 }; double error1; - error1 = RunSFM(num_points, 2, 0, false, - cameras_new, points_new, added_order, colors, pt_views, - threshold, NULL, NULL, NULL, NULL, true); + error1 = RunSFM_SBA(num_points, 2, 0, false, + cameras_new, points_new, added_order, + colors, pt_views, + threshold, NULL, NULL, NULL, NULL, true); return error1; } @@ -1260,13 +1261,14 @@ bool BundlerApp::BundleTwoFrame(int i1, int i2, TwoFrameModel *model, #if 1 #ifdef USE_COLORS - double error0 = RunSFM(pt_count, 2, 0, false, - cameras, points, added_order, colors, pt_views, - TERM_THRESH, NULL, NULL, NULL, NULL, true); + double error0 = RunSFM_SBA(pt_count, 2, 0, false, + cameras, points, added_order, + colors, pt_views, + TERM_THRESH, NULL, NULL, NULL, NULL, true); #else - double error0 = RunSFM(pt_count, 2, 0, false, - cameras, points, added_order, NULL, pt_views, - TERM_THRESH, NULL, NULL, NULL, NULL, true); + double error0 = RunSFM_SBA(pt_count, 2, 0, false, + cameras, points, added_order, NULL, pt_views, + TERM_THRESH, NULL, NULL, NULL, NULL, true); #endif #endif @@ -1572,9 +1574,9 @@ bool BundlerApp::BundleTwoFrame(int i1, int i2, TwoFrameModel *model, #endif #if 1 - error0 = RunSFM(pt_count, 2, 0, false, - cameras, points, added_order, NULL, pt_views, - TERM_THRESH, S, U, V, W, false); + error0 = RunSFM_SBA(pt_count, 2, 0, false, + cameras, points, added_order, NULL, pt_views, + TERM_THRESH, S, U, V, W, false); #endif memset(Uf, 0, sizeof(double) * 4 * cnp * cnp); @@ -1847,13 +1849,13 @@ bool BundlerApp::BundleTwoFrame(int i1, int i2, TwoFrameModel *model, #if 1 #ifdef USE_COLORS - error0 = RunSFM(pt_count, 2, 0, false, - cameras, points, added_order, colors, pt_views, - TERM_THRESH, S, U, V, W, false); + error0 = RunSFM_SBA(pt_count, 2, 0, false, + cameras, points, added_order, colors, pt_views, + TERM_THRESH, S, U, V, W, false); #else - error0 = RunSFM(pt_count, 2, 0, false, - cameras, points, added_order, NULL, pt_views, - TERM_THRESH, S, U, V, W, false); + error0 = RunSFM_SBA(pt_count, 2, 0, false, + cameras, points, added_order, NULL, pt_views, + TERM_THRESH, S, U, V, W, false); #endif #endif diff --git a/src/BundlerApp.cpp b/src/BundlerApp.cpp index 8add1a5..5cf0dd8 100644 --- a/src/BundlerApp.cpp +++ b/src/BundlerApp.cpp @@ -223,6 +223,11 @@ void BundlerApp::ProcessOptions(int argc, char **argv) {"run_bundle", 0, 0, 'r'}, {"rerun_bundle", 0, 0, 'j'}, {"slow_bundle", 0, 0, 'D'}, + +#ifdef __USE_CERES__ + {"use_ceres", 0, 0, 371}, +#endif /* __USE_CERES__ */ + {"skip_full_bundle", 0, 0, 321},// {"skip_add_points", 0, 0, 322},// @@ -265,7 +270,6 @@ void BundlerApp::ProcessOptions(int argc, char **argv) {"trust_focal_estimate", 0, 0, '_'}, {"estimate_ignored", 0, 0, 344},// {"reposition_scene", 0, 0, 'R'},// - {"segment_sky", 1, 0, 350},// {"keypoint_border_width", 1, 0, 355},// {"keypoint_border_bottom", 1, 0, 365},// @@ -273,6 +277,7 @@ void BundlerApp::ProcessOptions(int argc, char **argv) {"max_track_views", 1, 0, 320},// {"min_max_matches", 1, 0, 362},// {"min_feature_matches", 1, 0, 369},// + {"num_matches_add_camera", 1, 0, 370}, {"ray_angle_threshold", 1, 0, 'N'}, {"estimate_distortion", 0, 0, 347}, @@ -298,7 +303,6 @@ void BundlerApp::ProcessOptions(int argc, char **argv) {"assemble", 0, 0, 308},// {"bundle", 1, 0, 'b'}, - {"server_mode", 1, 0, 346},// {"match_dir", 1, 0, 'm'}, {"match_index_dir", 1, 0, 366}, {"match_table", 1, 0, 364}, @@ -308,7 +312,6 @@ void BundlerApp::ProcessOptions(int argc, char **argv) {"analyze_matches", 0, 0, 'M'},// {"match_global", 0, 0, '<'},// {"ann_max_pts_visit", 1, 0, 302},// - {"global_knn", 1, 0, 303},// {"global_nn_sigma", 1, 0, 304},// {"output_dir", 1, 0, 'u'}, @@ -386,21 +389,27 @@ void BundlerApp::ProcessOptions(int argc, char **argv) case 'o': m_bundle_output_file = strdup(optarg); break; + case 'a': m_bundle_output_base = strdup(optarg); break; + case 'i': m_init_focal_length = atof(optarg); break; + case 'v': m_fixed_focal_length = false; break; + case 'x': m_fixed_focal_length = true; break; + case 'r': m_run_bundle = true; break; + case 'j': m_rerun_bundle = true; break; @@ -409,6 +418,12 @@ void BundlerApp::ProcessOptions(int argc, char **argv) m_fast_bundle = false; break; +#ifdef __USE_CERES__ + case 371: + m_use_ceres = true; + break; +#endif /* __USE_CERES__ */ + case 321: m_skip_full_bundle = true; break; @@ -429,18 +444,11 @@ void BundlerApp::ProcessOptions(int argc, char **argv) m_prune_bad_points = true; break; - - case 368: m_output_relposes = true; m_output_relposes_file = strdup(optarg); break; - case 350: - m_segment_sky = true; - m_sky_model_file = strdup(optarg); - break; - case 305: m_scale_focal = atof(optarg); break; @@ -580,6 +588,10 @@ void BundlerApp::ProcessOptions(int argc, char **argv) m_min_num_feat_matches = atoi(optarg); break; + case 370: + m_num_matches_add_camera = atoi(optarg); + break; + case 'N': m_ray_angle_threshold = atof(optarg); break; @@ -588,11 +600,6 @@ void BundlerApp::ProcessOptions(int argc, char **argv) m_assemble = true; break; - case 346: - m_server_mode = true; - m_server_port = atoi(optarg); - break; - case 'b': m_bundle_provided = true; m_bundle_file = strdup(optarg); @@ -634,10 +641,7 @@ void BundlerApp::ProcessOptions(int argc, char **argv) m_ann_max_pts_visit = atoi(optarg); printf(" ann_max_pts_visit: %d\n", m_ann_max_pts_visit); break; - case 303: - m_global_knn = atoi(optarg); - printf(" global_knn: %d\n", m_global_knn); - break; + case 304: m_global_nn_sigma = atof(optarg); printf(" global_nn_sigma: %0.3f\n", m_global_nn_sigma); diff --git a/src/BundlerApp.h b/src/BundlerApp.h index b3afef6..23d589a 100644 --- a/src/BundlerApp.h +++ b/src/BundlerApp.h @@ -79,6 +79,7 @@ class BundlerApp : public BaseApp m_max_track_views = 100000; m_min_num_feat_matches = 16; m_min_max_matches = 16; + m_num_matches_add_camera = -1; /* No maximum by default */ m_ray_angle_threshold = 2.0; m_keypoint_border_width = 0; @@ -88,19 +89,18 @@ class BundlerApp : public BaseApp m_bundle_output_file = m_bundle_output_base = NULL; m_bundle_file = NULL; m_intrinsics_file = NULL; - m_match_directory = (const char *) "."; + m_match_directory = "."; m_match_index_dir = NULL; m_match_table = NULL; - m_key_directory = (const char *) "."; - m_image_directory = (const char *) "."; - m_output_directory = (const char *) "."; + m_key_directory = "."; + m_image_directory = "."; + m_output_directory = "."; m_use_intrinsics = false; m_matches_computed = false; m_match_global = false; m_ann_max_pts_visit = 400; m_global_nn_sigma = 16.0; - m_global_knn = 200; // m_transforms = NULL; // m_set_transforms = NULL; @@ -110,11 +110,12 @@ class BundlerApp : public BaseApp m_features_coalesced = false; m_assemble = false; - m_server_mode = false; - m_server_port = -1; m_run_bundle = false; m_rerun_bundle = false; m_fast_bundle = true; +#ifdef __USE_CERES__ + m_use_ceres = false; +#endif /* __USE_CERES__ */ m_skip_full_bundle = false; m_skip_add_points = false; m_use_angular_score = false; @@ -130,10 +131,6 @@ class BundlerApp : public BaseApp m_output_relposes = false; m_output_relposes_file = NULL; - - - m_sky_model_file = NULL; - m_compute_covariance = false; m_covariance_fix1 = -1; m_covariance_fix2 = -1; @@ -376,12 +373,40 @@ class BundlerApp : public BaseApp double *V = NULL, double *W = NULL); void ReRunSFM(double *S = NULL, double *U = NULL, double *V = NULL, double *W = NULL); + + /* Run bundle adjustment on a given reconstruction */ double RunSFM(int num_pts, int num_cameras, int start_camera, - bool fix_points, camera_params_t *init_camera_params, - v3_t *init_pts, int *added_order, v3_t *colors, - std::vector &pt_views, double eps2 = 1.0e-12, + bool fix_points, camera_params_t *init_camera_params, + v3_t *init_pts, int *added_order, v3_t *colors, + std::vector &pt_views, + int max_iter = 0, int max_iter2 = 0, + int verbosity = 0, double eps2 = 1.0e-12, double *S = NULL, double *U = NULL, double *V = NULL, - double *W = NULL, bool remove_outliers = true); + double *W = NULL, bool remove_outliers = true, + bool final_bundle = false, + bool write_intermediate = false); + + double RunSFM_SBA(int num_pts, int num_cameras, int start_camera, + bool fix_points, camera_params_t *init_camera_params, + v3_t *init_pts, int *added_order, v3_t *colors, + std::vector &pt_views, + double eps2 = 1.0e-12, + double *S = NULL, double *U = NULL, double *V = NULL, + double *W = NULL, bool remove_outliers = true); + +#ifdef __USE_CERES__ + double RunSFM_Ceres(int num_pts, int num_cameras, int start_camera, + bool fix_points, camera_params_t *init_camera_params, + v3_t *init_pts, int *added_order, v3_t *colors, + std::vector &pt_views, + int max_iter = 0, int max_iter2 = 0, + int verbosity = 0, double eps2 = 1.0e-12, + double *S = NULL, double *U = NULL, double *V = NULL, + double *W = NULL, bool remove_outliers = true, + bool final_bundle = false, + bool write_intermediate = false); +#endif /* __USE_CERES__ */ + double RunSFMNecker(int i1, int i2, camera_params_t *cameras, int num_points, v3_t *points, v3_t *colors, @@ -389,6 +414,8 @@ class BundlerApp : public BaseApp camera_params_t *cameras_new, v3_t *points_new, double threshold); + + #endif /* __DEMO__ */ bool BundleTwoFrame(int i1, int i2, TwoFrameModel *model, @@ -430,6 +457,7 @@ class BundlerApp : public BaseApp /* Find a ground plane in the scene */ void FindGroundPlane(); + /* Find a sky plane in the scene */ void FindSkyPlane(); @@ -475,8 +503,6 @@ class BundlerApp : public BaseApp bool m_match_global; /* Compute matches using global matcher */ double m_global_nn_sigma; /* Threshold from expected variance * where features match */ - int m_global_knn; /* Number of neighbors to find in - * global matching */ bool m_optimize_for_fisheye; /* Optimize for fisheye-distorted * points */ @@ -513,10 +539,12 @@ class BundlerApp : public BaseApp int m_min_max_matches; /* Minimum number of matches * needed to register an image */ + int m_num_matches_add_camera; /* Number of matches needed to + * consider registering an image */ - char *m_bundle_output_file; /* Output file names for BA */ - char *m_bundle_output_base; - char *m_output_directory; + const char *m_bundle_output_file; /* Output file names for BA */ + const char *m_bundle_output_base; + const char *m_output_directory; bool m_compute_covariance; /* Compute the covariance of a * reconstruction */ @@ -559,8 +587,6 @@ class BundlerApp : public BaseApp bool m_features_coalesced; /* Have features been coalesced */ - int m_server_port; /* Port to use when in server mode */ - bool m_server_mode; /* Run bundler as a server? */ bool m_assemble; /* Assemble the scene from the bottom up */ bool m_run_bundle; /* Should we run bundle adjustment * automatically? */ @@ -568,6 +594,12 @@ class BundlerApp : public BaseApp * automatically? */ bool m_fast_bundle; /* Should we run the fast version of * bundle adjustment? */ + +#ifdef __USE_CERES__ + bool m_use_ceres; /* Use Ceres solver for + * bundle adjustment? */ +#endif /* __USE_CERES__ */ + bool m_skip_full_bundle; /* Skip full optimization stages */ bool m_skip_add_points; /* Don't add new points to the * optimization */ @@ -594,11 +626,6 @@ class BundlerApp : public BaseApp bool m_output_relposes; char *m_output_relposes_file; - bool m_segment_sky; /* Activative sky segmentation */ - char *m_sky_model_file; - - - bool m_enrich_points; /* Enrich the point set? */ bool m_zero_distortion_params; /* Set all distortion parameters to * zero */ diff --git a/src/BundlerGeometry.cpp b/src/BundlerGeometry.cpp index 6d9cd71..1b2a121 100644 --- a/src/BundlerGeometry.cpp +++ b/src/BundlerGeometry.cpp @@ -103,7 +103,7 @@ void BundlerApp::ComputeGeometricConstraints(bool overwrite, int num_images = GetNumImages(); /* Read information from files if they exist */ - char *filename = "constraints.txt"; + const char *filename = "constraints.txt"; if (!overwrite && FileExists(filename)) { ReadGeometricConstraints(filename); return; @@ -383,9 +383,8 @@ bool BundlerApp::ComputeEpipolarGeometry(int idx1, int idx2, memcpy(m_transforms[offset].m_fmatrix, F, 9 * sizeof(double)); // m_transforms[offset]->m_scale = sqrt(M[0] * M[0] + M[1] * M[1]); - printf("Inliers[%d,%d] = %d out of %d\n", idx1, idx2, num_inliers, + printf("Inliers[%d,%d] = %d out of %lu\n", idx1, idx2, num_inliers, list.size()); - // (int) m_match_lists[offset].size()); return true; } else { diff --git a/src/Camera.cpp b/src/Camera.cpp index 40cb9fc..796f773 100644 --- a/src/Camera.cpp +++ b/src/Camera.cpp @@ -958,7 +958,7 @@ void CameraInfo::WriteFile(FILE *f) void CameraInfo::WriteXML(FILE *f) { - static char *spacer = " "; + static const char *spacer = " "; fprintf(f, "%s %0.8e \n", spacer, m_focal); fprintf(f, "%s %0.8e %0.8e %0.8e " diff --git a/src/ImageData.cpp b/src/ImageData.cpp index a51eb75..1655076 100644 --- a/src/ImageData.cpp +++ b/src/ImageData.cpp @@ -84,7 +84,7 @@ int CompareImageDates(ImageDate *date1, ImageDate *date2) return 0; } -static char *month_strings[] = +static const char *month_strings[] = { "January", "February", "March", @@ -183,7 +183,8 @@ void ImageNote::Read(FILE *f, double width, double height) } /* Initialize the image data given a string description */ -void ImageData::InitFromString(char *buf, char *path, bool fisheye_by_default) +void ImageData::InitFromString(char *buf, const char *path, + bool fisheye_by_default) { /* Eat the newline */ if (buf[strlen(buf)-1] == '\n') @@ -712,7 +713,7 @@ int ImageData::GetNumKeys() #endif } -void ImageData::LoadOrExtractKeys(char *sift_binary, bool undistort) +void ImageData::LoadOrExtractKeys(const char *sift_binary, bool undistort) { if (m_keys_loaded) return; /* Already loaded the keys */ @@ -735,7 +736,7 @@ void ImageData::LoadOrExtractKeys(char *sift_binary, bool undistort) } } -void ImageData::ExtractFeatures(char *sift_binary, bool undistort) +void ImageData::ExtractFeatures(const char *sift_binary, bool undistort) { #ifndef __DEMO__ /* Find the extension */ diff --git a/src/ImageData.h b/src/ImageData.h index 79180a0..9d2e4b4 100644 --- a/src/ImageData.h +++ b/src/ImageData.h @@ -154,13 +154,12 @@ class ImageData { m_day_photo = true; m_added = false; m_is_rep = false; - // m_tps_lu = NULL; - // m_tps_ipiv = NULL; m_geosupport = 0.0; } /* Initialize the image data given a string description */ - void InitFromString(char *buf, char *path, bool fisheye_by_default); + void InitFromString(char *buf, const char *path, + bool fisheye_by_default); /* Create a pinhole view for the keys */ void UndistortKeys(); @@ -244,13 +243,13 @@ class ImageData { void UnloadThumb256(); int GetNumKeys(); - void LoadOrExtractKeys(char *sift_binary, bool undistort = true); + void LoadOrExtractKeys(const char *sift_binary, bool undistort = true); void LoadKeys(bool descriptor = true, bool undistort = true); void LoadDescriptors(bool undistort); void LoadKeysWithScaleRot(bool descriptor = true, bool undistort = true); void UnloadKeys(); void UnloadKeysWithScaleRot(); - void ExtractFeatures(char *sift_binary, bool undistort); + void ExtractFeatures(const char *sift_binary, bool undistort); /* Find line segments in the image */ void DetectLineSegments(double sigma, diff --git a/src/Makefile b/src/Makefile index 086974b..db4ddac 100644 --- a/src/Makefile +++ b/src/Makefile @@ -3,7 +3,7 @@ CC=gcc CXX=g++ OPTFLAGS=-O3 -Wall -OTHERFLAGS=-std=gnu++0x +OTHERFLAGS=-std=gnu++0x -D__USE_CERES__ OS=$(shell uname -o) @@ -23,7 +23,8 @@ RADIALUNDISTORT=RadialUndistort endif INCLUDE_PATH=-I../lib/imagelib -I../lib/sfm-driver -I../lib/matrix \ - -I../lib/5point -I../lib/sba-1.5 -I../lib/ann_1.1_char/include + -I../lib/5point -I../lib/sba-1.5 -I../lib/ann_1.1_char/include \ + -I../include -I/usr/include/eigen3 LIB_PATH=-L../lib -L../lib/ann_1.1_char/lib @@ -36,11 +37,12 @@ BUNDLER_OBJS=BaseApp.o BundlerApp.o keys.o Register.o Epipolar.o \ ImageData.o SifterUtil.o BaseGeometry.o BundlerGeometry.o \ BoundingBox.o BundleAdd.o ComputeTracks.o BruteForceSearch.o \ BundleIO.o ProcessBundle.o BundleTwo.o Decompose.o \ - RelativePose.o Distortion.o TwoFrameModel.o LoadJPEG.o + RelativePose.o Distortion.o TwoFrameModel.o LoadJPEG.o \ + BundleCeres.o -BUNDLER_LIBS=-limage -lsfmdrv -lsba.v1.5 -lmatrix -lz -llapack -lblas \ +BUNDLER_LIBS=-limage -lsfmdrv -lsba.v1.5 -lmatrix -lz -lblas -llapack \ -lcblas -lminpack -lm -l5point -ljpeg -lANN_char -lgfortran - +CERES_LIBS=-lceres -lgomp -lglog -lcholmod all: $(BUNDLER) $(KEYMATCHFULL) $(BUNDLE2PLY) $(BUNDLE2PMVS) $(BUNDLE2VIS) $(RADIALUNDISTORT) @@ -49,7 +51,7 @@ all: $(BUNDLER) $(KEYMATCHFULL) $(BUNDLE2PLY) $(BUNDLE2PMVS) $(BUNDLE2VIS) $(RAD $(BUNDLER): $(BUNDLER_OBJS) $(CXX) -o $@ $(CPPFLAGS) $(LIB_PATH) \ - $(BUNDLER_DEFINES) $(BUNDLER_OBJS) $(BUNDLER_LIBS) + $(BUNDLER_DEFINES) $(BUNDLER_OBJS) $(BUNDLER_LIBS) $(CERES_LIBS) cp $@ ../bin $(KEYMATCHFULL): KeyMatchFull.o keys2a.o