diff --git a/CameraParameterEstimation/apps/README.md b/CameraParameterEstimation/apps/README.md index 06c7866..c2bc5e0 100644 --- a/CameraParameterEstimation/apps/README.md +++ b/CameraParameterEstimation/apps/README.md @@ -1 +1,6 @@ -TODO: Descibe dependiencies and what is necessary to build these. \ No newline at end of file +### Building + +To bulid camera parameter estimation application you need to install `glew` and `glfw` libraries. +On Ubuntu they are available through `apt-get` and on macOS they can be installed using `homebrew`. + +Once the libraries are installed navigate to the `src` folder for eack app and run `make` command. \ No newline at end of file diff --git a/CameraParameterEstimation/apps/basics/argparse.h b/CameraParameterEstimation/apps/basics/argparse.h index 6284e32..3dd6b51 100644 --- a/CameraParameterEstimation/apps/basics/argparse.h +++ b/CameraParameterEstimation/apps/basics/argparse.h @@ -14,7 +14,7 @@ #include #include #include - +#include namespace bsc { template @@ -351,7 +351,7 @@ parse ( int argc, char** argv ) int n_args = args_to_parse.size(); // parse value to correct argument - auto parse_argument = [ &args_to_parse, &idx, n_args ] + auto parse_argument = [ &args_to_parse, &idx ] ( std::string to_parse, argument* str_arg, argument* cstr_arg, @@ -603,4 +603,4 @@ print_help() const exit(-1); } -#endif //BSC_IMPLEMENTATION \ No newline at end of file +#endif //BSC_IMPLEMENTATION diff --git a/CameraParameterEstimation/apps/basics/basics.h b/CameraParameterEstimation/apps/basics/basics.h index 245cc86..dd4c345 100644 --- a/CameraParameterEstimation/apps/basics/basics.h +++ b/CameraParameterEstimation/apps/basics/basics.h @@ -65,42 +65,25 @@ //////////////////////////////////////////////////////////////////////////////// #ifdef BSC_USE_WINDOW // Graphics through window - - // glew for opengl extension - // TODO(maciej): To be removed and replaced with some inline loader - #ifndef __EMSCRIPTEN__ - #if defined(_WIN32) || defined(_WIN64) - #include "GL/glew.h" - #endif - #else - #define GLFW_INCLUDE_ES2 - #endif - - // glfw configuration - // TODO(maciej): Unlikely in near feature, but we might strip this. - #define GLFW_INCLUDE_GLCOREARB /* don't drag in legacy GL headers. */ + #define GLFW_INCLUDE_NONE #define GLFW_NO_GLU #include "GLFW/glfw3.h" +#endif -#else // offscreen rendering - - #ifdef __APPLE__ - #include - #include - #include - #include - #endif - - #ifdef __unix__ - #include - #include - #include - #include - #endif - - //TODO: Windows +#ifdef __APPLE__ + #include + #include + #include + #include +#endif +#if defined(__linux__) + #include + #include + #include #endif + +//TODO: Windows // tiny_dir for easy directory stepping and file name/extension tokenizing diff --git a/CameraParameterEstimation/apps/basics/common.h b/CameraParameterEstimation/apps/basics/common.h index fe1d73d..cf4b074 100644 --- a/CameraParameterEstimation/apps/basics/common.h +++ b/CameraParameterEstimation/apps/basics/common.h @@ -164,7 +164,7 @@ namespace bsc string_hash ( const char * str ) { int hash = 0; - for ( int i = 0; i < strlen( str ) ; ++i ) + for ( int i = 0; i < (int)strlen( str ) ; ++i ) hash = hash * 65599 + str[i]; return hash; } diff --git a/CameraParameterEstimation/apps/basics/gfx/camera.h b/CameraParameterEstimation/apps/basics/gfx/camera.h index a442904..f16a161 100644 --- a/CameraParameterEstimation/apps/basics/gfx/camera.h +++ b/CameraParameterEstimation/apps/basics/gfx/camera.h @@ -131,13 +131,11 @@ pan( bsc::camera * cam, const bsc::mat4 * view, const bsc::vec4i * viewport ) { - ui::state & UI = get_UI(); i8 is_mmb = ui::is_mouse_held( ui::mmb ); if ( is_mmb ) { - vec2d mouse_pos = UI.mouse_pos; vec2d mouse_drag = ui::get_mouse_drag_delta ( ui::mmb ); if ( norm( mouse_drag ) == 0 ) return false; diff --git a/CameraParameterEstimation/apps/basics/gfx/gpu_assets.h b/CameraParameterEstimation/apps/basics/gfx/gpu_assets.h index 5eda197..0eaac4b 100644 --- a/CameraParameterEstimation/apps/basics/gfx/gpu_assets.h +++ b/CameraParameterEstimation/apps/basics/gfx/gpu_assets.h @@ -711,4 +711,4 @@ free_gpu_tex( gpu_texture * tex ) // glDeleteRenderbuffers( 1, &(rb->id) ); // } -#endif //BSC_IMPLEMENTATION \ No newline at end of file +#endif //BSC_IMPLEMENTATION diff --git a/CameraParameterEstimation/apps/basics/gfx/image.h b/CameraParameterEstimation/apps/basics/gfx/image.h index ec152ef..c3fe86f 100644 --- a/CameraParameterEstimation/apps/basics/gfx/image.h +++ b/CameraParameterEstimation/apps/basics/gfx/image.h @@ -262,13 +262,13 @@ read( const char * filename ) if ( data != nullptr ) { free( data ); data=nullptr; } // determine extension - char * period = strrchr( filename, '.' ); + const char * period = strrchr( filename, '.' ); if ( period == NULL ) { printf( "Image reading error -> No file extension\n" ); return 0; } - char * extension = period + 1; + const char * extension = period + 1; // call appropriate function if ( !strcmp( extension, "jpg" ) || !strcmp( extension, "jpeg") ) @@ -379,14 +379,14 @@ template i32 bsc::image:: write( const char * filename ) { - char * period = strrchr( filename, '.' ); + const char * period = strrchr( filename, '.' ); if ( period == NULL ) { error( "Image writing error", __LINE__, "No file extension" ); return 0; } - char * extension = period + 1; + const char * extension = period + 1; if ( !strcmp( extension, "jpg" ) || !strcmp( extension, "jpeg") ) { return write_jpg( filename, this ); @@ -522,4 +522,4 @@ at ( i32 x, i32 y ) return &( this->data[ this->ncomp * (y * this->width + x )] ); } -#endif //BSC_IMAGE_H \ No newline at end of file +#endif //BSC_IMAGE_H diff --git a/CameraParameterEstimation/apps/basics/window/win.h b/CameraParameterEstimation/apps/basics/window/win.h index 2e18b61..e80ae2d 100644 --- a/CameraParameterEstimation/apps/basics/window/win.h +++ b/CameraParameterEstimation/apps/basics/window/win.h @@ -120,8 +120,7 @@ create_window ( const char * title, const i32 width, const i32 height, // lets get gl extension from glew // TODO: need to replace this library - #if defined(_WIN32) || defined(_WIN64) - #ifndef __EMSCRIPTEN__ + #if defined(_WIN32) || defined(_WIN64) || defined(__linux__) glewExperimental = GL_TRUE; if ( glewInit() != GLEW_OK ) { @@ -129,20 +128,6 @@ create_window ( const char * title, const i32 width, const i32 height, return 0; } #endif - #endif - - // lets create the vector graphics context - #ifdef __EMSCRIPTEN__ - // g_window.vg = nvgCreateGLES2( NVG_ANTIALIAS | NVG_STENCIL_STROKES ); - #else - // g_window.vg = nvgCreateGL3( NVG_ANTIALIAS | NVG_STENCIL_STROKES ); - #endif - - // if ( g_window.vg == NULL ) - // { - // printf( "Could not init nanovg\n" ); - // return 0; - // } // some sane opengl defaults glEnable( GL_DEPTH_TEST ); diff --git a/CameraParameterEstimation/apps/calibrate_depth/src/calibrate_depth.cpp b/CameraParameterEstimation/apps/calibrate_depth/src/calibrate_depth.cpp index f8c55b8..933009e 100644 --- a/CameraParameterEstimation/apps/calibrate_depth/src/calibrate_depth.cpp +++ b/CameraParameterEstimation/apps/calibrate_depth/src/calibrate_depth.cpp @@ -114,6 +114,7 @@ ReadParametersFile( bsc::mat3 &intrinsics, bsc::mat4 &extrinsics, const char* filename ) { + int success = 1; intrinsics = bsc::mat3(); extrinsics = bsc::mat4(); FILE * params_file = fopen( filename, "r" ); @@ -127,7 +128,6 @@ ReadParametersFile( bsc::mat3 &intrinsics, { char cmd[1024]; line_number++; - bool success = 1; if (sscanf(buffer, "%s =", cmd) != (unsigned int)1) { continue; @@ -172,7 +172,7 @@ ReadParametersFile( bsc::mat3 &intrinsics, } } fclose(params_file); - return 1; + return success; } printf( "Could not open parameters file %s\n", filename ); @@ -207,10 +207,12 @@ ReadPlanePoses( bsc::mat4 depth_to_color, { // Load in the plane pose bsc::mat4 pose; - fscanf(fp, "%f %f %f %f", &(pose[0][0]), &(pose[1][0]), &(pose[2][0]), &(pose[3][0])); - fscanf(fp, "%f %f %f %f", &(pose[0][1]), &(pose[1][1]), &(pose[2][1]), &(pose[3][1])); - fscanf(fp, "%f %f %f %f", &(pose[0][2]), &(pose[1][2]), &(pose[2][2]), &(pose[3][2])); - fscanf(fp, "%f %f %f %f", &(pose[0][3]), &(pose[1][3]), &(pose[2][3]), &(pose[3][3])); + int returned_bytes = 0; + returned_bytes = fscanf(fp, "%f %f %f %f", &(pose[0][0]), &(pose[1][0]), &(pose[2][0]), &(pose[3][0])); + returned_bytes = fscanf(fp, "%f %f %f %f", &(pose[0][1]), &(pose[1][1]), &(pose[2][1]), &(pose[3][1])); + returned_bytes = fscanf(fp, "%f %f %f %f", &(pose[0][2]), &(pose[1][2]), &(pose[2][2]), &(pose[3][2])); + returned_bytes = fscanf(fp, "%f %f %f %f", &(pose[0][3]), &(pose[1][3]), &(pose[2][3]), &(pose[3][3])); + (void)returned_bytes; plane_poses.push_back( color_to_depth * pose ); } @@ -609,10 +611,10 @@ ApplyUndistortion( const SequenceData * seq_data, const Options * opts ) } std::string im_name = seq_data->image_names[im_idx]; int name_length = im_name.length(); - const char *img_name = im_name.substr(0, name_length - 4).c_str(); + std::string img_name = im_name.substr(0, name_length - 4); char depth_name[256], depth_raw_name[256]; - sprintf( depth_raw_name, "depth_raw/%s.png", img_name ); - sprintf( depth_name, "depth/%s.png", img_name ); + sprintf( depth_raw_name, "depth_raw/%s.png", img_name.c_str() ); + sprintf( depth_name, "depth/%s.png", img_name.c_str() ); raw_depth_im.read( depth_raw_name ); for ( i32 j = 0; j < h; ++j ) @@ -1233,4 +1235,4 @@ int main(int argc, char **argv) bsc::main_loop(); return 1; -} \ No newline at end of file +} diff --git a/CameraParameterEstimation/apps/calibrate_depth/src/makefile b/CameraParameterEstimation/apps/calibrate_depth/src/makefile index a0d9e54..97fcc6a 100644 --- a/CameraParameterEstimation/apps/calibrate_depth/src/makefile +++ b/CameraParameterEstimation/apps/calibrate_depth/src/makefile @@ -7,7 +7,7 @@ LIB_DIR = /usr/local/lib OUT_DIR = ../out/ BSC_DIR = ../../basics/ IMGUI_DIR = $(BSC_DIR)extern/imgui/ - +UNAME = $(shell uname -s) # List of source files SRCS =calibrate_depth.cpp $(IMGUI_DIR)imgui.cpp $(IMGUI_DIR)imgui_draw.cpp @@ -15,24 +15,35 @@ OBJS = $(SRCS:%.cpp=$(OUT_DIR)%.o) # Compile and link options CC = g++ -WARNINGS = -Wall +WARNINGS = -Wall -Wno-unused-result CPPFLAGS = -std=c++11 -O -I. -I/usr/local/include -I$(IMGUI_DIR) -I$(BSC_DIR) # Libraries -LIBS = -L$(LIB_DIR) -lglew -lglfw3 +LIBS = -L$(LIB_DIR) # Frameworks FRAMEWORKS = -framework OpenGL -framework GLUT +ifeq ($(UNAME),Linux) + LIBS += -lGL -lGLEW -lglfw +endif + +ifeq ($(UNAME),Darwin) + LIBS += $(FRAMEWORKS) -lglew -lglfw + CPPFLAGS += -DGL_SILENCE_DEPRECATION +endif + # Make targets -all: clean calibrate_depth +all: clean make_directories calibrate_depth calibrate_depth: $(OBJS) - $(CC) $(FRAMEWORKS) $(CPPFLAGS) $(OBJS) $(LIBS) -o ${BIN_DIR}${EXE_NAME} + $(CC) $(CPPFLAGS) $(OBJS) -o ${BIN_DIR}${EXE_NAME} $(LIBS) clean: rm -f $(OUT_DIR)*.a $(OUT_DIR)*.o ${BIN_DIR}${EXE_NAME} ${BIN_DIR}${EXE_NAME}.exe +make_directories: + mkdir -p ../out; mkdir -p ../../../bin # Compile command $(OUT_DIR)%.o: %.cpp diff --git a/CameraParameterEstimation/apps/calibration_explorer/src/calibration_explorer.cpp b/CameraParameterEstimation/apps/calibration_explorer/src/calibration_explorer.cpp index e411e96..06c77a4 100644 --- a/CameraParameterEstimation/apps/calibration_explorer/src/calibration_explorer.cpp +++ b/CameraParameterEstimation/apps/calibration_explorer/src/calibration_explorer.cpp @@ -225,7 +225,7 @@ render_explorer_pointcloud( bsc::gpu_geometry *pointcloud_geo, bool should_update, char * vs_src, char * fs_src ) { - if ( pointcloud_geo->vao == -1 ) + if ( pointcloud_geo->vao == (u32)-1 ) { create_3d_pointcloud( pointcloud_geo, color_image, depth_image, K, true ); bsc::create_shader_prog_from_source( vs_src, fs_src, pointcloud_shader ); @@ -345,7 +345,7 @@ transform_img ( const bsc::img_u16 *src, u32 n_pos = src->width * src->height; u32 size = n_pos * sizeof(bsc::vec3); vec3 * positions = (vec3*)malloc(size); - memset( positions, 0, size ); + memset( (void*)positions, 0, size ); // backproject for ( i32 y = 0 ; y < src->height ; y++ ) diff --git a/CameraParameterEstimation/apps/calibration_explorer/src/makefile b/CameraParameterEstimation/apps/calibration_explorer/src/makefile index 746ecbd..730e706 100644 --- a/CameraParameterEstimation/apps/calibration_explorer/src/makefile +++ b/CameraParameterEstimation/apps/calibration_explorer/src/makefile @@ -5,34 +5,45 @@ EXE_NAME = calibration_explorer BIN_DIR = ../../../bin/ LIB_DIR = /usr/local/lib/ OUT_DIR = ../out/ - BSC_DIR = ../../basics/ IMGUI_DIR = $(BSC_DIR)extern/imgui/ +UNAME = $(shell uname -s) # List of source files SRCS = calibration_explorer.cpp $(IMGUI_DIR)imgui.cpp $(IMGUI_DIR)imgui_draw.cpp OBJS = $(SRCS:%.cpp=$(OUT_DIR)%.o) # Compile and link options CC = g++ -WARNINGS = -Wall +WARNINGS = -Wall -Wno-unused-result CPPFLAGS = -std=c++11 -O -I. -I/usr/local/include -I$(IMGUI_DIR) -I$(BSC_DIR) # Libraries -LIBS = -L$(LIB_DIR) -lglew -lglfw3 +LIBS = -L$(LIB_DIR) # Frameworks -FRAMEWORKS = -framework opengl +FRAMEWORKS = -framework OpenGL -framework GLUT + +ifeq ($(UNAME),Linux) + LIBS += -lGL -lGLEW -lglfw +endif + +ifeq ($(UNAME),Darwin) + LIBS += $(FRAMEWORKS) -lglew -lglfw + CPPFLAGS += -DGL_SILENCE_DEPRECATION +endif # Make targets -all: clean calibration_explorer +all: clean make_directories calibration_explorer calibration_explorer: $(OBJS) - $(CC) $(FRAMEWORKS) $(CPPFLAGS) $(OBJS) $(LIBS) -o ${BIN_DIR}${EXE_NAME} + $(CC) $(CPPFLAGS) $(OBJS) -o ${BIN_DIR}${EXE_NAME} $(LIBS) clean: rm -f $(OUT_DIR)*.a $(OUT_DIR)*.o ${BIN_DIR}${EXE_NAME} ${BIN_DIR}${EXE_NAME}.exe +make_directories: + mkdir -p ../out; mkdir -p ../../../bin # Compile command $(OUT_DIR)%.o: %.cpp diff --git a/CameraParameterEstimation/tutorial/tutorial.md b/CameraParameterEstimation/tutorial/tutorial.md index 941bad9..066b00f 100644 --- a/CameraParameterEstimation/tutorial/tutorial.md +++ b/CameraParameterEstimation/tutorial/tutorial.md @@ -85,7 +85,7 @@ ____. __calibrate_depth__ can use these when run in apply mode ~~~~~~~~ calibrate_depth depth_distortion_calibration.conf --apply_undistortion ~~~~~~~~ -But this file formats will also work with [ScanNet](http://link) pipeline. +But this file formats will also work with ScanNet pipeline. You can also run the __calibrate_depth__ without any argument to see how the images got undistorted. @@ -108,3 +108,18 @@ well images are aligned. All calibration parameters are also exposed if some manual intervention is needed/wanted. You can pass __--output_parameters __ to the __calibration_explorer__ to be able to save the modified parameters. + +`validation.conf` file is a simple text file that lists all the input images and +links to the __parameters.txt__ file. + +File should be formated as follows: +~~~ +n_images + +parameters +scan 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 +scan 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 +scan 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 +scan 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 +... +~~~