Skip to content

Commit

Permalink
Merge branch 'master' of github.com:snavely/bundler_sfm
Browse files Browse the repository at this point in the history
  • Loading branch information
snavely committed Aug 30, 2014
2 parents 457b7b8 + 401d546 commit 5d05ddb
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 53 deletions.
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,34 @@
*.o
*.a
*.so
*.dll

# emacs temp files
*~

# Compiled binaries and temporary library files
bin/Bundle2PMVS
bin/Bundle2Ply
bin/Bundle2Vis
bin/KeyMatchFull
bin/RadialUndistort
bin/bundler
lib/ann_1.1_char/lib
lib/f2c/arith.h
lib/f2c/signal1.h
lib/f2c/sysdep1.h
src/Bundle2PMVS
src/Bundle2Ply
src/Bundle2Vis
src/KeyMatchFull
src/RadialUndistort
src/bundler

# Binaries we depend on
bin/sift

# misc
list_keys.txt
list_tmp.txt
options.txt
sift.txt
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ based on the Photo Tourism work of Noah Snavely, Steven M. Seitz,

For more information, see the Bundler homepage at
http://www.cs.cornell.edu/~snavely/bundler/
or see the FAQ at
http://www.cs.cornell.edu/~snavely/bundler/faq.html

What is Bundler?
----------------
Expand Down
3 changes: 3 additions & 0 deletions bin/extract_focal.pl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"Canon Canon EOS 400D DIGITAL" => 22.2,
"Canon Canon EOS 40D" => 22.2,
"Canon Canon EOS 5D" => 35.8,
"Canon Canon EOS 5D Mark II" => 36.0,
"Canon Canon EOS 5D Mark III" => 36.0,
"Canon Canon EOS DIGITAL REBEL" => 22.66,
"Canon Canon EOS DIGITAL REBEL XT" => 22.2,
"Canon Canon EOS DIGITAL REBEL XTi" => 22.2,
Expand Down Expand Up @@ -112,6 +114,7 @@
"Canon Canon PowerShot SD700 IS" => 5.76, # 1/2.5"
"Canon Canon PowerShot SD750" => 5.75, # 1/2.5"
"Canon Canon PowerShot SD800 IS" => 5.76, # 1/2.5"
"Canon Canon PowerShot SX500 IS" => 6.17, # 1/2.3"
"Canon EOS 300D DIGITAL" => 22.66,
"Canon EOS DIGITAL REBEL" => 22.66,
"Canon PowerShot A510" => 5.76, # 1/2.5" ???
Expand Down
13 changes: 11 additions & 2 deletions src/Bundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,10 +657,13 @@ double BundlerApp::RunSFM_SBA(int num_pts, int num_cameras, int start_camera,
printf("[RunSFM] run_sfm took %0.3fs\n",
(double) (end - start) / (double) CLOCKS_PER_SEC);

/* Check for outliers */
/* Compute statistics and check for outliers */

start = clock();

double global_reprojection_error = 0;
int global_num_observations = 0;

std::vector<int> outliers;
std::vector<double> reproj_errors;

Expand Down Expand Up @@ -784,7 +787,8 @@ double BundlerApp::RunSFM_SBA(int num_pts, int num_cameras, int start_camera,
iround(0.5 * num_pts_proj), dists),
thresh);

// printf("Outlier threshold is %0.3f\n", thresh);
global_reprojection_error += sum;
global_num_observations += num_pts_proj;

pt_count = 0;
for (int j = 0; j < num_keys; j++) {
Expand Down Expand Up @@ -846,6 +850,11 @@ double BundlerApp::RunSFM_SBA(int num_pts, int num_cameras, int start_camera,
delete [] dists;
}

printf("[RunSFM] Global mean reprojection error: %0.3e "
"(%d observations)\n",
global_reprojection_error / global_num_observations,
global_num_observations);

/* Remove outlying points */
if (remove_outliers) {
for (int i = 0; i < (int) outliers.size(); i++) {
Expand Down
11 changes: 11 additions & 0 deletions src/BundleCeres.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ double BundlerApp::RunSFM_Ceres(int num_pts, int num_cameras,

start = clock();

double global_reprojection_error = 0;
int global_num_observations = 0;

std::vector<int> outliers;
std::vector<int> outlier_views;
std::vector<double> reproj_errors;
Expand Down Expand Up @@ -649,6 +652,9 @@ double BundlerApp::RunSFM_Ceres(int num_pts, int num_cameras,
iround(0.5 * num_pts_proj), dists),
thresh);

global_reprojection_error += sum;
global_num_observations += num_pts_proj;

pt_count = 0;
for (int j = 0; j < num_keys; j++) {
int pt_idx = GetKey(added_order[i],j).m_extra;
Expand Down Expand Up @@ -715,6 +721,11 @@ double BundlerApp::RunSFM_Ceres(int num_pts, int num_cameras,
delete [] dists;
}

printf("[RunSFM] Global mean reprojection error: %0.3e "
"(%d observations)\n",
global_reprojection_error / global_num_observations,
global_num_observations);

/* Remove outlying points */
if ((!final_bundle || round > 0) && remove_outliers) {
int num_dead = 0;
Expand Down
12 changes: 2 additions & 10 deletions src/BundleIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,8 +1138,7 @@ 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
/*bool reflect*/)
camera_params_t *cameras)
{
int num_good_pts = 0;

Expand Down Expand Up @@ -1174,8 +1173,6 @@ void BaseApp::DumpPointsToPly(const char *output_directory,
/* Output the vertex */
fprintf(f, "%0.6e %0.6e %0.6e %d %d %d\n",
Vx(points[i]), Vy(points[i]), Vz(points[i]),
// Vx(points[idx]), Vy(points[idx]), Vz(points[idx]),
// (reflect ? -1 : 1) * Vz(points[i]),
iround(Vx(colors[i])),
iround(Vy(colors[i])),
iround(Vz(colors[i])));
Expand All @@ -1191,25 +1188,20 @@ void BaseApp::DumpPointsToPly(const char *output_directory,

if ((i % 2) == 0)
fprintf(f, "%0.6e %0.6e %0.6e 0 255 0\n", c[0], c[1], c[2]);
// (reflect ? -1 : 1) * c[2]);
else
fprintf(f, "%0.6e %0.6e %0.6e 255 0 0\n", c[0], c[1], c[2]);
// (reflect ? -1 : 1) * c[2]);

double p_cam[3] = { 0.0, 0.0, -0.05 };
double p[3];

// if (!reflect)
// p_cam[2] *= -1.0;

matrix_product(3, 3, 3, 1, Rinv, p_cam, p);

p[0] += c[0];
p[1] += c[1];
p[2] += c[2];

fprintf(f, "%0.6e %0.6e %0.6e 255 255 0\n",
p[0], p[1], p[2]); // (reflect ? -1 : 1) * p[2]);
p[0], p[1], p[2]);
}

fclose(f);
Expand Down
91 changes: 53 additions & 38 deletions src/KeyMatchFull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,56 @@
/* KeyMatchFull.cpp */
/* Read in keys, match, write results to a file */

#include <assert.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "keys2a.h"

int ReadFileList(char* list_in, std::vector<std::string>& key_files) {
FILE* fp;

if ((fp = fopen(list_in, "r")) == NULL) {
printf("Error opening file %s for reading.\n", list_in);
return 1;
}

char buf[512], *start;
while (fgets(buf, 512, fp)) {
// Remove trailing new-line
if (buf[strlen(buf) - 1] == '\n') buf[strlen(buf) - 1] = '\0';

// Find first non-space character
start = buf;
while(isspace(*start)) start++;

// Skip empty lines
if (strlen(start) == 0) continue;

// Append file-name to key_files
key_files.push_back(std::string(buf));
}

// Check we found input files
if (key_files.size() == 0) {
printf("No input files found in %s.\n", list_in);
return 1;
}

return 0;
}

int main(int argc, char **argv) {
char *list_in;
char *file_out;
double ratio;

if (argc != 3 && argc != 4) {
printf("Usage: %s <list.txt> <outfile> [window_radius]\n", argv[0]);
return -1;
printf("Usage: %s <list.txt> <outfile> [window_radius]\n", argv[0]);
return EXIT_FAILURE;
}

list_in = argv[1];
ratio = 0.6;
file_out = argv[2];
Expand All @@ -45,47 +77,31 @@ int main(int argc, char **argv) {

clock_t start = clock();

unsigned char **keys;
int *num_keys;

/* Read the list of files */
std::vector<std::string> key_files;

FILE *f = fopen(list_in, "r");
if (f == NULL) {
printf("Error opening file %s for reading\n", list_in);
return 1;
}
if (ReadFileList(list_in, key_files) != 0) return EXIT_FAILURE;

char buf[512];
while (fgets(buf, 512, f)) {
/* Remove trailing newline */
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = 0;

key_files.push_back(std::string(buf));
FILE *f;
if ((f = fopen(file_out, "w")) == NULL) {
printf("Could not open %s for writing.\n", file_out);
return EXIT_FAILURE;
}

fclose(f);

f = fopen(file_out, "w");
assert(f != NULL);

int num_images = (int) key_files.size();

keys = new unsigned char *[num_images];
num_keys = new int[num_images];
std::vector<unsigned char*> keys(num_images);
std::vector<int> num_keys(num_images);

/* Read all keys */
for (int i = 0; i < num_images; i++) {
keys[i] = NULL;
num_keys[i] = ReadKeyFile(key_files[i].c_str(), keys+i);
num_keys[i] = ReadKeyFile(key_files[i].c_str(), &keys[i]);
}

clock_t end = clock();
clock_t end = clock();
printf("[KeyMatchFull] Reading keys took %0.3fs\n",
(end - start) / ((double) CLOCKS_PER_SEC));

for (int i = 0; i < num_images; i++) {
if (num_keys[i] == 0)
continue;
Expand All @@ -109,7 +125,7 @@ int main(int argc, char **argv) {
/* Compute likely matches between two sets of keypoints */
std::vector<KeypointMatch> matches =
MatchKeys(num_keys[j], keys[j], tree, ratio);

int num_matches = (int) matches.size();

if (num_matches >= 16) {
Expand All @@ -126,22 +142,21 @@ int main(int argc, char **argv) {
}
}

end = clock();
end = clock();
printf("[KeyMatchFull] Matching took %0.3fs\n",
(end - start) / ((double) CLOCKS_PER_SEC));
fflush(stdout);

delete tree;
}

/* Free keypoints */
for (int i = 0; i < num_images; i++) {
if (keys[i] != NULL)
delete [] keys[i];
}
delete [] keys;
delete [] num_keys;


fclose(f);
return 0;
return EXIT_SUCCESS;
}

14 changes: 11 additions & 3 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
CC=gcc
CXX=g++
OPTFLAGS=-O3 -Wall -Wno-unused-result
# OPTFLAGS=-g2
OTHERFLAGS=-std=gnu++0x

OS=$(shell uname -o)
Expand Down Expand Up @@ -39,17 +40,24 @@ BUNDLER_OBJS=BaseApp.o BundlerApp.o keys.o Register.o Epipolar.o \
BundleIO.o ProcessBundle.o BundleTwo.o Decompose.o \
RelativePose.o Distortion.o TwoFrameModel.o LoadJPEG.o

BUNDLER_LIBS=-limage -lsfmdrv -lsba.v1.5 -lmatrix -lz -lblas -llapack \
BUNDLER_BASE_LIBS=-limage -lsfmdrv -lsba.v1.5 -lmatrix -lz -llapack -lblas \
-lcblas -lminpack -lm -l5point -ljpeg -lANN_char -lgfortran
CERES_LIBS= -lceres -lcholmod -lcolamd -lamd -lcamd -lcxsparse \
CERES_LIBS=-lceres -lcholmod -lccolamd -lcolamd -lamd -lcamd -lcxsparse \
-lsuitesparseconfig -lgomp -lglog -lpthread

# if we are using Ceres, add to options
ifeq ($(USE_CERES),true)
# Edit these two variables as needed
CERES_INCLUDE_PATH=
CERES_LIB_PATH=
BUNDLER_DEFINES+=-D__USE_CERES__
BUNDLER_LIBS+=$(CERES_LIBS)
BUNDLER_LIBS=$(CERES_LIBS) $(BUNDLER_BASE_LIBS)
BUNDLER_OBJS+=BundleCeres.o
INCLUDE_PATH+=$(CERES_INCLUDE_PATH)
LIB_PATH+=$(CERES_LIB_PATH)
INCLUDE_PATH+=-I/usr/include/eigen3
else
BUNDLER_LIBS=$(BUNDLER_BASE_LIBS)
endif

CPPFLAGS=$(OPTFLAGS) $(OTHERFLAGS) $(INCLUDE_PATH)
Expand Down
3 changes: 3 additions & 0 deletions utils/bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"Canon Canon EOS 400D DIGITAL" : 22.2,
"Canon Canon EOS 40D" : 22.2,
"Canon Canon EOS 5D" : 35.8,
"Canon Canon EOS 5D Mark II" : 36.0,
"Canon Canon EOS 5D Mark III" : 36.0,
"Canon Canon EOS DIGITAL REBEL" : 22.66,
"Canon Canon EOS DIGITAL REBEL XT" : 22.2,
"Canon Canon EOS DIGITAL REBEL XTi" : 22.2,
Expand Down Expand Up @@ -141,6 +143,7 @@
"Canon Canon PowerShot SD700 IS" : 5.76, # 1/2.5"
"Canon Canon PowerShot SD750" : 5.75, # 1/2.5"
"Canon Canon PowerShot SD800 IS" : 5.76, # 1/2.5"
"Canon Canon PowerShot SX500 IS" : 6.17, # 1/2.3"
"Canon EOS 300D DIGITAL" : 22.66,
"Canon EOS DIGITAL REBEL" : 22.66,
"Canon PowerShot A510" : 5.76, # 1/2.5" ???
Expand Down

0 comments on commit 5d05ddb

Please sign in to comment.