├── .clang-format ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── algorithmparameters.h ├── camera.h ├── cameraGeometryUtils.h ├── cameraparameters.h ├── config.h ├── data └── dtu │ └── calib │ ├── rect_001_3_r5000.png.P │ ├── rect_001_3_r7000.png.P │ ├── rect_001_6_r5000.png.P │ ├── rect_002_3_r5000.png.P │ ├── rect_002_3_r7000.png.P │ ├── rect_002_6_r5000.png.P │ ├── rect_003_3_r5000.png.P │ ├── rect_003_3_r7000.png.P │ ├── rect_003_6_r5000.png.P │ ├── rect_004_3_r5000.png.P │ ├── rect_004_3_r7000.png.P │ ├── rect_004_6_r5000.png.P │ ├── rect_005_3_r5000.png.P │ ├── rect_005_3_r7000.png.P │ ├── rect_005_6_r5000.png.P │ ├── rect_006_3_r5000.png.P │ ├── rect_006_3_r7000.png.P │ ├── rect_006_6_r5000.png.P │ ├── rect_007_3_r5000.png.P │ ├── rect_007_3_r7000.png.P │ ├── rect_007_6_r5000.png.P │ ├── rect_008_3_r5000.png.P │ ├── rect_008_3_r7000.png.P │ ├── rect_008_6_r5000.png.P │ ├── rect_009_3_r5000.png.P │ ├── rect_009_3_r7000.png.P │ ├── rect_009_6_r5000.png.P │ ├── rect_010_3_r5000.png.P │ ├── rect_010_3_r7000.png.P │ ├── rect_010_6_r5000.png.P │ ├── rect_011_3_r5000.png.P │ ├── rect_011_3_r7000.png.P │ ├── rect_011_6_r5000.png.P │ ├── rect_012_3_r5000.png.P │ ├── rect_012_3_r7000.png.P │ ├── rect_012_6_r5000.png.P │ ├── rect_013_3_r5000.png.P │ ├── rect_013_3_r7000.png.P │ ├── rect_013_6_r5000.png.P │ ├── rect_014_3_r5000.png.P │ ├── rect_014_3_r7000.png.P │ ├── rect_014_6_r5000.png.P │ ├── rect_015_3_r5000.png.P │ ├── rect_015_3_r7000.png.P │ ├── rect_015_6_r5000.png.P │ ├── rect_016_3_r5000.png.P │ ├── rect_016_3_r7000.png.P │ ├── rect_016_6_r5000.png.P │ ├── rect_017_3_r5000.png.P │ ├── rect_017_3_r7000.png.P │ ├── rect_017_6_r5000.png.P │ ├── rect_018_3_r5000.png.P │ ├── rect_018_3_r7000.png.P │ ├── rect_018_6_r5000.png.P │ ├── rect_019_3_r5000.png.P │ ├── rect_019_3_r7000.png.P │ ├── rect_019_6_r5000.png.P │ ├── rect_020_3_r5000.png.P │ ├── rect_020_3_r7000.png.P │ ├── rect_020_6_r5000.png.P │ ├── rect_021_3_r5000.png.P │ ├── rect_021_3_r7000.png.P │ ├── rect_021_6_r5000.png.P │ ├── rect_022_3_r5000.png.P │ ├── rect_022_3_r7000.png.P │ ├── rect_022_6_r5000.png.P │ ├── rect_023_3_r5000.png.P │ ├── rect_023_3_r7000.png.P │ ├── rect_023_6_r5000.png.P │ ├── rect_024_3_r5000.png.P │ ├── rect_024_3_r7000.png.P │ ├── rect_024_6_r5000.png.P │ ├── rect_025_3_r5000.png.P │ ├── rect_025_3_r7000.png.P │ ├── rect_025_6_r5000.png.P │ ├── rect_026_3_r5000.png.P │ ├── rect_026_3_r7000.png.P │ ├── rect_026_6_r5000.png.P │ ├── rect_027_3_r5000.png.P │ ├── rect_027_3_r7000.png.P │ ├── rect_027_6_r5000.png.P │ ├── rect_028_3_r5000.png.P │ ├── rect_028_3_r7000.png.P │ ├── rect_028_6_r5000.png.P │ ├── rect_029_3_r5000.png.P │ ├── rect_029_3_r7000.png.P │ ├── rect_029_6_r5000.png.P │ ├── rect_030_3_r5000.png.P │ ├── rect_030_3_r7000.png.P │ ├── rect_030_6_r5000.png.P │ ├── rect_031_3_r5000.png.P │ ├── rect_031_3_r7000.png.P │ ├── rect_031_6_r5000.png.P │ ├── rect_032_3_r5000.png.P │ ├── rect_032_3_r7000.png.P │ ├── rect_032_6_r5000.png.P │ ├── rect_033_3_r5000.png.P │ ├── rect_033_3_r7000.png.P │ ├── rect_033_6_r5000.png.P │ ├── rect_034_3_r5000.png.P │ ├── rect_034_3_r7000.png.P │ ├── rect_034_6_r5000.png.P │ ├── rect_035_3_r5000.png.P │ ├── rect_035_3_r7000.png.P │ ├── rect_035_6_r5000.png.P │ ├── rect_036_3_r5000.png.P │ ├── rect_036_3_r7000.png.P │ ├── rect_036_6_r5000.png.P │ ├── rect_037_3_r5000.png.P │ ├── rect_037_3_r7000.png.P │ ├── rect_037_6_r5000.png.P │ ├── rect_038_3_r5000.png.P │ ├── rect_038_3_r7000.png.P │ ├── rect_038_6_r5000.png.P │ ├── rect_039_3_r5000.png.P │ ├── rect_039_3_r7000.png.P │ ├── rect_039_6_r5000.png.P │ ├── rect_040_3_r5000.png.P │ ├── rect_040_3_r7000.png.P │ ├── rect_040_6_r5000.png.P │ ├── rect_041_3_r5000.png.P │ ├── rect_041_3_r7000.png.P │ ├── rect_041_6_r5000.png.P │ ├── rect_042_3_r5000.png.P │ ├── rect_042_3_r7000.png.P │ ├── rect_042_6_r5000.png.P │ ├── rect_043_3_r5000.png.P │ ├── rect_043_3_r7000.png.P │ ├── rect_043_6_r5000.png.P │ ├── rect_044_3_r5000.png.P │ ├── rect_044_3_r7000.png.P │ ├── rect_044_6_r5000.png.P │ ├── rect_045_3_r5000.png.P │ ├── rect_045_3_r7000.png.P │ ├── rect_045_6_r5000.png.P │ ├── rect_046_3_r5000.png.P │ ├── rect_046_3_r7000.png.P │ ├── rect_046_6_r5000.png.P │ ├── rect_047_3_r5000.png.P │ ├── rect_047_3_r7000.png.P │ ├── rect_047_6_r5000.png.P │ ├── rect_048_3_r5000.png.P │ ├── rect_048_3_r7000.png.P │ ├── rect_048_6_r5000.png.P │ ├── rect_049_3_r5000.png.P │ ├── rect_049_3_r7000.png.P │ ├── rect_049_6_r5000.png.P │ ├── rect_050_3_r5000.png.P │ ├── rect_050_3_r7000.png.P │ ├── rect_050_6_r5000.png.P │ ├── rect_051_3_r5000.png.P │ ├── rect_051_3_r7000.png.P │ ├── rect_051_6_r5000.png.P │ ├── rect_052_3_r5000.png.P │ ├── rect_052_3_r7000.png.P │ ├── rect_052_6_r5000.png.P │ ├── rect_053_3_r5000.png.P │ ├── rect_053_3_r7000.png.P │ ├── rect_053_6_r5000.png.P │ ├── rect_054_3_r5000.png.P │ ├── rect_054_3_r7000.png.P │ ├── rect_054_6_r5000.png.P │ ├── rect_055_3_r5000.png.P │ ├── rect_055_3_r7000.png.P │ ├── rect_055_6_r5000.png.P │ ├── rect_056_3_r5000.png.P │ ├── rect_056_3_r7000.png.P │ ├── rect_056_6_r5000.png.P │ ├── rect_057_3_r5000.png.P │ ├── rect_057_3_r7000.png.P │ ├── rect_057_6_r5000.png.P │ ├── rect_058_3_r5000.png.P │ ├── rect_058_3_r7000.png.P │ ├── rect_058_6_r5000.png.P │ ├── rect_059_3_r5000.png.P │ ├── rect_059_3_r7000.png.P │ ├── rect_059_6_r5000.png.P │ ├── rect_060_3_r5000.png.P │ ├── rect_060_3_r7000.png.P │ ├── rect_060_6_r5000.png.P │ ├── rect_061_3_r5000.png.P │ ├── rect_061_3_r7000.png.P │ ├── rect_061_6_r5000.png.P │ ├── rect_062_3_r5000.png.P │ ├── rect_062_3_r7000.png.P │ ├── rect_062_6_r5000.png.P │ ├── rect_063_3_r5000.png.P │ ├── rect_063_3_r7000.png.P │ ├── rect_063_6_r5000.png.P │ ├── rect_064_3_r5000.png.P │ ├── rect_064_3_r7000.png.P │ └── rect_064_6_r5000.png.P ├── displayUtils.h ├── exception.h ├── fileIoUtils.h ├── gipuma.cu ├── gipuma.h ├── globalstate.h ├── groundTruthUtils.h ├── helper_cuda.h ├── helper_string.h ├── imageinfo.h ├── linestate.h ├── main.cpp ├── main.h ├── managed.h ├── mathUtils.h ├── readmeWindows.txt ├── scripts ├── dino.sh ├── dinoRing.sh ├── dinoSparseRing.sh ├── download-dtu.sh ├── download-middlebury.sh ├── dtu_accurate.sh ├── dtu_fast.sh ├── temple.sh ├── templeRing.sh └── templeSparseRing.sh ├── vector_operations.h └── win32_dirent.h /.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | # BasedOnStyle: Google 4 | AccessModifierOffset: -1 5 | AlignAfterOpenBracket: true 6 | AlignEscapedNewlinesLeft: true 7 | AlignOperands: true 8 | AlignTrailingComments: true 9 | AllowAllParametersOfDeclarationOnNextLine: true 10 | AllowShortBlocksOnASingleLine: false 11 | AllowShortCaseLabelsOnASingleLine: false 12 | AllowShortIfStatementsOnASingleLine: true 13 | AllowShortLoopsOnASingleLine: true 14 | AllowShortFunctionsOnASingleLine: All 15 | AlwaysBreakAfterDefinitionReturnType: false 16 | AlwaysBreakTemplateDeclarations: true 17 | AlwaysBreakBeforeMultilineStrings: true 18 | BreakBeforeBinaryOperators: None 19 | BreakBeforeTernaryOperators: true 20 | BreakConstructorInitializersBeforeComma: false 21 | BinPackParameters: true 22 | BinPackArguments: true 23 | ColumnLimit: 80 24 | ConstructorInitializerAllOnOneLineOrOnePerLine: true 25 | ConstructorInitializerIndentWidth: 4 26 | DerivePointerAlignment: true 27 | ExperimentalAutoDetectBinPacking: false 28 | IndentCaseLabels: true 29 | IndentWrappedFunctionNames: false 30 | IndentFunctionDeclarationAfterType: false 31 | MaxEmptyLinesToKeep: 1 32 | KeepEmptyLinesAtTheStartOfBlocks: false 33 | NamespaceIndentation: None 34 | ObjCBlockIndentWidth: 2 35 | ObjCSpaceAfterProperty: false 36 | ObjCSpaceBeforeProtocolList: false 37 | PenaltyBreakBeforeFirstCallParameter: 1 38 | PenaltyBreakComment: 300 39 | PenaltyBreakString: 1000 40 | PenaltyBreakFirstLessLess: 120 41 | PenaltyExcessCharacter: 1000000 42 | PenaltyReturnTypeOnItsOwnLine: 200 43 | PointerAlignment: Left 44 | SpacesBeforeTrailingComments: 2 45 | Cpp11BracedListStyle: true 46 | Standard: Auto 47 | IndentWidth: 4 48 | TabWidth: 8 49 | UseTab: Never 50 | BreakBeforeBraces: Attach 51 | SpacesInParentheses: false 52 | SpacesInSquareBrackets: false 53 | SpacesInAngles: false 54 | SpaceInEmptyParentheses: false 55 | SpacesInCStyleCastParentheses: false 56 | SpaceAfterCStyleCast: false 57 | SpacesInContainerLiterals: true 58 | SpaceBeforeAssignmentOperators: true 59 | ContinuationIndentWidth: 4 60 | CommentPragmas: '^ IWYU pragma:' 61 | ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] 62 | SpaceBeforeParens: ControlStatements 63 | DisableFormat: false 64 | ... 65 | 66 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | cudacost.png 6 | cudadisp.png 7 | normals.png 8 | gipuma 9 | results 10 | scripts/data 11 | .cproject 12 | .project 13 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 3.9) 2 | project (gipuma) 3 | # Enable C++11 globally 4 | set(CMAKE_CXX_STANDARD 11) 5 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 6 | set(CMAKE_CXX_EXTENSIONS OFF) 7 | 8 | # Support IDEs: https://cliutils.gitlab.io/modern-cmake/chapters/features/ides.html 9 | set_property(GLOBAL PROPERTY USE_FOLDERS ON) 10 | set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "cmake-default-targets") 11 | 12 | find_package(CUDA 6.0 REQUIRED ) # For Cuda Managed Memory and c++11 13 | find_package(OpenCV REQUIRED ) 14 | if(NOT DEFINED CMAKE_CUDA_STANDARD) 15 | set(CMAKE_CUDA_STANDARD 11) 16 | set(CMAKE_CUDA_STANDARD_REQUIRED ON) 17 | endif() 18 | 19 | include_directories(${OpenCV_INCLUDE_DIRS}) 20 | include_directories(.) 21 | 22 | # from https://en.wikipedia.org/wiki/CUDA#GPUs_supported 23 | set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-O3 --use_fast_math --ptxas-options=-v --compiler-options -Wall -gencode arch=compute_30,code=sm_30 -gencode arch=compute_32,code=sm_32 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_62,code=sm_62 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_72,code=sm_72 -gencode arch=compute_75,code=sm_75) 24 | #set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-O3 --use_fast_math --ptxas-options=-v -std=c++11 --compiler-options -Wall -gencode arch=compute_52,code=sm_52) 25 | 26 | if(CMAKE_COMPILER_IS_GNUCXX) 27 | add_definitions(-Wall) 28 | add_definitions(-Wextra) 29 | add_definitions(-pedantic) 30 | add_definitions(-Wno-unused-function) 31 | add_definitions(-Wno-switch) 32 | set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast -ffast-math -march=native") # extend release-profile with fast-math 33 | endif() 34 | 35 | find_package(OpenMP) 36 | if (OPENMP_FOUND) 37 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") 38 | endif() 39 | 40 | if(MSVC) 41 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 42 | endif() 43 | 44 | 45 | # For compilation ... 46 | # Specify target & source files to compile it from 47 | cuda_add_executable( 48 | gipuma 49 | cameraGeometryUtils.h 50 | vector_operations.h 51 | camera.h 52 | globalstate.h 53 | algorithmparameters.h 54 | cameraparameters.h 55 | linestate.h 56 | groundTruthUtils.h 57 | displayUtils.h 58 | fileIoUtils.h 59 | main.h 60 | gipuma.cu 61 | main.cpp 62 | ) 63 | 64 | # For linking ... 65 | # Specify target & libraries to link it with 66 | target_link_libraries(gipuma 67 | ${OpenCV_LIBS} 68 | OpenMP::OpenMP_CXX 69 | ) 70 | 71 | include(FeatureSummary) 72 | feature_summary(WHAT ALL) 73 | 74 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gipuma 2 | 3 | Source code for the paper: 4 | 5 | _S. Galliani, K. Lasinger and K. Schindler_, [**Massively Parallel Multiview Stereopsis by Surface Normal Diffusion**](http://www.prs.igp.ethz.ch/content/dam/ethz/special-interest/baug/igp/photogrammetry-remote-sensing-dam/documents/pdf/galliani-lasinger-iccv15.pdf) [(**supplementary material**)](http://www.prs.igp.ethz.ch/content/dam/ethz/special-interest/baug/igp/photogrammetry-remote-sensing-dam/documents/pdf/galliani-lasinger-supplementary-iccv15.pdf), [ICCV 2015](http://pamitc.org/iccv15/) 6 | 7 | ## Documentation and Install 8 | Refer to the [wiki](https://github.com/kysucix/gipuma/wiki) for detailed documentation and examples. 9 | 10 | ## Authors 11 | - [Silvano Galliani](mailto:kysucix@dyne.org) 12 | - [Katrin Lasinger](mailto:katrin.lasinger@geod.baug.ethz.ch) 13 | 14 | © 2015-2022 Silvano Galliani, Katrin Lasinger, ETH Zurich 15 | 16 | 17 | **IMPORTANT**: If you use this software please cite the following in any resulting publication: 18 | ``` 19 | @InProceedings{Galliani_2015_ICCV, 20 | author = {Galliani, Silvano and Lasinger, Katrin and Schindler, Konrad}, 21 | title = {Massively Parallel Multiview Stereopsis by Surface Normal Diffusion}, 22 | journal = {The IEEE International Conference on Computer Vision (ICCV)}, 23 | month = {June}, 24 | year = {2015} 25 | } 26 | ``` 27 | -------------------------------------------------------------------------------- /algorithmparameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "managed.h" 3 | 4 | //cost function 5 | enum { 6 | PM_COST = 0, 7 | CENSUS_TRANSFORM = 1, 8 | ADAPTIVE_CENSUS = 2, 9 | CENSUS_SELFSIMILARITY = 3, 10 | PM_SELFSIMILARITY = 4, 11 | ADCENSUS = 5, 12 | ADCENSUS_SELFSIMILARITY = 6, 13 | SPARSE_CENSUS = 7 14 | }; 15 | 16 | //cost combination 17 | enum { COMB_ALL = 0, COMB_BEST_N = 1, COMB_ANGLE = 2, COMB_GOOD = 3 }; 18 | 19 | struct AlgorithmParameters : public Managed{ 20 | 21 | AlgorithmParameters(): 22 | algorithm (0), // algorithm cost type 23 | max_disparity (256.0f), // maximal disparity value CUDA 24 | min_disparity (0.0f), // minimum disparity value (default 0) CUDA 25 | box_hsize (19), // filter kernel width CUDA 26 | box_vsize (19), // filter kernel height CUDA 27 | tau_color (10), // PM_COST max. threshold for color CUDA 28 | tau_gradient (2.0f), // PM_COST max. threshold for gradient CUDA 29 | alpha (0.9f), // PM_COST weighting between color and gradient CUDA 30 | gamma (10.0f), // parameter for weight function (used e.g. in PM_COST) CUDA 31 | border_value (-1), // what value should pixel at extended border get (constant or replicate -1) 32 | iterations (8), // number of iterations 33 | color_processing (false), // use color processing or not (otherwise just grayscale processing) 34 | dispTol (1.0), //PM Stereo: 1, PM Huber: 0.5 35 | normTol (0.1f), // 0.1 ... about 5.7 degrees 36 | census_epsilon (2.5f), //for census transform 37 | self_similarity_n (50), // number of pixels considered for self similarity 38 | cam_scale (1.0f), //used to rescale K in case of rescaled image size 39 | num_img_processed (1), //number of images that are processed as reference images 40 | costThresh (40.0f), // threshold to decide whether disparity/depth is valid or not 41 | good_factor (1.5f), // for cost aggregation/combination good: factor for truncation CUDA 42 | n_best (2), // CUDA 43 | cost_comb (1), // CUDA 44 | viewSelection (true), // Default has to be false, or user has no way to disable view selection 45 | depthMin (-1.0f), // CUDA 46 | depthMax (-1.0f), // CUDA 47 | min_angle (5.0f), // CUDA 48 | max_angle (45.0f), // CUDA 49 | no_texture_sim (0.9f), // CUDA 50 | no_texture_per (0.6f), // CUDA 51 | max_views (9) {} 52 | int algorithm; // algorithm cost type 53 | float max_disparity; // maximal disparity value CUDA 54 | float min_disparity; // minimum disparity value (default 0) CUDA 55 | int box_hsize; // filter kernel width CUDA 56 | int box_vsize; // filter kernel height CUDA 57 | float tau_color; // PM_COST max. threshold for color CUDA 58 | float tau_gradient; // PM_COST max. threshold for gradient CUDA 59 | float alpha; // PM_COST weighting between color and gradient CUDA 60 | float gamma; // parameter for weight function (used e.g. in PM_COST) CUDA 61 | int border_value; // what value should pixel at extended border get (constant or replicate -1) 62 | int iterations; // number of iterations 63 | bool color_processing; // use color processing or not (otherwise just grayscale processing) 64 | float dispTol; //PM Stereo: 1, PM Huber: 0.5 65 | float normTol; // 0.1 ... about 5.7 degrees 66 | float census_epsilon; //for census transform 67 | int self_similarity_n; // number of pixels considered for self similarity 68 | float cam_scale; //used to rescale K in case of rescaled image size 69 | int num_img_processed; //number of images that are processed as reference images 70 | float costThresh; // threshold to decide whether disparity/depth is valid or not 71 | float good_factor; // for cost aggregation/combination good: factor for truncation CUDA 72 | int n_best; // CUDA 73 | int cost_comb; // CUDA 74 | bool viewSelection; 75 | float depthMin; // CUDA 76 | float depthMax; // CUDA 77 | float min_angle; // CUDA 78 | float max_angle; // CUDA 79 | float no_texture_sim; // CUDA 80 | float no_texture_per; // CUDA 81 | unsigned int max_views; 82 | // hack XXX 83 | int cols; 84 | int rows; 85 | }; 86 | -------------------------------------------------------------------------------- /camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "managed.h" 3 | #include 4 | #include 5 | #include "helper_cuda.h" 6 | 7 | class Camera_cu : public Managed { 8 | public: 9 | float* P; 10 | float4 P_col34; 11 | float* P_inv; 12 | float* M_inv; 13 | float* R; 14 | float* R_orig_inv; 15 | float4 t4; 16 | float4 C4; 17 | float fx; 18 | float fy; 19 | float f; 20 | float alpha; 21 | float baseline; 22 | bool reference; 23 | float depthMin; // this could be figured out from the bounding volume (not 24 | // done right now, but that's why this parameter is here as 25 | // well and not only in AlgorithmParameters) 26 | float depthMax; // this could be figured out from the bounding volume (not 27 | // done right now, but that's why this parameter is here as 28 | // well and not only in AlgorithmParameters) 29 | char* id; // corresponds to the image name id (eg. 0-10), independent of 30 | // order in argument list, just dependent on name 31 | float* K; 32 | float* K_inv; 33 | Camera_cu() { 34 | baseline = 0.54f; 35 | reference = false; 36 | depthMin = 2.0f; // this could be figured out from the bounding volume 37 | // (not done right now, but that's why this parameter 38 | // is here as well and not only in 39 | // AlgorithmParameters) 40 | depthMax = 20.0f; // this could be figured out from the bounding volume 41 | // (not done right now, but that's why this parameter 42 | // is here as well and not only in 43 | // AlgorithmParameters) 44 | 45 | checkCudaErrors(cudaMallocManaged(&P, sizeof(float) * 4 * 4)); 46 | checkCudaErrors(cudaMallocManaged(&P_inv, sizeof(float) * 4 * 4)); 47 | checkCudaErrors(cudaMallocManaged(&M_inv, sizeof(float) * 4 * 4)); 48 | checkCudaErrors(cudaMallocManaged(&K, sizeof(float) * 4 * 4)); 49 | checkCudaErrors(cudaMallocManaged(&K_inv, sizeof(float) * 4 * 4)); 50 | checkCudaErrors(cudaMallocManaged(&R, sizeof(float) * 4 * 4)); 51 | checkCudaErrors(cudaMallocManaged(&R_orig_inv, sizeof(float) * 4 * 4)); 52 | } 53 | ~Camera_cu() { 54 | cudaFree(P); 55 | cudaFree(P_inv); 56 | cudaFree(M_inv); 57 | cudaFree(K); 58 | cudaFree(K_inv); 59 | cudaFree(R); 60 | cudaFree(R_orig_inv); 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /cameraGeometryUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * cameraGeometryUtils.h 3 | * 4 | * utility functions for camera geometry related stuff 5 | * most of them from: "Multiple View Geometry in computer vision" by Hartley and Zisserman 6 | */ 7 | 8 | #pragma once 9 | #include "mathUtils.h" 10 | #include 11 | #include 12 | 13 | Mat_ getColSubMat ( Mat_ M, int* indices, int numCols ) { 14 | Mat_ subMat = Mat::zeros ( M.rows,numCols,CV_32F ); 15 | for ( int i = 0; i < numCols; i++ ) { 16 | M.col ( indices[i] ).copyTo ( subMat.col ( i ) ); 17 | } 18 | return subMat; 19 | } 20 | 21 | // Multi View Geometry, page 163 22 | Mat_ getCameraCenter ( Mat_ &P ) { 23 | Mat_ C = Mat::zeros ( 4,1,CV_32F ); 24 | 25 | Mat_ M = Mat::zeros ( 3,3,CV_32F ); 26 | 27 | int xIndices[] = { 1, 2, 3 }; 28 | int yIndices[] = { 0, 2, 3 }; 29 | int zIndices[] = { 0, 1, 3 }; 30 | int tIndices[] = { 0, 1, 2 }; 31 | 32 | // x coordinate 33 | M = getColSubMat ( P,xIndices,sizeof ( xIndices )/sizeof ( xIndices[0] ) ); 34 | C ( 0,0 ) = ( float )determinant ( M ); 35 | 36 | // y coordinate 37 | M = getColSubMat ( P,yIndices,sizeof ( yIndices )/sizeof ( yIndices[0] ) ); 38 | C ( 1,0 ) = - ( float )determinant ( M ); 39 | 40 | // z coordinate 41 | M = getColSubMat ( P,zIndices,sizeof ( zIndices )/sizeof ( zIndices[0] ) ); 42 | C ( 2,0 ) = ( float )determinant ( M ); 43 | 44 | // t coordinate 45 | M = getColSubMat ( P,tIndices,sizeof ( tIndices )/sizeof ( tIndices[0] ) ); 46 | C ( 3,0 ) = - ( float )determinant ( M ); 47 | 48 | return C; 49 | } 50 | 51 | inline Vec3f get3Dpoint ( Camera &cam, float x, float y, float depth ) { 52 | // in case camera matrix is not normalized: see page 162, then depth might not be the real depth but w and depth needs to be computed from that first 53 | 54 | Mat_ pt = Mat::ones ( 3,1,CV_32F ); 55 | pt ( 0,0 ) = x; 56 | pt ( 1,0 ) = y; 57 | 58 | //formula taken from page 162 (alternative expression) 59 | Mat_ ptX = cam.M_inv * ( depth*pt - cam.P.col ( 3 ) ); 60 | return Vec3f ( ptX ( 0 ),ptX ( 1 ),ptX ( 2 ) ); 61 | } 62 | 63 | inline Vec3f get3Dpoint ( Camera &cam, int x, int y, float depth ){ 64 | return get3Dpoint(cam,(float)x,(float)y,depth); 65 | } 66 | 67 | // get the viewing ray for a pixel position of the camera 68 | static inline Vec3f getViewVector ( Camera &cam, int x, int y) { 69 | 70 | //get some point on the line (the other point on the line is the camera center) 71 | Vec3f ptX = get3Dpoint ( cam,x,y,1.0f ); 72 | 73 | //get vector between camera center and other point on the line 74 | Vec3f v = ptX - cam.C; 75 | return normalize ( v ); 76 | } 77 | 78 | /* get depth from 3D point 79 | * page 162: w = P3T*X (P3T ... third (=last) row of projection matrix P) 80 | */ 81 | float getDepth ( Vec3f &X, Mat_ &P ) { 82 | //assuming homogenous component of X being 1 83 | float w = P ( 2,0 )*X ( 0 ) + P ( 2,1 ) * X ( 1 ) + P ( 2,2 ) * X ( 2 ) + P ( 2,3 ); 84 | 85 | return w; 86 | } 87 | 88 | Mat_ getTransformationMatrix ( Mat_ R, Mat_ t ) { 89 | Mat_ transMat = Mat::eye ( 4,4, CV_32F ); 90 | //Mat_ Rt = - R * t; 91 | R.copyTo ( transMat ( Range ( 0,3 ),Range ( 0,3 ) ) ); 92 | t.copyTo ( transMat ( Range ( 0,3 ),Range ( 3,4 ) ) ); 93 | 94 | return transMat; 95 | } 96 | 97 | /* compute depth value from disparity or disparity value from depth 98 | * Input: f - focal length in pixel 99 | * baseline - baseline between cameras (in meters) 100 | * d - either disparity or depth value 101 | * Output: either depth or disparity value 102 | */ 103 | float disparityDepthConversion ( float f, float baseline, float d ) { 104 | /*if ( d == 0 )*/ 105 | /*return FLT_MAX;*/ 106 | return f * baseline / d; 107 | } 108 | 109 | Mat_ getTransformationReferenceToOrigin ( Mat_ R,Mat_ t ) { 110 | // create rotation translation matrix 111 | Mat_ transMat_original = getTransformationMatrix ( R,t ); 112 | 113 | // get transformation matrix for [R1|t1] = [I|0] 114 | return transMat_original.inv (); 115 | } 116 | 117 | void transformCamera ( Mat_ R,Mat_ t, Mat_ transform, Camera &cam, Mat_ K ) { 118 | // create rotation translation matrix 119 | Mat_ transMat_original = getTransformationMatrix ( R,t ); 120 | 121 | //transform 122 | Mat_ transMat_t = transMat_original * transform; 123 | 124 | // compute translated P (only consider upper 3x4 matrix) 125 | cam.P = K * transMat_t ( Range ( 0,3 ),Range ( 0,4 ) ); 126 | // set R and t 127 | cam.R = transMat_t ( Range ( 0,3 ),Range ( 0,3 ) ); 128 | cam.t = transMat_t ( Range ( 0,3 ),Range ( 3,4 ) ); 129 | // set camera center C 130 | Mat_ C = getCameraCenter ( cam.P ); 131 | 132 | C = C / C ( 3,0 ); 133 | cam.C = Vec3f ( C ( 0,0 ),C ( 1,0 ),C ( 2,0 ) ); 134 | } 135 | 136 | Mat_ scaleK ( Mat_ K, float scaleFactor ) { 137 | 138 | Mat_ K_scaled = K.clone(); 139 | //scale focal length 140 | K_scaled ( 0,0 ) = K ( 0,0 ) / scaleFactor; 141 | K_scaled ( 1,1 ) = K ( 1,1 ) / scaleFactor; 142 | //scale center point 143 | K_scaled ( 0,2 ) = K ( 0,2 ) / scaleFactor; 144 | K_scaled ( 1,2 ) = K ( 1,2 ) / scaleFactor; 145 | 146 | return K_scaled; 147 | } 148 | void copyOpencvVecToFloat4 ( Vec3f &v, float4 *a) 149 | { 150 | a->x = v(0); 151 | a->y = v(1); 152 | a->z = v(2); 153 | } 154 | void copyOpencvVecToFloatArray ( Vec3f &v, float *a) 155 | { 156 | a[0] = v(0); 157 | a[1] = v(1); 158 | a[2] = v(2); 159 | } 160 | void copyOpencvMatToFloatArray ( Mat_ &m, float **a) 161 | { 162 | for (int pj=0; pj KMaros = Mat::eye ( 3, 3, CV_32F ); 193 | KMaros(0,0) = 8066.0; 194 | KMaros(1,1) = 8066.0; 195 | KMaros(0,2) = 2807.5; 196 | KMaros(1,2) = 1871.5; 197 | //load projection matrix from file (e.g. for Strecha) 198 | 199 | // Load pmvs files 200 | if ( !inputFiles.pmvs_folder.empty () ) { 201 | numCameras = inputFiles.img_filenames.size (); 202 | params.cameras.resize ( numCameras ); 203 | for ( size_t i = 0; i < numCameras; i++ ) { 204 | size_t lastindex = inputFiles.img_filenames[i].find_last_of("."); 205 | string filename_without_extension = inputFiles.img_filenames[i].substr(0, lastindex); 206 | readPFileStrechaPmvs ( inputFiles.p_folder + filename_without_extension + ".txt",params.cameras[i].P ); 207 | size_t found = inputFiles.img_filenames[i].find_last_of ( "." ); 208 | //params.cameras[i].id = atoi ( inputFiles.img_filenames[i].substr ( 0,found ).c_str () ); 209 | params.cameras[i].id = inputFiles.img_filenames[i].substr ( 0,found ).c_str (); 210 | // params.cameras[i].P = KMaros * params.cameras[i].P; 211 | //cout << params.cameras[i].P << endl; 212 | 213 | } 214 | } 215 | // Load p files strecha style 216 | else if ( !inputFiles.p_folder.empty () ) { 217 | numCameras = inputFiles.img_filenames.size (); 218 | params.cameras.resize ( numCameras ); 219 | for ( size_t i = 0; i < numCameras; i++ ) { 220 | readPFileStrechaPmvs ( inputFiles.p_folder + inputFiles.img_filenames[i] + ".P",params.cameras[i].P ); 221 | size_t found = inputFiles.img_filenames[i].find_last_of ( "." ); 222 | //params.cameras[i].id = atoi ( inputFiles.img_filenames[i].substr ( 0,found ).c_str () ); 223 | params.cameras[i].id = inputFiles.img_filenames[i].substr ( 0,found ).c_str (); 224 | // params.cameras[i].P = KMaros * params.cameras[i].P; 225 | 226 | //cout << params.cameras[i].P << endl; 227 | } 228 | 229 | } 230 | // Load P matrix for middlebury format 231 | if ( !inputFiles.krt_file.empty () ) { 232 | numCameras = inputFiles.img_filenames.size (); 233 | params.cameras.resize ( numCameras ); 234 | //cout << "Num Cameras " << numCameras << endl; 235 | readKRtFileMiddlebury ( inputFiles.krt_file, params.cameras, inputFiles); 236 | } 237 | 238 | 239 | /*cout << "KMaros is" << endl;*/ 240 | /*cout << KMaros << endl;*/ 241 | 242 | 243 | // decompose projection matrices into K, R and t 244 | vector > K ( numCameras ); 245 | vector > R ( numCameras ); 246 | vector > T ( numCameras ); 247 | 248 | vector > C ( numCameras ); 249 | vector > t ( numCameras ); 250 | 251 | for ( size_t i = 0; i < numCameras; i++ ) { 252 | decomposeProjectionMatrix ( params.cameras[i].P,K[i],R[i],T[i] ); 253 | 254 | //cout << "K: " << K[i] << endl; 255 | //cout << "R: " << R[i] << endl; 256 | //cout << "T: " << T[i] << endl; 257 | 258 | // get 3-dimensional translation vectors and camera center (divide by augmented component) 259 | C[i] = T[i] ( Range ( 0,3 ),Range ( 0,1 ) ) / T[i] ( 3,0 ); 260 | t[i] = -R[i] * C[i]; 261 | 262 | //cout << "C: " << C[i] << endl; 263 | //cout << "t: " << t[i] << endl; 264 | } 265 | 266 | // transform projection matrices (R and t part) so that P1 = K [I | 0] 267 | //computeTranslatedProjectionMatrices(R1, R2, t1, t2, params); 268 | Mat_ transform = Mat::eye ( 4,4 ,CV_32F); 269 | 270 | if ( transformP ) 271 | transform = getTransformationReferenceToOrigin ( R[0],t[0] ); 272 | /*cout << "transform is " << transform << endl;*/ 273 | params.cameras[0].reference = true; 274 | params.idRef = 0; 275 | //cout << "K before scale is" << endl; 276 | //cout << K[0] << endl; 277 | 278 | //assuming K is the same for all cameras 279 | params.K = scaleK ( K[0],scaleFactor ); 280 | params.K_inv = params.K.inv (); 281 | // get focal length from calibration matrix 282 | params.f = params.K ( 0,0 ); 283 | 284 | for ( size_t i = 0; i < numCameras; i++ ) { 285 | params.cameras[i].K = scaleK(K[i],scaleFactor); 286 | params.cameras[i].K_inv = params.cameras[i].K.inv ( ); 287 | //params.cameras[i].f = params.cameras[i].K(0,0); 288 | 289 | if ( !inputFiles.bounding_folder.empty () ) { 290 | Vec3f ptBL, ptTR; 291 | readBoundingVolume ( inputFiles.bounding_folder + inputFiles.img_filenames[i] + ".bounding",ptBL,ptTR ); 292 | 293 | cout << "d1: " << getDepth ( ptBL,params.cameras[i].P ) < tmpK = params.K.t (); 309 | //copyOpencvMatToFloatArray ( params.K, &cpc.K); 310 | //copyOpencvMatToFloatArray ( params.K_inv, &cpc.K_inv); 311 | copyOpencvMatToFloatArray ( params.cameras[i].K, &cpc.cameras[i].K); 312 | copyOpencvMatToFloatArray ( params.cameras[i].K_inv, &cpc.cameras[i].K_inv); 313 | copyOpencvMatToFloatArray ( params.cameras[i].R_orig_inv, &cpc.cameras[i].R_orig_inv); 314 | cpc.cameras[i].fy = params.K(1,1); 315 | cpc.f = params.K(0,0); 316 | cpc.cameras[i].f = params.K(0,0); 317 | cpc.cameras[i].fx = params.K(0,0); 318 | cpc.cameras[i].fy = params.K(1,1); 319 | cpc.cameras[i].baseline = params.cameras[i].baseline; 320 | cpc.cameras[i].reference = params.cameras[i].reference; 321 | 322 | /*params.cameras[i].alpha = params.K ( 0,0 )/params.K(1,1);*/ 323 | cpc.cameras[i].alpha = params.K ( 0,0 )/params.K(1,1); 324 | // Copy data to cuda structure 325 | copyOpencvMatToFloatArray ( params.cameras[i].P, &cpc.cameras[i].P); 326 | copyOpencvMatToFloatArray ( params.cameras[i].P_inv, &cpc.cameras[i].P_inv); 327 | copyOpencvMatToFloatArray ( params.cameras[i].M_inv, &cpc.cameras[i].M_inv); 328 | //copyOpencvMatToFloatArray ( params.K, &cpc.cameras[i].K); 329 | //copyOpencvMatToFloatArray ( params.K_inv, &cpc.cameras[i].K_inv); 330 | copyOpencvMatToFloatArray ( params.cameras[i].K, &cpc.cameras[i].K); 331 | copyOpencvMatToFloatArray ( params.cameras[i].K_inv, &cpc.cameras[i].K_inv); 332 | copyOpencvMatToFloatArray ( params.cameras[i].R, &cpc.cameras[i].R); 333 | /*copyOpencvMatToFloatArray ( params.cameras[i].t, &cpc.cameras[i].t);*/ 334 | /*copyOpencvVecToFloatArray ( params.cameras[i].C, cpc.cameras[i].C);*/ 335 | copyOpencvVecToFloat4 ( params.cameras[i].C, &cpc.cameras[i].C4); 336 | cpc.cameras[i].t4.x = params.cameras[i].t(0); 337 | cpc.cameras[i].t4.y = params.cameras[i].t(1); 338 | cpc.cameras[i].t4.z = params.cameras[i].t(2); 339 | Mat_ tmp = params.cameras[i].P.col(3); 340 | /*cpc.cameras[i].P_col3[0] = tmp(0,0);*/ 341 | /*cpc.cameras[i].P_col3[1] = tmp(1,0);*/ 342 | /*cpc.cameras[i].P_col3[2] = tmp(2,0);*/ 343 | cpc.cameras[i].P_col34.x = tmp(0,0); 344 | cpc.cameras[i].P_col34.y = tmp(1,0); 345 | cpc.cameras[i].P_col34.z = tmp(2,0); 346 | //cout << params.cameras[i].P << endl; 347 | //cout << endl; 348 | 349 | Mat_ tmpKinv = params.K_inv.t (); 350 | } 351 | 352 | return params; 353 | } 354 | 355 | -------------------------------------------------------------------------------- /cameraparameters.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "camera.h" 4 | #include "managed.h" 5 | #include "config.h" 6 | 7 | class __align__(128) CameraParameters_cu : public Managed { 8 | public: 9 | float f; // used only for dummy depth -> disparity conversion 10 | bool rectified; 11 | Camera_cu cameras[MAX_IMAGES]; 12 | int idRef; 13 | int cols; 14 | int rows; 15 | int* viewSelectionSubset; 16 | int viewSelectionSubsetNumber; 17 | CameraParameters_cu() 18 | { 19 | rectified = true; 20 | idRef = 0; 21 | cudaMallocManaged (&viewSelectionSubset, sizeof(int) * MAX_IMAGES); 22 | } 23 | ~CameraParameters_cu() 24 | { 25 | cudaFree (viewSelectionSubset); 26 | } 27 | }; 28 | -------------------------------------------------------------------------------- /config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #define MAX_IMAGES 512 3 | 4 | /*#define SHARED_HARDCODED*/ 5 | #ifdef SHARED_HARDCODED 6 | #define BLOCKSIZE_W 15 + 1 // +1 for the gradient computation 7 | #define BLOCKSIZE_H 15 + 1 // +1 for the gradient computation 8 | #define WIN_RADIUS_W (BLOCKSIZE_W) / (2) 9 | #define WIN_RADIUS_H (BLOCKSIZE_H) / (2) 10 | 11 | #define BLOCK_W 32 12 | #define BLOCK_H (BLOCK_W/2) 13 | #define TILE_W BLOCK_W 14 | #define TILE_H BLOCK_H * 2 15 | #define TILE_SIZE TILE_W * TILE_H 16 | #define SHARED_SIZE_W (TILE_W + WIN_RADIUS_W * 2) 17 | #define SHARED_SIZE_H (TILE_H + WIN_RADIUS_H * 2) 18 | #define SHARED_SIZE (SHARED_SIZE_W * SHARED_SIZE_H) 19 | #endif 20 | 21 | #define REFERENCE 0 22 | #define MAXCOST 1000.0f 23 | 24 | #define FORCEINLINE_GIPUMA __forceinline__ 25 | //#define FORCEINLINE_GIPUMA 26 | 27 | #define pow2(x) ((x)*(x)) 28 | #define pow3(x) ((x)*(x)*(x)) 29 | #define pow4(x) ((x)*(x)*(x)*(x)) 30 | #define get_pow2_norm(x,y) (pow2(x)+pow2(y)) 31 | #define get_normf(x,y) (sqrtf((pow2(x)+pow2(y)))) 32 | #define get_normf3(v) (sqrtf((pow2(v.x)+pow2(v.y) + pow2(v.z)))) 33 | #define get_pow2_normf3(v) ((pow2(v.x)+pow2(v.y) + pow2(v.z))) 34 | 35 | // Vector operations 36 | #define dot4(v0,v1) v0.x * v1.x + \ 37 | v0.y * v1.y + \ 38 | v0.z * v1.z 39 | #define mul4(v,k) \ 40 | v->x = v->x * k; \ 41 | v->y = v->y * k; \ 42 | v->z = v->z * k; 43 | 44 | #define vecdiv4(v,k) \ 45 | v->x = v->x / k; \ 46 | v->y = v->y / k; \ 47 | v->z = v->z / k; 48 | 49 | #define vecdiv42(v,k) \ 50 | v.x = v.x / k; \ 51 | v.y = v.y / k; \ 52 | v.z = v.z / k; 53 | 54 | 55 | #define vecdiv(v,k) \ 56 | v[0] = v[0] / k; \ 57 | v[1] = v[1] / k; \ 58 | v[2] = v[2] / k; 59 | 60 | #define get_pow2_normv3(x,y) (pow2(x)+pow2(y)) 61 | 62 | #define negate(v) mul(v,-1.0f) 63 | #define negate4(v) v->x = -v->x; \ 64 | v->y = -v->y; \ 65 | v->z = -v->z; 66 | 67 | #define sub(v0,v1) v0.x = v0.x - v1.x; \ 68 | v0.y = v0.y - v1.y; \ 69 | v0.z = v0.z - v1.z; 70 | #define subout(v0,v1,vout) vout.x = v0.x - v1.x; \ 71 | vout.y = v0.y - v1.y; \ 72 | vout.z = v0.z - v1.z; 73 | 74 | #define outer_product(v0,v1, out) \ 75 | out[0] = v0[0] * v1[0]; \ 76 | out[1] = v0[0] * v1[1]; \ 77 | out[2] = v0[0] * v1[2]; \ 78 | out[3] = v0[1] * v1[0]; \ 79 | out[4] = v0[1] * v1[1]; \ 80 | out[5] = v0[1] * v1[2]; \ 81 | out[6] = v0[2] * v1[0]; \ 82 | out[7] = v0[2] * v1[1]; \ 83 | out[8] = v0[2] * v1[2]; 84 | 85 | #define outer_product4(v0,v1, out) \ 86 | out[0] = v0.x * v1.x; \ 87 | out[1] = v0.x * v1.y; \ 88 | out[2] = v0.x * v1.z; \ 89 | out[3] = v0.y * v1.x; \ 90 | out[4] = v0.y * v1.y; \ 91 | out[5] = v0.y * v1.z; \ 92 | out[6] = v0.z * v1.x; \ 93 | out[7] = v0.z * v1.y; \ 94 | out[8] = v0.z * v1.z; 95 | // Matrix operations 96 | #define matadd(m,k) m[0] = m[0] + k; \ 97 | m[1] = m[1] + k; \ 98 | m[2] = m[2] + k; \ 99 | m[3] = m[3] + k; \ 100 | m[4] = m[4] + k; \ 101 | m[5] = m[5] + k; \ 102 | m[6] = m[6] + k; \ 103 | m[7] = m[7] + k; \ 104 | m[8] = m[8] + k; 105 | 106 | #define matsub(m,k) m[0] = m[0] - k; \ 107 | m[1] = m[1] - k; \ 108 | m[2] = m[2] - k; \ 109 | m[3] = m[3] - k; \ 110 | m[4] = m[4] - k; \ 111 | m[5] = m[5] - k; \ 112 | m[6] = m[6] - k; \ 113 | m[7] = m[7] - k; \ 114 | m[8] = m[8] - k; 115 | 116 | #define matmatsub(m0, m1) \ 117 | m0[0] = m0[0] - m1[0]; \ 118 | m0[1] = m0[1] - m1[1]; \ 119 | m0[2] = m0[2] - m1[2]; \ 120 | m0[3] = m0[3] - m1[3]; \ 121 | m0[4] = m0[4] - m1[4]; \ 122 | m0[5] = m0[5] - m1[5]; \ 123 | m0[6] = m0[6] - m1[6]; \ 124 | m0[7] = m0[7] - m1[7]; \ 125 | m0[8] = m0[8] - m1[8]; 126 | 127 | #define matmatsub2(m0, m1) \ 128 | m1[0] = m0[0] - m1[0]; \ 129 | m1[1] = m0[1] - m1[1]; \ 130 | m1[2] = m0[2] - m1[2]; \ 131 | m1[3] = m0[3] - m1[3]; \ 132 | m1[4] = m0[4] - m1[4]; \ 133 | m1[5] = m0[5] - m1[5]; \ 134 | m1[6] = m0[6] - m1[6]; \ 135 | m1[7] = m0[7] - m1[7]; \ 136 | m1[8] = m0[8] - m1[8]; 137 | 138 | 139 | #define matdivide(m,k) \ 140 | m[0] = m[0] / k; \ 141 | m[1] = m[1] / k; \ 142 | m[2] = m[2] / k; \ 143 | m[3] = m[3] / k; \ 144 | m[4] = m[4] / k; \ 145 | m[5] = m[5] / k; \ 146 | m[6] = m[6] / k; \ 147 | m[7] = m[7] / k; \ 148 | m[8] = m[8] / k; 149 | 150 | #define matvecmul4noz(m, v, out) \ 151 | out->x = \ 152 | m [0] * v.x + \ 153 | m [1] * v.y + \ 154 | m [2];\ 155 | out->y = \ 156 | m [3] * v.x + \ 157 | m [4] * v.y + \ 158 | m [5]; \ 159 | out->z = \ 160 | m [6] * v.x + \ 161 | m [7] * v.y + \ 162 | m [8]; 163 | 164 | #define matvecmul4(m, v, out) \ 165 | out->x = \ 166 | m [0] * v.x + \ 167 | m [1] * v.y + \ 168 | m [2] * v.z; \ 169 | out->y = \ 170 | m [3] * v.x + \ 171 | m [4] * v.y + \ 172 | m [5] * v.z; \ 173 | out->z = \ 174 | m [6] * v.x + \ 175 | m [7] * v.y + \ 176 | m [8] * v.z; 177 | #define matvecmul4div(m, v, out,d) \ 178 | out->x = \ 179 | (m [0] * v.x + \ 180 | m [1] * v.y + \ 181 | m [2] * v.z)/d; \ 182 | out->y = \ 183 | (m [3] * v.x + \ 184 | m [4] * v.y + \ 185 | m [5] * v.z)/d; \ 186 | out->z = \ 187 | (m [6] * v.x + \ 188 | m [7] * v.y + \ 189 | m [8] * v.z)/d; 190 | 191 | #define matvecmul(m, v, out) \ 192 | out[0] = \ 193 | m [0] * v[0] + \ 194 | m [1] * v[1] + \ 195 | m [2] * v[2]; \ 196 | out[1] = \ 197 | m [3] * v[0] + \ 198 | m [4] * v[1] + \ 199 | m [5] * v[2]; \ 200 | out[2] = \ 201 | m [6] * v[0] + \ 202 | m [7] * v[1] + \ 203 | m [8] * v[2]; 204 | 205 | #define matmul_cu(m0, m1, out) \ 206 | out[0] = \ 207 | m0 [0] * m1[0] + \ 208 | m0 [1] * m1[0+3] + \ 209 | m0 [2] * m1[0+6]; \ 210 | out[1] = \ 211 | m0 [0] * m1[1] + \ 212 | m0 [1] * m1[1+3] + \ 213 | m0 [2] * m1[1+6]; \ 214 | out[2] = \ 215 | m0 [0] * m1[2] + \ 216 | m0 [1] * m1[2+3] + \ 217 | m0 [2] * m1[2+6]; \ 218 | out[3] = \ 219 | m0 [3] * m1[0] + \ 220 | m0 [4] * m1[0+3] + \ 221 | m0 [5] * m1[0+6]; \ 222 | out[4] = \ 223 | m0 [3] * m1[1] + \ 224 | m0 [4] * m1[1+3] + \ 225 | m0 [5] * m1[1+6]; \ 226 | out[5] = \ 227 | m0 [3] * m1[2] + \ 228 | m0 [4] * m1[2+3] + \ 229 | m0 [5] * m1[2+6]; \ 230 | out[6] = \ 231 | m0 [6] * m1[0] + \ 232 | m0 [7] * m1[0+3] + \ 233 | m0 [8] * m1[0+6]; \ 234 | out[7] = \ 235 | m0 [6] * m1[1] + \ 236 | m0 [7] * m1[1+3] + \ 237 | m0 [8] * m1[1+6]; \ 238 | out[8] = \ 239 | m0 [6] * m1[2] + \ 240 | m0 [7] * m1[2+3] + \ 241 | m0 [8] * m1[2+6]; 242 | 243 | // texture utils 244 | 245 | #define texat(tex,x, y) \ 246 | tex2D(tex, x+0.5f, y+0.5f) 247 | #define texatf4(tex,x, y) \ 248 | tex2D(tex, x+0.5f, y+0.5f) 249 | 250 | #define texatpt(tex,pt) \ 251 | texat(tex, pt[0], pt[1]) 252 | #define texatpt4(tex,pt) \ 253 | texat(tex, pt.x, pt.y) 254 | #define texatptf4(tex,pt) \ 255 | texatf4(tex, pt.x, pt.y) 256 | 257 | #define colorDifferenceL1_macro(x,y) \ 258 | fabsf(x-y) 259 | 260 | #define print_vector(v,string) \ 261 | printf("%s is \tnp.array([%e, %e ,%e])\n", string, v[0],v[1],v[2]); 262 | 263 | #define print_vector4(v,string) \ 264 | printf("%s is \tnp.array([%f, %f ,%f])\n", string, v.x,v.y,v.z); 265 | 266 | #define print_matrix(m,string) \ 267 | printf("%s is [[%.4e, %.4e, %.4e], \n\t [%.4e, %.4e, %.4e], \n\t [%.4e, %.4e, %.4e]]\n", string, m[0],m[1],m[2],m[3],m[4],m[5],m[6],m[7],m[8]); 268 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_001_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2607.429996 -3.844898 1498.178098 -533936.661373 2 | -192.076910 2862.552532 681.798177 23434.686572 3 | -0.241605 -0.030951 0.969881 22.540121 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_001_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2607.429996 -3.844898 1498.178098 -533936.661373 2 | -192.076910 2862.552532 681.798177 23434.686572 3 | -0.241605 -0.030951 0.969881 22.540121 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_001_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2607.429996 -3.844898 1498.178098 -533936.661373 2 | -192.076910 2862.552532 681.798177 23434.686572 3 | -0.241605 -0.030951 0.969881 22.540121 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_002_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1977.784758 -1210.002933 1915.072827 -784204.529312 2 | 976.333235 2626.930526 917.583083 -178022.203917 3 | -0.416183 0.073779 0.906283 71.276252 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_002_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1977.784758 -1210.002933 1915.072827 -784204.529312 2 | 976.333235 2626.930526 917.583083 -178022.203917 3 | -0.416183 0.073779 0.906283 71.276252 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_002_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1977.784758 -1210.002933 1915.072827 -784204.529312 2 | 976.333235 2626.930526 917.583083 -178022.203917 3 | -0.416183 0.073779 0.906283 71.276252 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_003_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 805.625978 -1995.776821 2100.258376 -861180.861253 2 | 1844.712809 1881.939141 1323.362766 -479716.738619 3 | -0.509301 0.248881 0.823814 129.344349 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_003_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 805.625978 -1995.776821 2100.258376 -861180.861253 2 | 1844.712809 1881.939141 1323.362766 -479716.738619 3 | -0.509301 0.248881 0.823814 129.344349 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_003_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 805.625978 -1995.776821 2100.258376 -861180.861253 2 | 1844.712809 1881.939141 1323.362766 -479716.738619 3 | -0.509301 0.248881 0.823814 129.344349 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_004_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -608.157075 -2157.350493 2004.801089 -744310.243134 2 | 2190.032357 817.079895 1797.800882 -805666.997926 3 | -0.495318 0.449091 0.743625 181.594427 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_004_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -608.157075 -2157.350493 2004.801089 -744310.243134 2 | 2190.032357 817.079895 1797.800882 -805666.997926 3 | -0.495318 0.449091 0.743625 181.594427 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_004_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -608.157075 -2157.350493 2004.801089 -744310.243134 2 | 2190.032357 817.079895 1797.800882 -805666.997926 3 | -0.495318 0.449091 0.743625 181.594427 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_005_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1890.101654 -1655.282615 1652.512870 -460952.775022 2 | 1923.835795 -292.676059 2215.659236 -1070542.481635 3 | -0.376647 0.619943 0.688337 213.217451 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_005_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1890.101654 -1655.282615 1652.512870 -460952.775022 2 | 1923.835795 -292.676059 2215.659236 -1070542.481635 3 | -0.376647 0.619943 0.688337 213.217451 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_005_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1890.101654 -1655.282615 1652.512870 -460952.775022 2 | 1923.835795 -292.676059 2215.659236 -1070542.481635 3 | -0.376647 0.619943 0.688337 213.217451 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_006_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2130.802557 -1542.030106 1457.761021 -330542.222978 2 | 1511.647738 -25.829597 2531.837917 -1243548.668365 3 | -0.497523 0.672091 0.548420 305.637292 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_006_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -2130.802557 -1542.030106 1457.761021 -330542.222978 2 | 1511.647738 -25.829597 2531.837917 -1243548.668365 3 | -0.497523 0.672091 0.548420 305.637292 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_006_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2130.802557 -1542.030106 1457.761021 -330542.222978 2 | 1511.647738 -25.829597 2531.837917 -1243548.668365 3 | -0.497523 0.672091 0.548420 305.637292 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_007_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1331.708123 -2046.856231 1755.043198 -555980.940205 2 | 1737.162697 598.490038 2306.517880 -1103917.042313 3 | -0.615533 0.512011 0.599136 276.695442 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_007_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1331.708123 -2046.856231 1755.043198 -555980.940205 2 | 1737.162697 598.490038 2306.517880 -1103917.042313 3 | -0.615533 0.512011 0.599136 276.695442 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_007_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1331.708123 -2046.856231 1755.043198 -555980.940205 2 | 1737.162697 598.490038 2306.517880 -1103917.042313 3 | -0.615533 0.512011 0.599136 276.695442 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_008_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -376.073604 -2256.711283 1951.682969 -721980.349189 2 | 1721.494757 1252.167622 2040.706088 -928229.029070 3 | -0.669067 0.324824 0.668460 233.091458 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_008_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -376.073604 -2256.711283 1951.682969 -721980.349189 2 | 1721.494757 1252.167622 2040.706088 -928229.029070 3 | -0.669067 0.324824 0.668460 233.091458 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_008_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -376.073604 -2256.711283 1951.682969 -721980.349189 2 | 1721.494757 1252.167622 2040.706088 -928229.029070 3 | -0.669067 0.324824 0.668460 233.091458 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_009_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 620.912402 -2140.893464 2018.486201 -803499.445275 2 | 1465.199321 1852.029366 1766.105169 -737777.600453 3 | -0.648986 0.133444 0.749006 179.300202 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_009_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 620.912402 -2140.893464 2018.486201 -803499.445275 2 | 1465.199321 1852.029366 1766.105169 -737777.600453 3 | -0.648986 0.133444 0.749006 179.300202 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_009_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 620.912402 -2140.893464 2018.486201 -803499.445275 2 | 1465.199321 1852.029366 1766.105169 -737777.600453 3 | -0.648986 0.133444 0.749006 179.300202 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_010_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1524.222238 -1711.483328 1947.001533 -792239.428516 2 | 999.681914 2321.140245 1519.504302 -556285.742082 3 | -0.558379 -0.035388 0.828831 123.151441 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_010_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1524.222238 -1711.483328 1947.001533 -792239.428516 2 | 999.681914 2321.140245 1519.504302 -556285.742082 3 | -0.558379 -0.035388 0.828831 123.151441 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_010_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1524.222238 -1711.483328 1947.001533 -792239.428516 2 | 999.681914 2321.140245 1519.504302 -556285.742082 3 | -0.558379 -0.035388 0.828831 123.151441 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_011_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2222.418058 -1022.685148 1748.775757 -688522.485294 2 | 382.189565 2604.600434 1328.885626 -406724.643764 3 | -0.409915 -0.160296 0.897928 71.838020 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_011_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2222.418058 -1022.685148 1748.775757 -688522.485294 2 | 382.189565 2604.600434 1328.885626 -406724.643764 3 | -0.409915 -0.160296 0.897928 71.838020 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_011_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2222.418058 -1022.685148 1748.775757 -688522.485294 2 | 382.189565 2604.600434 1328.885626 -406724.643764 3 | -0.409915 -0.160296 0.897928 71.838020 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_012_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2617.765103 -465.291527 1405.010051 -483933.879131 2 | -312.418600 2368.248003 1729.087998 -625971.516979 3 | -0.231706 -0.412418 0.881036 69.791221 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_012_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2617.765103 -465.291527 1405.010051 -483933.879131 2 | -312.418600 2368.248003 1729.087998 -625971.516979 3 | -0.231706 -0.412418 0.881036 69.791221 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_012_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2617.765103 -465.291527 1405.010051 -483933.879131 2 | -312.418600 2368.248003 1729.087998 -625971.516979 3 | -0.231706 -0.412418 0.881036 69.791221 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_013_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2250.931607 -1139.968385 1636.160922 -623291.342725 2 | 110.908760 2340.924859 1789.893668 -682096.413504 3 | -0.420739 -0.354197 0.835179 107.330908 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_013_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2250.931607 -1139.968385 1636.160922 -623291.342725 2 | 110.908760 2340.924859 1789.893668 -682096.413504 3 | -0.420739 -0.354197 0.835179 107.330908 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_013_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2250.931607 -1139.968385 1636.160922 -623291.342725 2 | 110.908760 2340.924859 1789.893668 -682096.413504 3 | -0.420739 -0.354197 0.835179 107.330908 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_014_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1702.146029 -1702.297629 1802.255603 -711268.253631 2 | 503.172114 2205.963703 1891.161352 -764413.983938 3 | -0.583649 -0.248866 0.772930 154.682734 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_014_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1702.146029 -1702.297629 1802.255603 -711268.253631 2 | 503.172114 2205.963703 1891.161352 -764413.983938 3 | -0.583649 -0.248866 0.772930 154.682734 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_014_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1702.146029 -1702.297629 1802.255603 -711268.253631 2 | 503.172114 2205.963703 1891.161352 -764413.983938 3 | -0.583649 -0.248866 0.772930 154.682734 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_015_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1015.354744 -2109.600372 1887.295578 -740317.688958 2 | 834.033581 1973.000760 2026.722792 -866772.108267 3 | -0.707308 -0.105288 0.699021 208.194544 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_015_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1015.354744 -2109.600372 1887.295578 -740317.688958 2 | 834.033581 1973.000760 2026.722792 -866772.108267 3 | -0.707308 -0.105288 0.699021 208.194544 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_015_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1015.354744 -2109.600372 1887.295578 -740317.688958 2 | 834.033581 1973.000760 2026.722792 -866772.108267 3 | -0.707308 -0.105288 0.699021 208.194544 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_016_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 243.389303 -2328.874543 1886.888601 -712137.352409 2 | 1078.804521 1662.885946 2183.332413 -979452.169804 3 | -0.782277 0.066583 0.619362 263.654146 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_016_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 243.389303 -2328.874543 1886.888601 -712137.352409 2 | 1078.804521 1662.885946 2183.332413 -979452.169804 3 | -0.782277 0.066583 0.619362 263.654146 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_016_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 243.389303 -2328.874543 1886.888601 -712137.352409 2 | 1078.804521 1662.885946 2183.332413 -979452.169804 3 | -0.782277 0.066583 0.619362 263.654146 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_017_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -557.263111 -2342.117711 1801.995015 -624881.535543 2 | 1224.342570 1297.622317 2348.001466 -1093513.811828 3 | -0.801624 0.255200 0.540622 316.202766 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_017_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -557.263111 -2342.117711 1801.995015 -624881.535543 2 | 1224.342570 1297.622317 2348.001466 -1093513.811828 3 | -0.801624 0.255200 0.540622 316.202766 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_017_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -557.263111 -2342.117711 1801.995015 -624881.535543 2 | 1224.342570 1297.622317 2348.001466 -1093513.811828 3 | -0.801624 0.255200 0.540622 316.202766 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_018_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1316.899404 -2152.232105 1636.128512 -486400.170161 2 | 1256.382378 902.890324 2510.426592 -1201374.745107 3 | -0.763974 0.442191 0.469906 361.453134 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_018_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1316.899404 -2152.232105 1636.128512 -486400.170161 2 | 1256.382378 902.890324 2510.426592 -1201374.745107 3 | -0.763974 0.442191 0.469906 361.453134 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_018_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1316.899404 -2152.232105 1636.128512 -486400.170161 2 | 1256.382378 902.890324 2510.426592 -1201374.745107 3 | -0.763974 0.442191 0.469906 361.453134 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_019_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1982.901337 -1772.297111 1403.676894 -307472.101267 2 | 1168.503313 510.931149 2658.852884 -1295463.419475 3 | -0.673570 0.614465 0.410775 396.976321 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_019_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1982.901337 -1772.297111 1403.676894 -307472.101267 2 | 1168.503313 510.931149 2658.852884 -1295463.419475 3 | -0.673570 0.614465 0.410775 396.976321 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_019_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1982.901337 -1772.297111 1403.676894 -307472.101267 2 | 1168.503313 510.931149 2658.852884 -1295463.419475 3 | -0.673570 0.614465 0.410775 396.976321 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_020_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2373.739147 -1514.796229 1055.461241 -72804.901683 2 | 610.964532 662.547611 2807.793136 -1361296.026140 3 | -0.693790 0.689242 0.208810 523.429556 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_020_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -2373.739147 -1514.796229 1055.461241 -72804.901683 2 | 610.964532 662.547611 2807.793136 -1361296.026140 3 | -0.693790 0.689242 0.208810 523.429556 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_020_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2373.739147 -1514.796229 1055.461241 -72804.901683 2 | 610.964532 662.547611 2807.793136 -1361296.026140 3 | -0.693790 0.689242 0.208810 523.429556 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_021_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1888.756435 -1951.804329 1290.853427 -245197.474029 2 | 690.442392 876.128780 2729.768663 -1312852.496641 3 | -0.806467 0.530859 0.260384 493.822219 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_021_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1888.756435 -1951.804329 1290.853427 -245197.474029 2 | 690.442392 876.128780 2729.768663 -1312852.496641 3 | -0.806467 0.530859 0.260384 493.822219 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_021_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1888.756435 -1951.804329 1290.853427 -245197.474029 2 | 690.442392 876.128780 2729.768663 -1312852.496641 3 | -0.806467 0.530859 0.260384 493.822219 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_022_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1301.490655 -2266.858005 1486.849166 -396872.273316 2 | 713.400529 1098.516027 2642.020347 -1255970.275996 3 | -0.877465 0.353366 0.324326 454.406028 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_022_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1301.490655 -2266.858005 1486.849166 -396872.273316 2 | 713.400529 1098.516027 2642.020347 -1255970.275996 3 | -0.877465 0.353366 0.324326 454.406028 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_022_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1301.490655 -2266.858005 1486.849166 -396872.273316 2 | 713.400529 1098.516027 2642.020347 -1255970.275996 3 | -0.877465 0.353366 0.324326 454.406028 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_023_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -646.679569 -2440.901717 1633.109894 -517707.418665 2 | 677.905495 1317.475719 2549.637457 -1194084.306986 3 | -0.902711 0.167153 0.396449 407.881500 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_023_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -646.679569 -2440.901717 1633.109894 -517707.418665 2 | 677.905495 1317.475719 2549.637457 -1194084.306986 3 | -0.902711 0.167153 0.396449 407.881500 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_023_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -646.679569 -2440.901717 1633.109894 -517707.418665 2 | 677.905495 1317.475719 2549.637457 -1194084.306986 3 | -0.902711 0.167153 0.396449 407.881500 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_024_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 40.599393 -2465.091274 1721.894387 -601455.414883 2 | 586.411244 1519.895550 2458.045700 -1130783.200574 3 | -0.880821 -0.017980 0.473108 356.302674 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_024_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 40.599393 -2465.091274 1721.894387 -601455.414883 2 | 586.411244 1519.895550 2458.045700 -1130783.200574 3 | -0.880821 -0.017980 0.473108 356.302674 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_024_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 40.599393 -2465.091274 1721.894387 -601455.414883 2 | 586.411244 1519.895550 2458.045700 -1130783.200574 3 | -0.880821 -0.017980 0.473108 356.302674 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_025_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 724.684566 -2336.701033 1748.686406 -645300.968219 2 | 452.358617 1695.665922 2369.818148 -1067352.313091 3 | -0.811477 -0.190525 0.552454 301.313285 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_025_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 724.684566 -2336.701033 1748.686406 -645300.968219 2 | 452.358617 1695.665922 2369.818148 -1067352.313091 3 | -0.811477 -0.190525 0.552454 301.313285 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_025_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 724.684566 -2336.701033 1748.686406 -645300.968219 2 | 452.358617 1695.665922 2369.818148 -1067352.313091 3 | -0.811477 -0.190525 0.552454 301.313285 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_026_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1367.253543 -2061.126438 1710.444134 -647330.630753 2 | 274.722438 1836.212339 2291.026215 -1008271.823123 3 | -0.699031 -0.341897 0.628062 247.354456 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_026_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1367.253543 -2061.126438 1710.444134 -647330.630753 2 | 274.722438 1836.212339 2291.026215 -1008271.823123 3 | -0.699031 -0.341897 0.628062 247.354456 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_026_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1367.253543 -2061.126438 1710.444134 -647330.630753 2 | 274.722438 1836.212339 2291.026215 -1008271.823123 3 | -0.699031 -0.341897 0.628062 247.354456 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_027_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1923.373183 -1658.256573 1610.609921 -602243.429236 2 | 64.492475 1931.138026 2227.666029 -957990.721882 3 | -0.551754 -0.461983 0.694362 197.826415 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_027_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1923.373183 -1658.256573 1610.609921 -602243.429236 2 | 64.492475 1931.138026 2227.666029 -957990.721882 3 | -0.551754 -0.461983 0.694362 197.826415 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_027_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1923.373183 -1658.256573 1610.609921 -602243.429236 2 | 64.492475 1931.138026 2227.666029 -957990.721882 3 | -0.551754 -0.461983 0.694362 197.826415 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_028_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2368.215050 -1148.231485 1454.773356 -515695.702355 2 | -167.012249 1976.426959 2182.153220 -919213.033519 3 | -0.376764 -0.545328 0.748777 155.156007 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_028_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2368.215050 -1148.231485 1454.773356 -515695.702355 2 | -167.012249 1976.426959 2182.153220 -919213.033519 3 | -0.376764 -0.545328 0.748777 155.156007 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_028_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2368.215050 -1148.231485 1454.773356 -515695.702355 2 | -167.012249 1976.426959 2182.153220 -919213.033519 3 | -0.376764 -0.545328 0.748777 155.156007 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_029_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2648.430054 -853.832664 1140.189288 -328933.023593 2 | -403.982410 1498.464013 2507.459492 -1117917.442654 3 | -0.205027 -0.731082 0.650755 204.396614 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_029_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2648.430054 -853.832664 1140.189288 -328933.023593 2 | -403.982410 1498.464013 2507.459492 -1117917.442654 3 | -0.205027 -0.731082 0.650755 204.396614 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_029_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2648.430054 -853.832664 1140.189288 -328933.023593 2 | -403.982410 1498.464013 2507.459492 -1117917.442654 3 | -0.205027 -0.731082 0.650755 204.396614 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_030_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2329.273350 -1374.897541 1314.300573 -433183.823762 2 | -308.263689 1510.262439 2513.967015 -1125302.441140 3 | -0.395935 -0.686363 0.610034 238.638323 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_030_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2329.273350 -1374.897541 1314.300573 -433183.823762 2 | -308.263689 1510.262439 2513.967015 -1125302.441140 3 | -0.395935 -0.686363 0.610034 238.638323 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_030_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2329.273350 -1374.897541 1314.300573 -433183.823762 2 | -308.263689 1510.262439 2513.967015 -1125302.441140 3 | -0.395935 -0.686363 0.610034 238.638323 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_031_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1900.552662 -1825.934941 1448.138374 -505371.826032 2 | -213.672121 1503.349850 2527.890968 -1138004.014866 3 | -0.570899 -0.604159 0.555937 281.106643 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_031_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1900.552662 -1825.934941 1448.138374 -505371.826032 2 | -213.672121 1503.349850 2527.890968 -1138004.014866 3 | -0.570899 -0.604159 0.555937 281.106643 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_031_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1900.552662 -1825.934941 1448.138374 -505371.826032 2 | -213.672121 1503.349850 2527.890968 -1138004.014866 3 | -0.570899 -0.604159 0.555937 281.106643 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_032_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1382.103881 -2185.885096 1534.580982 -542700.949419 2 | -124.129055 1477.779958 2548.863995 -1155507.421720 3 | -0.721584 -0.488267 0.490827 329.907140 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_032_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1382.103881 -2185.885096 1534.580982 -542700.949419 2 | -124.129055 1477.779958 2548.863995 -1155507.421720 3 | -0.721584 -0.488267 0.490827 329.907140 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_032_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1382.103881 -2185.885096 1534.580982 -542700.949419 2 | -124.129055 1477.779958 2548.863995 -1155507.421720 3 | -0.721584 -0.488267 0.490827 329.907140 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_033_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 798.693916 -2438.153488 1568.674338 -542599.034996 2 | -44.838945 1433.912029 2576.399630 -1176685.647358 3 | -0.840873 -0.344537 0.417405 382.793511 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_033_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 798.693916 -2438.153488 1568.674338 -542599.034996 2 | -44.838945 1433.912029 2576.399630 -1176685.647358 3 | -0.840873 -0.344537 0.417405 382.793511 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_033_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 798.693916 -2438.153488 1568.674338 -542599.034996 2 | -44.838945 1433.912029 2576.399630 -1176685.647358 3 | -0.840873 -0.344537 0.417405 382.793511 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_034_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 176.214340 -2571.639202 1548.826621 -506274.933127 2 | 21.906037 1374.562727 2608.840111 -1200443.944700 3 | -0.923468 -0.178998 0.339363 437.390029 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_034_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 176.214340 -2571.639202 1548.826621 -506274.933127 2 | 21.906037 1374.562727 2608.840111 -1200443.944700 3 | -0.923468 -0.178998 0.339363 437.390029 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_034_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 176.214340 -2571.639202 1548.826621 -506274.933127 2 | 21.906037 1374.562727 2608.840111 -1200443.944700 3 | -0.923468 -0.178998 0.339363 437.390029 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_035_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -455.639422 -2578.896245 1478.151026 -435397.162119 2 | 77.582603 1304.011367 2643.763338 -1225426.099974 3 | -0.965119 0.001370 0.261809 490.255024 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_035_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -455.639422 -2578.896245 1478.151026 -435397.162119 2 | 77.582603 1304.011367 2643.763338 -1225426.099974 3 | -0.965119 0.001370 0.261809 490.255024 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_035_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -455.639422 -2578.896245 1478.151026 -435397.162119 2 | 77.582603 1304.011367 2643.763338 -1225426.099974 3 | -0.965119 0.001370 0.261809 490.255024 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_036_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1070.239413 -2459.377273 1359.887719 -333637.877058 2 | 116.956405 1223.953920 2680.337160 -1250832.140695 3 | -0.964137 0.188274 0.187063 539.552544 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_036_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1070.239413 -2459.377273 1359.887719 -333637.877058 2 | 116.956405 1223.953920 2680.337160 -1250832.140695 3 | -0.964137 0.188274 0.187063 539.552544 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_036_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1070.239413 -2459.377273 1359.887719 -333637.877058 2 | 116.956405 1223.953920 2680.337160 -1250832.140695 3 | -0.964137 0.188274 0.187063 539.552544 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_037_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1637.716757 -2219.766493 1197.398899 -204461.293348 2 | 134.337309 1137.184109 2717.483226 -1276228.906966 3 | -0.920762 0.371953 0.117677 583.522681 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_037_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1637.716757 -2219.766493 1197.398899 -204461.293348 2 | 134.337309 1137.184109 2717.483226 -1276228.906966 3 | -0.920762 0.371953 0.117677 583.522681 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_037_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1637.716757 -2219.766493 1197.398899 -204461.293348 2 | 134.337309 1137.184109 2717.483226 -1276228.906966 3 | -0.920762 0.371953 0.117677 583.522681 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_038_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2132.142919 -1871.070108 998.151694 -54337.455774 2 | 130.635487 1047.626623 2753.427340 -1300087.249726 3 | -0.836896 0.544341 0.057431 619.986499 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_038_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -2132.142919 -1871.070108 998.151694 -54337.455774 2 | 130.635487 1047.626623 2753.427340 -1300087.249726 3 | -0.836896 0.544341 0.057431 619.986499 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_038_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2132.142919 -1871.070108 998.151694 -54337.455774 2 | 130.635487 1047.626623 2753.427340 -1300087.249726 3 | -0.836896 0.544341 0.057431 619.986499 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_039_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2474.907440 -1599.797588 598.936072 210349.070632 2 | -386.151672 1265.479653 2635.412192 -1200180.859686 3 | -0.770797 0.613276 -0.172521 759.831020 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_039_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -2474.907440 -1599.797588 598.936072 210349.070632 2 | -386.151672 1265.479653 2635.412192 -1200180.859686 3 | -0.770797 0.613276 -0.172521 759.831020 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_039_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2474.907440 -1599.797588 598.936072 210349.070632 2 | -386.151672 1265.479653 2635.412192 -1200180.859686 3 | -0.770797 0.613276 -0.172521 759.831020 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_040_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2084.301850 -2010.349130 810.817954 57222.923061 2 | -422.165344 1248.209387 2638.124151 -1199676.111406 3 | -0.881807 0.455559 -0.121993 730.502806 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_040_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -2084.301850 -2010.349130 810.817954 57222.923061 2 | -422.165344 1248.209387 2638.124151 -1199676.111406 3 | -0.881807 0.455559 -0.121993 730.502806 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_040_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -2084.301850 -2010.349130 810.817954 57222.923061 2 | -422.165344 1248.209387 2638.124151 -1199676.111406 3 | -0.881807 0.455559 -0.121993 730.502806 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_041_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1609.391254 -2336.063115 997.954154 -83211.685632 2 | -452.964474 1223.633976 2644.521198 -1203105.242681 3 | -0.957633 0.281621 -0.060239 692.669269 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_041_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1609.391254 -2336.063115 997.954154 -83211.685632 2 | -452.964474 1223.633976 2644.521198 -1203105.242681 3 | -0.957633 0.281621 -0.060239 692.669269 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_041_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1609.391254 -2336.063115 997.954154 -83211.685632 2 | -452.964474 1223.633976 2644.521198 -1203105.242681 3 | -0.957633 0.281621 -0.060239 692.669269 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_042_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1068.551022 -2563.835042 1152.472201 -204923.261624 2 | -479.238785 1193.754837 2653.531395 -1207831.122811 3 | -0.995146 0.097946 0.009509 648.082116 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_042_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1068.551022 -2563.835042 1152.472201 -204923.261624 2 | -479.238785 1193.754837 2653.531395 -1207831.122811 3 | -0.995146 0.097946 0.009509 648.082116 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_042_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1068.551022 -2563.835042 1152.472201 -204923.261624 2 | -479.238785 1193.754837 2653.531395 -1207831.122811 3 | -0.995146 0.097946 0.009509 648.082116 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_043_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -480.507214 -2683.730823 1268.836186 -306480.177291 2 | -499.578500 1159.506706 2664.941803 -1214196.736115 3 | -0.992413 -0.088895 0.084939 598.230009 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_043_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -480.507214 -2683.730823 1268.836186 -306480.177291 2 | -499.578500 1159.506706 2664.941803 -1214196.736115 3 | -0.992413 -0.088895 0.084939 598.230009 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_043_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -480.507214 -2683.730823 1268.836186 -306480.177291 2 | -499.578500 1159.506706 2664.941803 -1214196.736115 3 | -0.992413 -0.088895 0.084939 598.230009 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_044_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 119.406425 -2688.479389 1342.037354 -376975.483990 2 | -510.059464 1124.547870 2677.906033 -1222741.076072 3 | -0.949822 -0.267266 0.162499 545.451421 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_044_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 119.406425 -2688.479389 1342.037354 -376975.483990 2 | -510.059464 1124.547870 2677.906033 -1222741.076072 3 | -0.949822 -0.267266 0.162499 545.451421 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_044_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 119.406425 -2688.479389 1342.037354 -376975.483990 2 | -510.059464 1124.547870 2677.906033 -1222741.076072 3 | -0.949822 -0.267266 0.162499 545.451421 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_045_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 714.852204 -2580.644280 1368.395048 -416267.023424 2 | -511.182808 1088.625947 2692.496049 -1232554.553856 3 | -0.869117 -0.432578 0.239818 491.404115 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_045_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 714.852204 -2580.644280 1368.395048 -416267.023424 2 | -511.182808 1088.625947 2692.496049 -1232554.553856 3 | -0.869117 -0.432578 0.239818 491.404115 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_045_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 714.852204 -2580.644280 1368.395048 -416267.023424 2 | -511.182808 1088.625947 2692.496049 -1232554.553856 3 | -0.869117 -0.432578 0.239818 491.404115 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_046_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1279.939170 -2364.412796 1347.052869 -423332.215954 2 | -503.990572 1054.163581 2707.523211 -1242815.948552 3 | -0.753733 -0.577708 0.313273 438.564110 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_046_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1279.939170 -2364.412796 1347.052869 -423332.215954 2 | -503.990572 1054.163581 2707.523211 -1242815.948552 3 | -0.753733 -0.577708 0.313273 438.564110 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_046_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1279.939170 -2364.412796 1347.052869 -423332.215954 2 | -503.990572 1054.163581 2707.523211 -1242815.948552 3 | -0.753733 -0.577708 0.313273 438.564110 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_047_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1796.756166 -2044.860237 1278.067867 -399289.780885 2 | -489.969966 1021.829964 2722.451514 -1253505.242678 3 | -0.606748 -0.698070 0.380205 388.963309 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_047_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1796.756166 -2044.860237 1278.067867 -399289.780885 2 | -489.969966 1021.829964 2722.451514 -1253505.242678 3 | -0.606748 -0.698070 0.380205 388.963309 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_047_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1796.756166 -2044.860237 1278.067867 -399289.780885 2 | -489.969966 1021.829964 2722.451514 -1253505.242678 3 | -0.606748 -0.698070 0.380205 388.963309 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_048_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2233.555424 -1642.244218 1165.121315 -340057.109445 2 | -469.440675 992.852399 2736.753343 -1264249.144333 3 | -0.437266 -0.786318 0.436465 345.154435 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_048_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2233.555424 -1642.244218 1165.121315 -340057.109445 2 | -469.440675 992.852399 2736.753343 -1264249.144333 3 | -0.437266 -0.786318 0.436465 345.154435 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_048_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2233.555424 -1642.244218 1165.121315 -340057.109445 2 | -469.440675 992.852399 2736.753343 -1264249.144333 3 | -0.437266 -0.786318 0.436465 345.154435 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_049_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2578.935882 -1169.376077 1012.369937 -251464.751728 2 | -442.603362 968.714952 2749.844159 -1274561.094864 3 | -0.250546 -0.840266 0.480811 308.731803 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_049_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 2578.935882 -1169.376077 1012.369937 -251464.751728 2 | -442.603362 968.714952 2749.844159 -1274561.094864 3 | -0.250546 -0.840266 0.480811 308.731803 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_049_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 2578.935882 -1169.376077 1012.369937 -251464.751728 2 | -442.603362 968.714952 2749.844159 -1274561.094864 3 | -0.250546 -0.840266 0.480811 308.731803 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_050_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1719.296305 -1828.247732 1656.735956 -335297.214866 2 | 149.684229 1900.650431 2249.682613 -815877.872198 3 | -0.612617 -0.419165 0.670075 459.041616 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_050_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1719.296305 -1828.247732 1656.735956 -335297.214866 2 | 149.684229 1900.650431 2249.682613 -815877.872198 3 | -0.612617 -0.419165 0.670075 459.041616 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_050_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1719.296305 -1828.247732 1656.735956 -335297.214866 2 | 149.684229 1900.650431 2249.682613 -815877.872198 3 | -0.612617 -0.419165 0.670075 459.041616 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_051_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1082.483049 -2205.126041 1734.616147 -363653.721099 2 | 362.927766 1776.445604 2325.612553 -874329.697287 3 | -0.754972 -0.276004 0.594844 514.128855 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_051_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1082.483049 -2205.126041 1734.616147 -363653.721099 2 | 362.927766 1776.445604 2325.612553 -874329.697287 3 | -0.754972 -0.276004 0.594844 514.128855 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_051_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1082.483049 -2205.126041 1734.616147 -363653.721099 2 | 362.927766 1776.445604 2325.612553 -874329.697287 3 | -0.754972 -0.276004 0.594844 514.128855 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_052_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 368.883795 -2424.229630 1740.769666 -340038.664876 2 | 531.330960 1605.387832 2415.857324 -940341.241961 3 | -0.853117 -0.101985 0.511654 572.694087 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_052_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 368.883795 -2424.229630 1740.769666 -340038.664876 2 | 531.330960 1605.387832 2415.857324 -940341.241961 3 | -0.853117 -0.101985 0.511654 572.694087 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_052_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 368.883795 -2424.229630 1740.769666 -340038.664876 2 | 531.330960 1605.387832 2415.857324 -940341.241961 3 | -0.853117 -0.101985 0.511654 572.694087 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_053_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -373.231563 -2469.674283 1674.709144 -268663.106097 2 | 652.898239 1398.784559 2512.583320 -1008947.745274 3 | -0.898877 0.092910 0.428238 629.679158 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_053_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -373.231563 -2469.674283 1674.709144 -268663.106097 2 | 652.898239 1398.784559 2512.583320 -1008947.745274 3 | -0.898877 0.092910 0.428238 629.679158 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_053_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -373.231563 -2469.674283 1674.709144 -268663.106097 2 | 652.898239 1398.784559 2512.583320 -1008947.745274 3 | -0.898877 0.092910 0.428238 629.679158 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_054_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1092.910535 -2340.764314 1539.354596 -151238.323058 2 | 711.646291 1168.066538 2612.494863 -1077040.607211 3 | -0.890319 0.293144 0.348422 681.938593 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_054_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1092.910535 -2340.764314 1539.354596 -151238.323058 2 | 711.646291 1168.066538 2612.494863 -1077040.607211 3 | -0.890319 0.293144 0.348422 681.938593 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_054_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1092.910535 -2340.764314 1539.354596 -151238.323058 2 | 711.646291 1168.066538 2612.494863 -1077040.607211 3 | -0.890319 0.293144 0.348422 681.938593 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_055_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1260.402150 -2401.912024 1298.248294 2141.432715 2 | 85.324885 1198.610721 2692.954009 -1098493.190069 3 | -0.958139 0.242401 0.152353 804.539006 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_055_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -1260.402150 -2401.912024 1298.248294 2141.432715 2 | 85.324885 1198.610721 2692.954009 -1098493.190069 3 | -0.958139 0.242401 0.152353 804.539006 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_055_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -1260.402150 -2401.912024 1298.248294 2141.432715 2 | 85.324885 1198.610721 2692.954009 -1098493.190069 3 | -0.958139 0.242401 0.152353 804.539006 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_056_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -618.496869 -2567.484672 1438.307222 -112720.538745 2 | 48.788108 1278.218434 2657.014612 -1072644.492005 3 | -0.972175 0.042607 0.230348 753.423502 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_056_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -618.496869 -2567.484672 1438.307222 -112720.538745 2 | 48.788108 1278.218434 2657.014612 -1072644.492005 3 | -0.972175 0.042607 0.230348 753.423502 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_056_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -618.496869 -2567.484672 1438.307222 -112720.538745 2 | 48.788108 1278.218434 2657.014612 -1072644.492005 3 | -0.972175 0.042607 0.230348 753.423502 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_057_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 55.027664 -2591.508616 1524.565062 -195680.391996 2 | -5.569068 1346.598402 2623.469272 -1048144.240385 3 | -0.937328 -0.153542 0.312796 697.537254 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_057_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 55.027664 -2591.508616 1524.565062 -195680.391996 2 | -5.569068 1346.598402 2623.469272 -1048144.240385 3 | -0.937328 -0.153542 0.312796 697.537254 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_057_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 55.027664 -2591.508616 1524.565062 -195680.391996 2 | -5.569068 1346.598402 2623.469272 -1048144.240385 3 | -0.937328 -0.153542 0.312796 697.537254 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_058_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 720.831012 -2470.294861 1556.049335 -241448.095209 2 | -70.447370 1405.501544 2591.438186 -1024634.717717 3 | -0.855496 -0.333210 0.396355 639.262482 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_058_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 720.831012 -2470.294861 1556.049335 -241448.095209 2 | -70.447370 1405.501544 2591.438186 -1024634.717717 3 | -0.855496 -0.333210 0.396355 639.262482 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_058_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 720.831012 -2470.294861 1556.049335 -241448.095209 2 | -70.447370 1405.501544 2591.438186 -1024634.717717 3 | -0.855496 -0.333210 0.396355 639.262482 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_059_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1347.989106 -2213.215870 1525.727521 -244901.403219 2 | -147.567932 1447.899329 2564.714512 -1004348.550984 3 | -0.731013 -0.489337 0.475572 582.350268 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_059_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1347.989106 -2213.215870 1525.727521 -244901.403219 2 | -147.567932 1447.899329 2564.714512 -1004348.550984 3 | -0.731013 -0.489337 0.475572 582.350268 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_059_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1347.989106 -2213.215870 1525.727521 -244901.403219 2 | -147.567932 1447.899329 2564.714512 -1004348.550984 3 | -0.731013 -0.489337 0.475572 582.350268 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_060_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1673.738470 -2151.713201 1269.635152 -103760.857926 2 | -537.294202 959.675786 2736.107932 -1100911.065575 3 | -0.645379 -0.684258 0.339525 658.552305 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_060_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1673.738470 -2151.713201 1269.635152 -103760.857926 2 | -537.294202 959.675786 2736.107932 -1100911.065575 3 | -0.645379 -0.684258 0.339525 658.552305 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_060_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1673.738470 -2151.713201 1269.635152 -103760.857926 2 | -537.294202 959.675786 2736.107932 -1100911.065575 3 | -0.645379 -0.684258 0.339525 658.552305 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_061_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1102.095049 -2462.480016 1328.466129 -116736.682908 2 | -563.298623 1005.313122 2714.404074 -1086093.980871 3 | -0.794241 -0.546461 0.265634 712.811403 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_061_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 1102.095049 -2462.480016 1328.466129 -116736.682908 2 | -563.298623 1005.313122 2714.404074 -1086093.980871 3 | -0.794241 -0.546461 0.265634 712.811403 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_061_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 1102.095049 -2462.480016 1328.466129 -116736.682908 2 | -563.298623 1005.313122 2714.404074 -1086093.980871 3 | -0.794241 -0.546461 0.265634 712.811403 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_062_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | 483.918619 -2652.177108 1332.299868 -96726.780800 2 | -578.530354 1054.766320 2692.344690 -1071279.238959 3 | -0.905197 -0.382482 0.185272 770.195525 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_062_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | 483.918619 -2652.177108 1332.299868 -96726.780800 2 | -578.530354 1054.766320 2692.344690 -1071279.238959 3 | -0.905197 -0.382482 0.185272 770.195525 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_062_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | 483.918619 -2652.177108 1332.299868 -96726.780800 2 | -578.530354 1054.766320 2692.344690 -1071279.238959 3 | -0.905197 -0.382482 0.185272 770.195525 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_063_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -156.694740 -2715.846950 1281.743220 -39396.444648 2 | -579.496446 1106.501731 2671.289404 -1058560.759426 3 | -0.974726 -0.198491 0.102516 827.474745 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_063_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -156.694740 -2715.846950 1281.743220 -39396.444648 2 | -579.496446 1106.501731 2671.289404 -1058560.759426 3 | -0.974726 -0.198491 0.102516 827.474745 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_063_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -156.694740 -2715.846950 1281.743220 -39396.444648 2 | -579.496446 1106.501731 2671.289404 -1058560.759426 3 | -0.974726 -0.198491 0.102516 827.474745 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_064_3_r5000.png.P: -------------------------------------------------------------------------------- 1 | -793.577529 -2649.211030 1181.168575 52052.800319 2 | -568.603392 1159.883937 2650.907152 -1044930.786369 3 | -0.999796 -0.002290 0.020084 882.877078 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_064_3_r7000.png.P: -------------------------------------------------------------------------------- 1 | -793.577529 -2649.211030 1181.168575 52052.800319 2 | -568.603392 1159.883937 2650.907152 -1044930.786369 3 | -0.999796 -0.002290 0.020084 882.877078 4 | -------------------------------------------------------------------------------- /data/dtu/calib/rect_064_6_r5000.png.P: -------------------------------------------------------------------------------- 1 | -793.577529 -2649.211030 1181.168575 52052.800319 2 | -568.603392 1159.883937 2650.907152 -1044930.786369 3 | -0.999796 -0.002290 0.020084 882.877078 4 | -------------------------------------------------------------------------------- /displayUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * utility functions for visualization of results 3 | */ 4 | 5 | #pragma once 6 | #include 7 | #include 8 | 9 | #if (CV_MAJOR_VERSION ==2) 10 | #include // needed for applyColorMap! 11 | #endif 12 | 13 | 14 | /* compute gamma correction (just for display purposes to see more details in farther away areas of disparity image) 15 | * Input: img - image 16 | * gamma - gamma value 17 | * Output: gamma corrected image 18 | */ 19 | Mat correctGamma( Mat& img, double gamma ) { 20 | double inverse_gamma = 1.0 / gamma; 21 | 22 | Mat lut_matrix(1, 256, CV_8UC1 ); 23 | uchar * ptr = lut_matrix.ptr(); 24 | for( int i = 0; i < 256; i++ ) 25 | ptr[i] = (int)( pow( (double) i / 255.0, inverse_gamma ) * 255.0 ); 26 | 27 | Mat result; 28 | LUT( img, lut_matrix, result ); 29 | 30 | return result; 31 | } 32 | 33 | 34 | static void getDisparityForDisplay(const Mat_ &disp, Mat &dispGray, Mat &dispColor, float numDisparities, float minDisp = 0.0f){ 35 | float gamma = 2.0f; // to get higher contrast for lower disparity range (just for color visualization) 36 | disp.convertTo(dispGray,CV_16U,65535.f/(numDisparities-minDisp),-minDisp*65535.f/(numDisparities-minDisp)); 37 | Mat disp8; 38 | disp.convertTo(disp8,CV_8U,255.f/(numDisparities-minDisp),-minDisp*255.f/(numDisparities-minDisp)); 39 | if(minDisp == 0.0f) 40 | disp8 = correctGamma(disp8,gamma); 41 | applyColorMap(disp8, dispColor, COLORMAP_JET); 42 | for(int y = 0; y < dispColor.rows; y++){ 43 | for(int x = 0; x < dispColor.cols; x++){ 44 | if(disp(y,x) <= 0.0f) 45 | dispColor.at(y,x) = Vec3b(0,0,0); 46 | } 47 | } 48 | } 49 | 50 | static void convertDisparityDepthImage(const Mat_ &dispL, Mat_ &d, float f, float baseline){ 51 | d = Mat::zeros(dispL.rows, dispL.cols, CV_32F); 52 | for(int y = 0; y < dispL.rows; y++){ 53 | for(int x = 0; x < dispL.cols; x++){ 54 | d(y,x) = disparityDepthConversion(f,baseline,dispL(y,x)); 55 | } 56 | } 57 | } 58 | 59 | static string getColorString(uint8_t color){ 60 | stringstream ss; 61 | ss << (int)color << " " << (int)color << " " << (int)color; 62 | return ss.str(); 63 | } 64 | 65 | 66 | static string getColorString(Vec3b color){ 67 | stringstream ss; 68 | ss << (int)color(2) << " " << (int)color(1) << " " << (int)color(0); 69 | return ss.str(); 70 | } 71 | 72 | static string getColorString(Vec3i color){ 73 | stringstream ss; 74 | ss << (int)((float)color(2)/256.f) << " " << (int)((float)color(1)/256.f) << " " << (int)((float)color(0)/256.f); 75 | return ss.str(); 76 | } 77 | template 78 | static void storePlyFileBinary(char* plyFilePath, const Mat_ &depthImg, const Mat_ &normals, const Mat_ img, Camera cam, Mat_ &distImg){ 79 | cout << "Saving output depthmap in " << plyFilePath << endl; 80 | 81 | FILE *outputPly; 82 | outputPly=fopen(plyFilePath,"wb"); 83 | 84 | //write header 85 | fprintf(outputPly, "ply\n"); 86 | fprintf(outputPly, "format binary_little_endian 1.0\n"); 87 | fprintf(outputPly, "element vertex %d\n",depthImg.rows * depthImg.cols); 88 | fprintf(outputPly, "property float x\n"); 89 | fprintf(outputPly, "property float y\n"); 90 | fprintf(outputPly, "property float z\n"); 91 | fprintf(outputPly, "property float nx\n"); 92 | fprintf(outputPly, "property float ny\n"); 93 | fprintf(outputPly, "property float nz\n"); 94 | fprintf(outputPly, "property uchar red\n"); 95 | fprintf(outputPly, "property uchar green\n"); 96 | fprintf(outputPly, "property uchar blue\n"); 97 | fprintf(outputPly, "end_header\n"); 98 | 99 | distImg = Mat::zeros(depthImg.rows,depthImg.cols,CV_32F); 100 | 101 | //write data 102 | #pragma omp parallel for 103 | for(int x = 0; x < depthImg.cols; x++){ 104 | for(int y = 0; y < depthImg.rows; y++){ 105 | /* 106 | float zValue = depthImg(x,y); 107 | float xValue = ((float)x-cx)*zValue/camParams.f; 108 | float yValue = ((float)y-cy)*zValue/camParams.f; 109 | myfile << xValue << " " << yValue << " " << zValue << endl; 110 | */ 111 | 112 | //Mat_ pt = Mat::ones(3,1,CV_32F); 113 | //pt(0,0) = (float)x; 114 | //pt(1,0) = (float)y; 115 | 116 | Vec3f n = normals(y,x); 117 | ImgType color = img(y,x); 118 | 119 | //Mat_ ptX = P1_inv * depthImg(y,x)*pt; 120 | 121 | //if(depthImg(y,x) <= 0.0001f) 122 | // continue; 123 | 124 | 125 | Vec3f ptX = get3Dpoint(cam,x,y,depthImg(y,x)); 126 | 127 | //Vec3f ptX_v1 = get3dPointFromPlane(cam.P_inv,cam.C,n,planes.d(y,x),x,y); 128 | //cout << ptX_v1 << " / " << ptX << endl; 129 | 130 | if(!(ptX(0) < FLT_MAX && ptX(0) > -FLT_MAX) || !(ptX(1) < FLT_MAX && ptX(12) > -FLT_MAX) || !(ptX(2) < FLT_MAX && ptX(2) >= -FLT_MAX)){ 131 | ptX(0) = 0.0f; 132 | ptX(1) = 0.0f; 133 | ptX(2) = 0.0f; 134 | } 135 | #pragma omp critical 136 | { 137 | //myfile << ptX(0) << " " << ptX(1) << " " << ptX(2) << " " << n(0) << " " << n(1) << " " << n(2) << " " << getColorString(color) << endl; 138 | fwrite(&(ptX(0)), sizeof(float), 3, outputPly); 139 | fwrite(&(n(0)) , sizeof(float), 3, outputPly); 140 | fwrite(&color, sizeof(color) , 1, outputPly); 141 | fwrite(&color, sizeof(color) , 1, outputPly); 142 | fwrite(&color, sizeof(color) , 1, outputPly); 143 | } 144 | 145 | distImg(y,x) = sqrt(pow(ptX(0)-cam.C(0),2)+pow(ptX(1)-cam.C(1),2)+pow(ptX(2)-cam.C(2),2)); 146 | 147 | //}else{ 148 | // cout << ptX(0) << " " << ptX(1) << " " << ptX(2) << endl; 149 | // cout << depthImg(y,x) << endl; 150 | //} 151 | 152 | 153 | //P * 154 | //cout << xValue << " " << yValue << " " << zValue << " / " << 155 | } 156 | } 157 | 158 | fclose(outputPly); 159 | } 160 | 161 | template 162 | static void storePlyFile(char* plyFilePath, const Mat_ &depthImg, const Mat_ &normals, const Mat_ img, Camera cam, Mat_ &distImg){ 163 | cout << "store 3D points to ply file" << endl; 164 | ofstream myfile; 165 | myfile.open (plyFilePath, ios::out); 166 | 167 | //write header 168 | myfile << "ply" << endl; 169 | myfile << "format ascii 1.0" << endl; 170 | myfile << "element vertex " << depthImg.rows * depthImg.cols << endl; 171 | myfile << "property float x" << endl; 172 | myfile << "property float y" << endl; 173 | myfile << "property float z" << endl; 174 | myfile << "property float nx" << endl; 175 | myfile << "property float ny" << endl; 176 | myfile << "property float nz" << endl; 177 | myfile << "property uchar red" << endl; 178 | myfile << "property uchar green" << endl; 179 | myfile << "property uchar blue" << endl; 180 | myfile << "end_header" << endl; 181 | 182 | distImg = Mat::zeros(depthImg.rows,depthImg.cols,CV_32F); 183 | 184 | //write data 185 | //#pragma omp parallel for 186 | for(int x = 0; x < depthImg.cols; x++){ 187 | for(int y = 0; y < depthImg.rows; y++){ 188 | /* 189 | float zValue = depthImg(x,y); 190 | float xValue = ((float)x-cx)*zValue/camParams.f; 191 | float yValue = ((float)y-cy)*zValue/camParams.f; 192 | myfile << xValue << " " << yValue << " " << zValue << endl; 193 | */ 194 | 195 | //Mat_ pt = Mat::ones(3,1,CV_32F); 196 | //pt(0,0) = (float)x; 197 | //pt(1,0) = (float)y; 198 | 199 | Vec3f n = normals(y,x); 200 | ImgType color = img(y,x); 201 | 202 | //Mat_ ptX = P1_inv * depthImg(y,x)*pt; 203 | 204 | //if(depthImg(y,x) <= 0.0001f) 205 | // continue; 206 | 207 | 208 | Vec3f ptX = get3Dpoint(cam,x,y,depthImg(y,x)); 209 | 210 | //Vec3f ptX_v1 = get3dPointFromPlane(cam.P_inv,cam.C,n,planes.d(y,x),x,y); 211 | //cout << ptX_v1 << " / " << ptX << endl; 212 | 213 | if(!(ptX(0) < FLT_MAX && ptX(0) > -FLT_MAX) || !(ptX(1) < FLT_MAX && ptX(12) > -FLT_MAX) || !(ptX(2) < FLT_MAX && ptX(2) >= -FLT_MAX)){ 214 | ptX(0) = 0.0f; 215 | ptX(1) = 0.0f; 216 | ptX(2) = 0.0f; 217 | } 218 | //#pragma omp critical 219 | { 220 | myfile << ptX(0) << " " << ptX(1) << " " << ptX(2) << " " << n(0) << " " << n(1) << " " << n(2) << " " << getColorString(color) << endl; 221 | } 222 | 223 | distImg(y,x) = sqrt(pow(ptX(0)-cam.C(0),2)+pow(ptX(1)-cam.C(1),2)+pow(ptX(2)-cam.C(2),2)); 224 | 225 | //}else{ 226 | // cout << ptX(0) << " " << ptX(1) << " " << ptX(2) << endl; 227 | // cout << depthImg(y,x) << endl; 228 | //} 229 | 230 | 231 | //P * 232 | //cout << xValue << " " << yValue << " " << zValue << " / " << 233 | } 234 | } 235 | 236 | myfile.close(); 237 | } 238 | 239 | static void getNormalsForDisplay(const Mat &normals, Mat &normals_display, int rtype = CV_16U){ 240 | if(rtype == CV_8U) 241 | normals.convertTo(normals_display,CV_8U,128,128); 242 | else 243 | normals.convertTo(normals_display,CV_16U,32767,32767); 244 | cvtColor(normals_display,normals_display,COLOR_RGB2BGR); 245 | } 246 | -------------------------------------------------------------------------------- /exception.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | /* CUda UTility Library */ 13 | #ifndef _EXCEPTION_H_ 14 | #define _EXCEPTION_H_ 15 | 16 | // includes, system 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | //! Exception wrapper. 23 | //! @param Std_Exception Exception out of namespace std for easy typing. 24 | template 25 | class Exception : public Std_Exception 26 | { 27 | public: 28 | 29 | //! @brief Static construction interface 30 | //! @return Alwayss throws ( Located_Exception) 31 | //! @param file file in which the Exception occurs 32 | //! @param line line in which the Exception occurs 33 | //! @param detailed details on the code fragment causing the Exception 34 | static void throw_it(const char *file, 35 | const int line, 36 | const char *detailed = "-"); 37 | 38 | //! Static construction interface 39 | //! @return Alwayss throws ( Located_Exception) 40 | //! @param file file in which the Exception occurs 41 | //! @param line line in which the Exception occurs 42 | //! @param detailed details on the code fragment causing the Exception 43 | static void throw_it(const char *file, 44 | const int line, 45 | const std::string &detailed); 46 | 47 | //! Destructor 48 | virtual ~Exception() throw(); 49 | 50 | private: 51 | 52 | //! Constructor, default (private) 53 | Exception(); 54 | 55 | //! Constructor, standard 56 | //! @param str string returned by what() 57 | Exception(const std::string &str); 58 | 59 | }; 60 | 61 | //////////////////////////////////////////////////////////////////////////////// 62 | //! Exception handler function for arbitrary exceptions 63 | //! @param ex exception to handle 64 | //////////////////////////////////////////////////////////////////////////////// 65 | template 66 | inline void 67 | handleException(const Exception_Typ &ex) 68 | { 69 | std::cerr << ex.what() << std::endl; 70 | 71 | exit(EXIT_FAILURE); 72 | } 73 | 74 | //! Convenience macros 75 | 76 | //! Exception caused by dynamic program behavior, e.g. file does not exist 77 | #define RUNTIME_EXCEPTION( msg) \ 78 | Exception::throw_it( __FILE__, __LINE__, msg) 79 | 80 | //! Logic exception in program, e.g. an assert failed 81 | #define LOGIC_EXCEPTION( msg) \ 82 | Exception::throw_it( __FILE__, __LINE__, msg) 83 | 84 | //! Out of range exception 85 | #define RANGE_EXCEPTION( msg) \ 86 | Exception::throw_it( __FILE__, __LINE__, msg) 87 | 88 | //////////////////////////////////////////////////////////////////////////////// 89 | //! Implementation 90 | 91 | // includes, system 92 | #include 93 | 94 | //////////////////////////////////////////////////////////////////////////////// 95 | //! Static construction interface. 96 | //! @param Exception causing code fragment (file and line) and detailed infos. 97 | //////////////////////////////////////////////////////////////////////////////// 98 | /*static*/ template 99 | void 100 | Exception:: 101 | throw_it(const char *file, const int line, const char *detailed) 102 | { 103 | std::stringstream s; 104 | 105 | // Quiet heavy-weight but exceptions are not for 106 | // performance / release versions 107 | s << "Exception in file '" << file << "' in line " << line << "\n" 108 | << "Detailed description: " << detailed << "\n"; 109 | 110 | throw Exception(s.str()); 111 | } 112 | 113 | //////////////////////////////////////////////////////////////////////////////// 114 | //! Static construction interface. 115 | //! @param Exception causing code fragment (file and line) and detailed infos. 116 | //////////////////////////////////////////////////////////////////////////////// 117 | /*static*/ template 118 | void 119 | Exception:: 120 | throw_it(const char *file, const int line, const std::string &msg) 121 | { 122 | throw_it(file, line, msg.c_str()); 123 | } 124 | 125 | //////////////////////////////////////////////////////////////////////////////// 126 | //! Constructor, default (private). 127 | //////////////////////////////////////////////////////////////////////////////// 128 | template 129 | Exception::Exception() : 130 | Std_Exception("Unknown Exception.\n") 131 | { } 132 | 133 | //////////////////////////////////////////////////////////////////////////////// 134 | //! Constructor, standard (private). 135 | //! String returned by what(). 136 | //////////////////////////////////////////////////////////////////////////////// 137 | template 138 | Exception::Exception(const std::string &s) : 139 | Std_Exception(s) 140 | { } 141 | 142 | //////////////////////////////////////////////////////////////////////////////// 143 | //! Destructor 144 | //////////////////////////////////////////////////////////////////////////////// 145 | template 146 | Exception::~Exception() throw() { } 147 | 148 | // functions, exported 149 | 150 | #endif // #ifndef _EXCEPTION_H_ 151 | 152 | -------------------------------------------------------------------------------- /fileIoUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * utility functions for reading and writing files 3 | */ 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | static void getProjectionMatrix(char* line, Mat_ &P){ 11 | const char* p; 12 | int idx = 0; 13 | for (p = strtok( line, " " ); p; p = strtok( NULL, " " )) 14 | { 15 | if(p[0]=='P' || p[0]=='p') 16 | continue; 17 | 18 | //float val = stof(p); 19 | float val = (float)atof(p); 20 | /*cout << val << endl;*/ 21 | P(idx/4,idx%4)=val; 22 | 23 | idx++; 24 | } 25 | } 26 | 27 | static int read3Dpoint(char* line, Vec3f &pt){ 28 | const char* p; 29 | int idx = 0; 30 | for (p = strtok( line, " " ); p; p = strtok( NULL, " " )) 31 | { 32 | if(idx > 2) 33 | return -1; 34 | float val = (float)atof(p); 35 | pt[idx] = val; 36 | 37 | idx++; 38 | } 39 | if(idx<2) 40 | return -1; 41 | return 0; 42 | } 43 | 44 | static void readCalibFileKitti(const string calib_filename, Mat_ &P1, Mat_ &P2){ 45 | ifstream myfile; 46 | myfile.open(calib_filename.c_str(),ifstream::in); 47 | //get first line (containing P0) 48 | char line[512]; 49 | myfile.getline(line,512); 50 | getProjectionMatrix(line,P1); 51 | myfile.getline(line,512); 52 | getProjectionMatrix(line,P2); 53 | myfile.close(); 54 | } 55 | 56 | static void readBoundingVolume(const string filename, Vec3f &ptBL, Vec3f & ptTR){ 57 | ifstream myfile; 58 | myfile.open(filename.c_str(),ifstream::in); 59 | char line[512]; 60 | //bottom left point 61 | myfile.getline(line,512); 62 | read3Dpoint(line,ptBL); 63 | //top right point 64 | myfile.getline(line,512); 65 | read3Dpoint(line,ptTR); 66 | 67 | myfile.close(); 68 | } 69 | 70 | 71 | static void readCameraFileStrecha(const string camera_filename, float &focalLength){ 72 | // only interested in focal length, but possible to get also other internal and external camera parameters 73 | // focal length is stored in pixel format as alpha_x and alphy_y, only using alpha_x (which is the very first parameter of the internal camera matrix) 74 | ifstream myfile; 75 | myfile.open(camera_filename.c_str(),ifstream::in); 76 | char line[512]; 77 | myfile.getline(line,512); 78 | const char* p = strtok( line, " " ); 79 | focalLength = (float)atof(p); 80 | myfile.close(); 81 | } 82 | 83 | static void readPFileStrechaPmvs(const string p_filename, Mat_ &P){ 84 | ifstream myfile; 85 | myfile.open(p_filename.c_str(),ifstream::in); 86 | 87 | //cout <<"Opening file " << p_filename << endl; 88 | for( int i = 0; i < 4; i++){ 89 | if (myfile.eof()) 90 | break; 91 | char line[512]; 92 | myfile.getline(line,512); 93 | if (strstr(line,"CONTOUR")!= NULL) { 94 | //printf("Skipping CONTOUR\n"); 95 | i--; 96 | continue; 97 | } 98 | 99 | //cout << "Line is "<< line << endl; 100 | const char* p; 101 | int j = 0; 102 | for (p = strtok( line, " " ); p; p = strtok( NULL, " " )) 103 | { 104 | float val = (float)atof(p); 105 | P(i,j)=val; 106 | j++; 107 | } 108 | } 109 | myfile.close(); 110 | } 111 | static void readKRtFileMiddlebury(const string filename, vector cameras, InputFiles inputFiles) 112 | { 113 | ifstream myfile; 114 | myfile.open( filename, ifstream::in ); 115 | string line; 116 | 117 | getline (myfile, line); // throw away first line 118 | 119 | int i=0; 120 | size_t truei=-1; 121 | while( getline( myfile,line) ) 122 | { 123 | /*cout << "Line is "<< line << endl;*/ 124 | Mat Rt; 125 | Mat_ K = Mat::zeros( 3, 3, CV_32F ); 126 | Mat_ R = Mat::zeros( 3, 3, CV_32F ); 127 | Vec3f vt; 128 | stringstream ss(line); 129 | string tmp; 130 | ss >> tmp 131 | >> K(0,0) >> K(0,1) >> K(0,2) >> K(1,0) >> K(1,1) >> K(1,2) >> K(2,0) >> K(2,1) >> K(2,2) // 132 | >> R(0,0) >> R(0,1) >> R(0,2) >> R(1,0) >> R(1,1) >> R(1,2) >> R(2,0) >> R(2,1) >> R(2,2) // 133 | >> vt(0) >> vt(1) >> vt(2); 134 | /*cout << "K is " << K << endl;*/ 135 | /*cout << "R is " << R << endl;*/ 136 | /*cout << "t is " << vt << endl;*/ 137 | //cout << "Filename is " << tmp << endl; 138 | //cout << "image Filename is " << inputFiles.img_filenames[i] << endl; 139 | for( size_t j = 0; j < inputFiles.img_filenames.size(); j++) { 140 | if( tmp == inputFiles.img_filenames[j]) { 141 | truei=j; 142 | break; 143 | } 144 | } 145 | Mat t(vt, false); 146 | /*Mat t(vt);*/ 147 | hconcat(R, t, Rt); 148 | cameras[truei].P = K*Rt; 149 | /*cout << "Rt is " << Rt<< endl;*/ 150 | /*cout << "P is " << P << endl;*/ 151 | /*cout << "P is " << cameras[i].P << endl;*/ 152 | i++; 153 | } 154 | 155 | 156 | /*while (os >> temp) //the stringstream makes temp a token*/ 157 | /*std::cout < &P){ 165 | ifstream myfile; 166 | myfile.open(calib_filename.c_str(),ifstream::in); 167 | 168 | char line[512]; 169 | while (myfile.getline(line, 512)) { 170 | if(line[0] == 'p') 171 | getProjectionMatrix(line,P); 172 | } 173 | 174 | myfile.close(); 175 | } 176 | 177 | static void writeImageToFile(const char* outputFolder,const char* name,const Mat &img){ 178 | char outputPath[256]; 179 | sprintf(outputPath, "%s/%s.png", outputFolder,name); 180 | imwrite(outputPath,img); 181 | } 182 | 183 | static void writeParametersToFile(char* resultsFile, InputFiles inputFiles, AlgorithmParameters &algParameters, GTcheckParameters >Parameters, uint32_t numPixels){ 184 | 185 | ofstream myfile; 186 | myfile.open (resultsFile, ios::out); 187 | myfile << "Number of images: " << inputFiles.img_filenames.size() << endl; 188 | myfile << "Image folder: " << inputFiles.images_folder << endl; 189 | myfile << "Images: "; 190 | for(size_t i=0; i < inputFiles.img_filenames.size(); i++) 191 | myfile << inputFiles.img_filenames[i] << ", " ; 192 | myfile << endl; 193 | if(numPixels != 0) 194 | myfile << "Num. pixels: " << numPixels << endl; 195 | myfile << "\nParameters:" << endl; 196 | myfile << " Cost function: " ; 197 | if(algParameters.algorithm == PM_COST) 198 | myfile << "PatchMatch Cost" << endl; 199 | else if(algParameters.algorithm == CENSUS_TRANSFORM) 200 | myfile << "Census Transform" << endl; 201 | else if(algParameters.algorithm == SPARSE_CENSUS) 202 | myfile << "Sparse Census Transform" << endl; 203 | else if(algParameters.algorithm == CENSUS_SELFSIMILARITY) 204 | myfile << "Census Transform with Self-Similarity Propagation" << endl; 205 | else if(algParameters.algorithm == PM_SELFSIMILARITY) 206 | myfile << "Patch Match Cost with Self-Similarity Propagation" << endl; 207 | else 208 | myfile << algParameters.algorithm << endl; 209 | myfile << " Kernel size: " << algParameters.box_hsize << " x " << algParameters.box_vsize << endl; 210 | myfile << " Number of iterations: " << algParameters.iterations << endl; 211 | myfile << " Max. disparity: " << algParameters.max_disparity << endl; 212 | myfile << " Depth min: " << algParameters.depthMin << endl; 213 | myfile << " Depth max: " << algParameters.depthMax << endl; 214 | myfile << " gamma: " << algParameters.gamma << endl; 215 | myfile << " alpha: " << algParameters.alpha << endl; 216 | myfile << " tauCol: " << algParameters.tau_color << endl; 217 | myfile << " tauGrad: " << algParameters.tau_gradient << endl; 218 | myfile << " border value: " << algParameters.border_value << endl; 219 | myfile << " disparity tolerance (occ check): " << algParameters.dispTol << endl; 220 | myfile << " normal tolerance (occ check): " << algParameters.normTol << endl; 221 | myfile << " census epsilon: " << algParameters.census_epsilon << endl; 222 | myfile << " self-similarity n: " << algParameters.self_similarity_n << endl; 223 | myfile << " cost good truncation factor: " << algParameters.good_factor << endl; 224 | myfile << " cost combination: "; 225 | if(algParameters.cost_comb == COMB_ALL) 226 | myfile << "ALL" << endl; 227 | else if(algParameters.cost_comb == COMB_BEST_N) 228 | myfile << "BEST_N (n=" << algParameters.n_best << ")" << endl; 229 | else if(algParameters.cost_comb == COMB_ANGLE) 230 | myfile << "ANGLE" << endl; 231 | else if(algParameters.cost_comb == COMB_GOOD) 232 | myfile << "GOOD" << endl; 233 | myfile << " color processing: "; 234 | if(algParameters.color_processing) 235 | myfile << "yes" << endl; 236 | else 237 | myfile << "no" << endl; 238 | myfile << " view selection: "; 239 | if(algParameters.viewSelection) 240 | myfile << "yes" << endl; 241 | else 242 | myfile << "no" << endl; 243 | myfile << " GT disparity tolerance: " << gtParameters.dispTolGT << "\n" << endl; 244 | myfile.close(); 245 | } 246 | // read ground truth depth map file (dmb) (provided by Tola et al. "DAISY: A Fast Local Descriptor for Dense Matching" http://cvlab.epfl.ch/software/daisy) 247 | static int readDmbNormal (const char *filename, Mat_ &img) 248 | { 249 | FILE *inimage; 250 | inimage = fopen(filename, "rb"); 251 | if (!inimage){ 252 | printf("Error opening file %s",filename); 253 | return -1; 254 | } 255 | 256 | int32_t type, h, w, nb; 257 | 258 | type = -1; 259 | 260 | fread(&type,sizeof(int32_t),1,inimage); 261 | fread(&h,sizeof(int32_t),1,inimage); 262 | fread(&w,sizeof(int32_t),1,inimage); 263 | fread(&nb,sizeof(int32_t),1,inimage); 264 | 265 | //only support float 266 | if(type != 1){ 267 | fclose(inimage); 268 | return -1; 269 | } 270 | 271 | int32_t dataSize = h*w*nb; 272 | 273 | float* data; 274 | data = (float*) malloc (sizeof(float)*dataSize); 275 | fread(data,sizeof(float),dataSize,inimage); 276 | 277 | img = Mat(h,w,CV_32FC3,data); 278 | 279 | fclose(inimage); 280 | return 0; 281 | 282 | } 283 | // read ground truth depth map file (dmb) (provided by Tola et al. "DAISY: A Fast Local Descriptor for Dense Matching" http://cvlab.epfl.ch/software/daisy) 284 | static int readDmb(const char *filename, Mat_ &img) 285 | { 286 | FILE *inimage; 287 | inimage = fopen(filename, "rb"); 288 | if (!inimage){ 289 | printf("Error opening file %s",filename); 290 | return -1; 291 | } 292 | 293 | int32_t type, h, w, nb; 294 | 295 | type = -1; 296 | 297 | fread(&type,sizeof(int32_t),1,inimage); 298 | fread(&h,sizeof(int32_t),1,inimage); 299 | fread(&w,sizeof(int32_t),1,inimage); 300 | fread(&nb,sizeof(int32_t),1,inimage); 301 | 302 | //only support float 303 | if(type != 1){ 304 | fclose(inimage); 305 | return -1; 306 | } 307 | 308 | int32_t dataSize = h*w*nb; 309 | 310 | float* data; 311 | data = (float*) malloc (sizeof(float)*dataSize); 312 | fread(data,sizeof(float),dataSize,inimage); 313 | 314 | img = Mat(h,w,CV_32F,data); 315 | 316 | fclose(inimage); 317 | return 0; 318 | 319 | } 320 | static int writeDmbNormal(const char *filename, Mat_ &img){ 321 | FILE *outimage; 322 | outimage = fopen(filename, "wb"); 323 | if (!outimage) 324 | printf("Error opening file %s",filename); 325 | 326 | int32_t type = 1; //float 327 | int32_t h = img.rows; 328 | int32_t w = img.cols; 329 | int32_t nb = 3; 330 | 331 | fwrite(&type,sizeof(int32_t),1,outimage); 332 | fwrite(&h,sizeof(int32_t),1,outimage); 333 | fwrite(&w,sizeof(int32_t),1,outimage); 334 | fwrite(&nb,sizeof(int32_t),1,outimage); 335 | 336 | float* data = (float*)img.data; 337 | 338 | int32_t datasize = w*h*nb; 339 | fwrite(data,sizeof(float),datasize,outimage); 340 | 341 | fclose(outimage); 342 | return 0; 343 | } 344 | 345 | static int writeDmb(const char *filename, Mat_ &img){ 346 | FILE *outimage; 347 | outimage = fopen(filename, "wb"); 348 | if (!outimage) 349 | printf("Error opening file %s",filename); 350 | 351 | int32_t type = 1; //float 352 | int32_t h = img.rows; 353 | int32_t w = img.cols; 354 | int32_t nb = 1; 355 | 356 | fwrite(&type,sizeof(int32_t),1,outimage); 357 | fwrite(&h,sizeof(int32_t),1,outimage); 358 | fwrite(&w,sizeof(int32_t),1,outimage); 359 | fwrite(&nb,sizeof(int32_t),1,outimage); 360 | 361 | float* data = (float*)img.data; 362 | 363 | int32_t datasize = w*h*nb; 364 | fwrite(data,sizeof(float),datasize,outimage); 365 | 366 | fclose(outimage); 367 | return 0; 368 | } 369 | 370 | static int readPfm( const char *filename, 371 | //double ***u, // double matrix image 372 | Mat_ &img, 373 | long *nx, /*image size in x direction */ 374 | long *ny) /*image size in y direction */ 375 | { 376 | FILE *inimage; /* input image FILE pointer */ 377 | long i, j; /* loop variable */ 378 | char row[4096]; /* for reading data */ 379 | 380 | /* open input pgm file and read header */ 381 | inimage = fopen(filename, "rb"); 382 | if (!inimage) 383 | printf("Error opening file %s",filename); 384 | 385 | /* calling it two times because of the P6 header */ 386 | fgets (row, 4096, inimage); 387 | if (row[0]!='P') 388 | abort(); 389 | printf("Row is %s\n", row); 390 | char format = row[1]; 391 | switch (format) /* which format to deal with */ 392 | { 393 | case '5': /* P6 format - classic pgm */ 394 | printf("Opening %s P5 file\n", filename ); 395 | fgets (row, 4096, inimage); 396 | 397 | while (row[0]=='#'||row[0]=='\n') fgets(row, 4096, inimage); 398 | sscanf (row, "%ld %ld", nx, ny); 399 | fgets (row, 4096, inimage); 400 | // fgets (row, 4096, inimage); 401 | 402 | /* allocate storage */ 403 | //alloc_matrix_d (u, *nx, *ny); 404 | img = Mat::zeros((int)*ny,(int)*nx,CV_32F); 405 | 406 | /* read image data */ 407 | for (j=0; j<*ny; j++) 408 | for (i=0; i<*nx; i++) 409 | img(j,i) = (float) getc (inimage); 410 | //(*u)[i][j] = (double) getc (inimage); 411 | break; 412 | /* PF format - pbm HDR format file */ 413 | case 'F': 414 | case 'f': 415 | printf("Opening %s PF file\n", filename ); 416 | fgets (row, 4096, inimage); 417 | 418 | while (row[0]=='#'||row[0]=='\n') 419 | fgets(row, 4096, inimage); 420 | 421 | sscanf (row, "%ld %ld", nx, ny); 422 | 423 | // fgets (row, 4096, inimage); 424 | double scale; 425 | fscanf(inimage, "%lf\n", &scale); 426 | // printf("Scale is %f\n", scale); 427 | // fgets (row, 4096, inimage); 428 | 429 | /* allocate storage */ 430 | //alloc_matrix_d (u, (*nx)*4*3, (*ny)*4*3); 431 | img = Mat::zeros((int)*ny,(int)*nx,CV_32F); 432 | 433 | float tmpfloat; 434 | // printf("Float is %lu bytes big\n", sizeof(float)); 435 | /* read image data */ 436 | for (j=*ny-1; j>=0; j--) { 437 | for (i=0; i<*nx; i++) { 438 | // (*u)[i][j] = (double) getc (inimage); 439 | fread((void *)(&tmpfloat), sizeof(float), 1, inimage); 440 | /* overwrite other 3 channels when they are available */ 441 | if (format=='F') { 442 | fread((void *)(&tmpfloat), sizeof(float), 1, inimage); 443 | fread((void *)(&tmpfloat), sizeof(float), 1, inimage); 444 | } 445 | img(j,i) = tmpfloat; 446 | //(*u)[i][j] = (double) tmpfloat; 447 | 448 | /* if positive convert to big endian */ 449 | if (scale > 0) 450 | { 451 | char array[4]; 452 | char tmpbyte; 453 | memcpy(array, &tmpfloat, sizeof (float)); 454 | /* swap 0 3 */ 455 | tmpbyte = array[0]; 456 | array[0] = array[3]; 457 | array[3] = tmpbyte; 458 | /* swap 1 2 */ 459 | tmpbyte = array[1]; 460 | array[1]=array[2]; 461 | array[2] = tmpbyte; 462 | memcpy(&tmpfloat, array, sizeof (float)); 463 | 464 | img(j,i) = tmpfloat; 465 | //(*u)[i][j] = (double) tmpfloat; 466 | } 467 | } 468 | } 469 | break; 470 | } 471 | 472 | fclose(inimage); 473 | return 0; 474 | 475 | } 476 | -------------------------------------------------------------------------------- /gipuma.h: -------------------------------------------------------------------------------- 1 | #include "globalstate.h" 2 | int runcuda(GlobalState &gs); 3 | -------------------------------------------------------------------------------- /globalstate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "algorithmparameters.h" 4 | #include "cameraparameters.h" 5 | #include "linestate.h" 6 | #include "imageinfo.h" 7 | #include "managed.h" 8 | 9 | // Includes CUDA 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | // includes, cuda 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | class GlobalState : public Managed { 25 | public: 26 | CameraParameters_cu *cameras; 27 | LineState *lines; 28 | curandState *cs; 29 | AlgorithmParameters *params; 30 | 31 | cudaTextureObject_t imgs [MAX_IMAGES]; 32 | cudaArray *cuArray[MAX_IMAGES]; 33 | //cudaTextureObject_t gradx [MAX_IMAGES]; 34 | //cudaTextureObject_t grady [MAX_IMAGES]; 35 | GlobalState() { 36 | //printf("GlobalState constructor\n"); 37 | cameras = new CameraParameters_cu; 38 | lines = new LineState; 39 | } 40 | ~GlobalState() { 41 | //printf("GlobalState destructor\n"); 42 | delete cameras; 43 | delete lines; 44 | } 45 | }; 46 | -------------------------------------------------------------------------------- /groundTruthUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * utility functions for comparison with ground truth data 3 | */ 4 | 5 | #pragma once 6 | 7 | /* compute error of disparity image based on ground truth image 8 | * Input: gtDisp - ground truth disparity image 9 | * occImg - occlusion mask (for seperate error computation of non occluded pixels) 10 | * disp - disparity image 11 | * gtParam - parameters for error computation (e.g. division factor, thresholds, ...) 12 | * valid - mask that defines if pixel passed occlusion check (1) or not (0) 13 | * Output: errorImgContinuous - shows continuous error (difference between ground truth and actual disparity) 14 | * errorImg - white: no error, gray: error at occluded area, black: error at nonoccluded area 15 | * nonErrorImg - black: no GT data, gray: error, white: no error 16 | * error - error all (sum over all pixels: 0 or 1 (error), divided by num pixels for which GT data is available) 17 | * errorNocc - error for nonoccluded areas (using occlusion mask) 18 | * errorValid - error of all pixels that passed occlusion check 19 | * errorvalidAll - error of all pixels that passed the occlusion check with all other pixels being counted as error 1 20 | * errorImgValid - black: errorneous pixels that passed the occlusion check 21 | */ 22 | float computeError(const Mat_& gtDisp, const Mat_& occImg, Mat_& disp, Mat_& errorImgContinuous, Mat_& errorImg, Mat_& errorImg2, Mat_& nonErrorImg, float &error, float &error2, float &errorNocc, float &errorValid, float &errorValidAll, GTcheckParameters gtParam, Mat_& valid, Mat_& errorImgValid){ 23 | //for Middleburry dataset 24 | error = 0; 25 | error2 = 0; 26 | errorNocc = 0; 27 | errorValid = 0; 28 | errorValidAll = 0; 29 | int numGtPixels = 0; //pixels with disp=0 in GT are not counted 30 | int numNoccPixels = 0; //according to occImg (GT) 31 | int numValidPixels = 0; //pixels that passed occlusion check 32 | bool checkValid = false; 33 | if(valid.rows>0) 34 | checkValid =true; 35 | 36 | for(int i = 0; i < gtDisp.rows; i++) { 37 | for(int j = 0; j < gtDisp.cols; j++) { 38 | float d1 = (float)gtDisp(i,j)/gtParam.divFactor; 39 | if(d1==0.0f || d1==-1.0f){ //no valid disparity value for ground truth 40 | errorImgContinuous(i,j) = 255; 41 | errorImg(i,j) = 255; 42 | errorImg2(i,j) = 255; 43 | continue; 44 | } 45 | numGtPixels++; 46 | bool nocc = false; 47 | bool validPixel = false; 48 | if(occImg(i,j) != 0){ //check if pixel is occluded 49 | nocc = true; 50 | numNoccPixels++; 51 | } 52 | nonErrorImg(i,j) = 100; 53 | if(checkValid && valid(i,j) != 0){ 54 | validPixel = true; 55 | numValidPixels++; 56 | } 57 | float d2 = disp(i,j); 58 | float diff = abs(d1 - d2); 59 | errorImgContinuous(i,j) = 255 - min((int)(diff*gtParam.scale),255); 60 | uint8_t err = 255; 61 | if (diff >= gtParam.dispTolGT){ 62 | error++; 63 | err = 150; 64 | if(nocc){ 65 | errorNocc++; 66 | err = 0; 67 | } 68 | if(validPixel){ 69 | errorValid++; 70 | errorImgValid(i,j) = 0; 71 | } 72 | 73 | 74 | }else{ 75 | nonErrorImg(i,j) = 255; 76 | } 77 | errorImg(i,j) = err; 78 | 79 | uint8_t err2 = 255; 80 | if(diff >= gtParam.dispTolGT2){ 81 | err2 = 150; 82 | if(nocc) 83 | err2 = 0; 84 | error2++; 85 | } 86 | errorImg2(i,j) = err2; 87 | } 88 | } 89 | error = error / (float)numGtPixels; 90 | error2 = error2 / (float)numGtPixels; 91 | errorNocc = errorNocc / (float)numNoccPixels; 92 | errorValidAll = (errorValid + (numGtPixels-numValidPixels)) / (float)numGtPixels; 93 | errorValid = errorValid / (float)numValidPixels; 94 | return (float)numValidPixels/(float)numGtPixels; 95 | } 96 | 97 | static float computeNormalError(const Mat_ &normals, const Mat_ >Normals, float gtNormTol, float gtNormTol2, Mat_ &errorMap, float &error2){ 98 | int numGtPixels = 0; 99 | int error = 0; 100 | int error2_count = 0; 101 | for(int y = 0; y < gtNormals.rows; y++) { 102 | for(int x = 0; x < gtNormals.cols; x++) { 103 | /* 104 | Vec3i gtN_int = gtNormals(y,x); 105 | gtN_int = gtN_int - Vec3i(32767,32767,32767); 106 | 107 | 108 | if(gtN_int(0) == gtN_int(1) && gtN_int(0) == gtN_int(2) && gtN_int(0) == 0){ 109 | continue; 110 | } 111 | Vec3f gtN = normalize((Vec3f)gtN_int); // get rid of scaling 112 | */ 113 | Vec3f gtN = gtNormals(y,x); 114 | if(gtN(0) + gtN(1) + gtN(2) < 0.1f) 115 | continue; 116 | 117 | numGtPixels++; 118 | 119 | Vec3f n = normals(y,x); 120 | float angle = getAngle(gtN,n); 121 | 122 | //cout << "n: " << n << " / " << gtN << " / angle: " << angle << endl; 123 | errorMap(y,x) = angle; 124 | 125 | if(angle > gtNormTol){ 126 | error++; 127 | } 128 | if(angle > gtNormTol2){ 129 | error2_count++; 130 | } 131 | } 132 | } 133 | error2 = (float)error2_count/ (float) numGtPixels; 134 | return (float)error / (float) numGtPixels; 135 | } 136 | 137 | static void getNoccGTimg(const Mat_ &groundTruthDisp, const Mat_ &occlusionImg, Mat_ &groundTruthDispNocc){ 138 | bitwise_and(groundTruthDisp,groundTruthDisp,groundTruthDispNocc,occlusionImg); 139 | } 140 | -------------------------------------------------------------------------------- /helper_string.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 1993-2013 NVIDIA Corporation. All rights reserved. 3 | * 4 | * Please refer to the NVIDIA end user license agreement (EULA) associated 5 | * with this source code for terms and conditions that govern your use of 6 | * this software. Any use, reproduction, disclosure, or distribution of 7 | * this software and related documentation outside the terms of the EULA 8 | * is strictly prohibited. 9 | * 10 | */ 11 | 12 | // These are helper functions for the SDK samples (string parsing, timers, etc) 13 | #ifndef STRING_HELPER_H 14 | #define STRING_HELPER_H 15 | 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 22 | #ifndef _CRT_SECURE_NO_DEPRECATE 23 | #define _CRT_SECURE_NO_DEPRECATE 24 | #endif 25 | #ifndef STRCASECMP 26 | #define STRCASECMP _stricmp 27 | #endif 28 | #ifndef STRNCASECMP 29 | #define STRNCASECMP _strnicmp 30 | #endif 31 | #ifndef STRCPY 32 | #define STRCPY(sFilePath, nLength, sPath) strcpy_s(sFilePath, nLength, sPath) 33 | #endif 34 | 35 | #ifndef FOPEN 36 | #define FOPEN(fHandle,filename,mode) fopen_s(&fHandle, filename, mode) 37 | #endif 38 | #ifndef FOPEN_FAIL 39 | #define FOPEN_FAIL(result) (result != 0) 40 | #endif 41 | #ifndef SSCANF 42 | #define SSCANF sscanf_s 43 | #endif 44 | #ifndef SPRINTF 45 | #define SPRINTF sprintf_s 46 | #endif 47 | #else // Linux Includes 48 | #include 49 | #include 50 | 51 | #ifndef STRCASECMP 52 | #define STRCASECMP strcasecmp 53 | #endif 54 | #ifndef STRNCASECMP 55 | #define STRNCASECMP strncasecmp 56 | #endif 57 | #ifndef STRCPY 58 | #define STRCPY(sFilePath, nLength, sPath) strcpy(sFilePath, sPath) 59 | #endif 60 | 61 | #ifndef FOPEN 62 | #define FOPEN(fHandle,filename,mode) (fHandle = fopen(filename, mode)) 63 | #endif 64 | #ifndef FOPEN_FAIL 65 | #define FOPEN_FAIL(result) (result == NULL) 66 | #endif 67 | #ifndef SSCANF 68 | #define SSCANF sscanf 69 | #endif 70 | #ifndef SPRINTF 71 | #define SPRINTF sprintf 72 | #endif 73 | #endif 74 | 75 | #ifndef EXIT_WAIVED 76 | #define EXIT_WAIVED 2 77 | #endif 78 | 79 | // CUDA Utility Helper Functions 80 | inline int stringRemoveDelimiter(char delimiter, const char *string) 81 | { 82 | int string_start = 0; 83 | 84 | while (string[string_start] == delimiter) 85 | { 86 | string_start++; 87 | } 88 | 89 | if (string_start >= (int)strlen(string)-1) 90 | { 91 | return 0; 92 | } 93 | 94 | return string_start; 95 | } 96 | 97 | inline int getFileExtension(char *filename, char **extension) 98 | { 99 | int string_length = (int)strlen(filename); 100 | 101 | while (filename[string_length--] != '.') 102 | { 103 | if (string_length == 0) 104 | break; 105 | } 106 | 107 | if (string_length > 0) string_length += 2; 108 | 109 | if (string_length == 0) 110 | *extension = NULL; 111 | else 112 | *extension = &filename[string_length]; 113 | 114 | return string_length; 115 | } 116 | 117 | 118 | inline bool checkCmdLineFlag(const int argc, const char **argv, const char *string_ref) 119 | { 120 | bool bFound = false; 121 | 122 | if (argc >= 1) 123 | { 124 | for (int i=1; i < argc; i++) 125 | { 126 | int string_start = stringRemoveDelimiter('-', argv[i]); 127 | const char *string_argv = &argv[i][string_start]; 128 | 129 | const char *equal_pos = strchr(string_argv, '='); 130 | int argv_length = (int)(equal_pos == 0 ? strlen(string_argv) : equal_pos - string_argv); 131 | 132 | int length = (int)strlen(string_ref); 133 | 134 | if (length == argv_length && !STRNCASECMP(string_argv, string_ref, length)) 135 | { 136 | bFound = true; 137 | continue; 138 | } 139 | } 140 | } 141 | 142 | return bFound; 143 | } 144 | 145 | // This function wraps the CUDA Driver API into a template function 146 | template 147 | inline bool getCmdLineArgumentValue(const int argc, const char **argv, const char *string_ref, T *value) 148 | { 149 | bool bFound = false; 150 | 151 | if (argc >= 1) 152 | { 153 | for (int i=1; i < argc; i++) 154 | { 155 | int string_start = stringRemoveDelimiter('-', argv[i]); 156 | const char *string_argv = &argv[i][string_start]; 157 | int length = (int)strlen(string_ref); 158 | 159 | if (!STRNCASECMP(string_argv, string_ref, length)) 160 | { 161 | if (length+1 <= (int)strlen(string_argv)) 162 | { 163 | int auto_inc = (string_argv[length] == '=') ? 1 : 0; 164 | *value = (T)atoi(&string_argv[length + auto_inc]); 165 | } 166 | 167 | bFound = true; 168 | i=argc; 169 | } 170 | } 171 | } 172 | 173 | return bFound; 174 | } 175 | 176 | inline int getCmdLineArgumentInt(const int argc, const char **argv, const char *string_ref) 177 | { 178 | bool bFound = false; 179 | int value = -1; 180 | 181 | if (argc >= 1) 182 | { 183 | for (int i=1; i < argc; i++) 184 | { 185 | int string_start = stringRemoveDelimiter('-', argv[i]); 186 | const char *string_argv = &argv[i][string_start]; 187 | int length = (int)strlen(string_ref); 188 | 189 | if (!STRNCASECMP(string_argv, string_ref, length)) 190 | { 191 | if (length+1 <= (int)strlen(string_argv)) 192 | { 193 | int auto_inc = (string_argv[length] == '=') ? 1 : 0; 194 | value = atoi(&string_argv[length + auto_inc]); 195 | } 196 | else 197 | { 198 | value = 0; 199 | } 200 | 201 | bFound = true; 202 | continue; 203 | } 204 | } 205 | } 206 | 207 | if (bFound) 208 | { 209 | return value; 210 | } 211 | else 212 | { 213 | return 0; 214 | } 215 | } 216 | 217 | inline float getCmdLineArgumentFloat(const int argc, const char **argv, const char *string_ref) 218 | { 219 | bool bFound = false; 220 | float value = -1; 221 | 222 | if (argc >= 1) 223 | { 224 | for (int i=1; i < argc; i++) 225 | { 226 | int string_start = stringRemoveDelimiter('-', argv[i]); 227 | const char *string_argv = &argv[i][string_start]; 228 | int length = (int)strlen(string_ref); 229 | 230 | if (!STRNCASECMP(string_argv, string_ref, length)) 231 | { 232 | if (length+1 <= (int)strlen(string_argv)) 233 | { 234 | int auto_inc = (string_argv[length] == '=') ? 1 : 0; 235 | value = (float)atof(&string_argv[length + auto_inc]); 236 | } 237 | else 238 | { 239 | value = 0.f; 240 | } 241 | 242 | bFound = true; 243 | continue; 244 | } 245 | } 246 | } 247 | 248 | if (bFound) 249 | { 250 | return value; 251 | } 252 | else 253 | { 254 | return 0; 255 | } 256 | } 257 | 258 | inline bool getCmdLineArgumentString(const int argc, const char **argv, 259 | const char *string_ref, char **string_retval) 260 | { 261 | bool bFound = false; 262 | 263 | if (argc >= 1) 264 | { 265 | for (int i=1; i < argc; i++) 266 | { 267 | int string_start = stringRemoveDelimiter('-', argv[i]); 268 | char *string_argv = (char *)&argv[i][string_start]; 269 | int length = (int)strlen(string_ref); 270 | 271 | if (!STRNCASECMP(string_argv, string_ref, length)) 272 | { 273 | *string_retval = &string_argv[length+1]; 274 | bFound = true; 275 | continue; 276 | } 277 | } 278 | } 279 | 280 | if (!bFound) 281 | { 282 | *string_retval = NULL; 283 | } 284 | 285 | return bFound; 286 | } 287 | 288 | ////////////////////////////////////////////////////////////////////////////// 289 | //! Find the path for a file assuming that 290 | //! files are found in the searchPath. 291 | //! 292 | //! @return the path if succeeded, otherwise 0 293 | //! @param filename name of the file 294 | //! @param executable_path optional absolute path of the executable 295 | ////////////////////////////////////////////////////////////////////////////// 296 | inline char *sdkFindFilePath(const char *filename, const char *executable_path) 297 | { 298 | // defines a variable that is replaced with the name of the executable 299 | 300 | // Typical relative search paths to locate needed companion files (e.g. sample input data, or JIT source files) 301 | // The origin for the relative search may be the .exe file, a .bat file launching an .exe, a browser .exe launching the .exe or .bat, etc 302 | const char *searchPath[] = 303 | { 304 | "./", // same dir 305 | "./common/", // "/common/" subdir 306 | "./common/data/", // "/common/data/" subdir 307 | "./data/", // "/data/" subdir 308 | "./src/", // "/src/" subdir 309 | "./src//data/", // "/src//data/" subdir 310 | "./inc/", // "/inc/" subdir 311 | "./0_Simple/", // "/0_Simple/" subdir 312 | "./1_Utilities/", // "/1_Utilities/" subdir 313 | "./2_Graphics/", // "/2_Graphics/" subdir 314 | "./3_Imaging/", // "/3_Imaging/" subdir 315 | "./4_Financial/", // "/4_Financial/" subdir 316 | "./5_Simulations/", // "/5_Simulations/" subdir 317 | "./6_Advanced/", // "/6_Advanced/" subdir 318 | "./7_CUDALibraries/", // "/7_CUDALibraries/" subdir 319 | "./8_Android/", // "/8_Android/" subdir 320 | "./samples/", // "/samples/" subdir 321 | 322 | "../", // up 1 in tree 323 | "../common/", // up 1 in tree, "/common/" subdir 324 | "../common/data/", // up 1 in tree, "/common/data/" subdir 325 | "../data/", // up 1 in tree, "/data/" subdir 326 | "../src/", // up 1 in tree, "/src/" subdir 327 | "../inc/", // up 1 in tree, "/inc/" subdir 328 | 329 | "../0_Simple//data/", // up 1 in tree, "/0_Simple//" subdir 330 | "../1_Utilities//data/", // up 1 in tree, "/1_Utilities//" subdir 331 | "../2_Graphics//data/", // up 1 in tree, "/2_Graphics//" subdir 332 | "../3_Imaging//data/", // up 1 in tree, "/3_Imaging//" subdir 333 | "../4_Financial//data/", // up 1 in tree, "/4_Financial//" subdir 334 | "../5_Simulations//data/", // up 1 in tree, "/5_Simulations//" subdir 335 | "../6_Advanced//data/", // up 1 in tree, "/6_Advanced//" subdir 336 | "../7_CUDALibraries//data/",// up 1 in tree, "/7_CUDALibraries//" subdir 337 | "../8_Android//data/", // up 1 in tree, "/8_Android//" subdir 338 | "../samples//data/", // up 1 in tree, "/samples//" subdir 339 | "../../", // up 2 in tree 340 | "../../common/", // up 2 in tree, "/common/" subdir 341 | "../../common/data/", // up 2 in tree, "/common/data/" subdir 342 | "../../data/", // up 2 in tree, "/data/" subdir 343 | "../../src/", // up 2 in tree, "/src/" subdir 344 | "../../inc/", // up 2 in tree, "/inc/" subdir 345 | "../../sandbox//data/", // up 2 in tree, "/sandbox//" subdir 346 | "../../0_Simple//data/", // up 2 in tree, "/0_Simple//" subdir 347 | "../../1_Utilities//data/", // up 2 in tree, "/1_Utilities//" subdir 348 | "../../2_Graphics//data/", // up 2 in tree, "/2_Graphics//" subdir 349 | "../../3_Imaging//data/", // up 2 in tree, "/3_Imaging//" subdir 350 | "../../4_Financial//data/", // up 2 in tree, "/4_Financial//" subdir 351 | "../../5_Simulations//data/", // up 2 in tree, "/5_Simulations//" subdir 352 | "../../6_Advanced//data/", // up 2 in tree, "/6_Advanced//" subdir 353 | "../../7_CUDALibraries//data/", // up 2 in tree, "/7_CUDALibraries//" subdir 354 | "../../8_Android//data/", // up 2 in tree, "/8_Android//" subdir 355 | "../../samples//data/", // up 2 in tree, "/samples//" subdir 356 | "../../../", // up 3 in tree 357 | "../../../src//", // up 3 in tree, "/src//" subdir 358 | "../../../src//data/", // up 3 in tree, "/src//data/" subdir 359 | "../../../src//src/", // up 3 in tree, "/src//src/" subdir 360 | "../../../src//inc/", // up 3 in tree, "/src//inc/" subdir 361 | "../../../sandbox//", // up 3 in tree, "/sandbox//" subdir 362 | "../../../sandbox//data/", // up 3 in tree, "/sandbox//data/" subdir 363 | "../../../sandbox//src/", // up 3 in tree, "/sandbox//src/" subdir 364 | "../../../sandbox//inc/", // up 3 in tree, "/sandbox//inc/" subdir 365 | "../../../0_Simple//data/", // up 3 in tree, "/0_Simple//" subdir 366 | "../../../1_Utilities//data/", // up 3 in tree, "/1_Utilities//" subdir 367 | "../../../2_Graphics//data/", // up 3 in tree, "/2_Graphics//" subdir 368 | "../../../3_Imaging//data/", // up 3 in tree, "/3_Imaging//" subdir 369 | "../../../4_Financial//data/", // up 3 in tree, "/4_Financial//" subdir 370 | "../../../5_Simulations//data/", // up 3 in tree, "/5_Simulations//" subdir 371 | "../../../6_Advanced//data/", // up 3 in tree, "/6_Advanced//" subdir 372 | "../../../7_CUDALibraries//data/", // up 3 in tree, "/7_CUDALibraries//" subdir 373 | "../../../8_Android//data/", // up 3 in tree, "/8_Android//" subdir 374 | "../../../samples//data/", // up 3 in tree, "/samples//" subdir 375 | "../../../common/", // up 3 in tree, "../../../common/" subdir 376 | "../../../common/data/", // up 3 in tree, "../../../common/data/" subdir 377 | "../../../data/", // up 3 in tree, "../../../data/" subdir 378 | "../../../../", // up 4 in tree 379 | "../../../../src//", // up 4 in tree, "/src//" subdir 380 | "../../../../src//data/", // up 4 in tree, "/src//data/" subdir 381 | "../../../../src//src/", // up 4 in tree, "/src//src/" subdir 382 | "../../../../src//inc/", // up 4 in tree, "/src//inc/" subdir 383 | "../../../../sandbox//", // up 4 in tree, "/sandbox//" subdir 384 | "../../../../sandbox//data/", // up 4 in tree, "/sandbox//data/" subdir 385 | "../../../../sandbox//src/", // up 4 in tree, "/sandbox//src/" subdir 386 | "../../../../sandbox//inc/", // up 4 in tree, "/sandbox//inc/" subdir 387 | "../../../../0_Simple//data/", // up 4 in tree, "/0_Simple//" subdir 388 | "../../../../1_Utilities//data/", // up 4 in tree, "/1_Utilities//" subdir 389 | "../../../../2_Graphics//data/", // up 4 in tree, "/2_Graphics//" subdir 390 | "../../../../3_Imaging//data/", // up 4 in tree, "/3_Imaging//" subdir 391 | "../../../../4_Financial//data/", // up 4 in tree, "/4_Financial//" subdir 392 | "../../../../5_Simulations//data/",// up 4 in tree, "/5_Simulations//" subdir 393 | "../../../../6_Advanced//data/", // up 4 in tree, "/6_Advanced//" subdir 394 | "../../../../7_CUDALibraries//data/", // up 4 in tree, "/7_CUDALibraries//" subdir 395 | "../../../../8_Android//data/", // up 4 in tree, "/8_Android//" subdir 396 | "../../../../samples//data/", // up 4 in tree, "/samples//" subdir 397 | "../../../../common/", // up 4 in tree, "../../../common/" subdir 398 | "../../../../common/data/", // up 4 in tree, "../../../common/data/" subdir 399 | "../../../../data/", // up 4 in tree, "../../../data/" subdir 400 | "../../../../../", // up 5 in tree 401 | "../../../../../src//", // up 5 in tree, "/src//" subdir 402 | "../../../../../src//data/", // up 5 in tree, "/src//data/" subdir 403 | "../../../../../src//src/", // up 5 in tree, "/src//src/" subdir 404 | "../../../../../src//inc/", // up 5 in tree, "/src//inc/" subdir 405 | "../../../../../sandbox//", // up 5 in tree, "/sandbox//" subdir 406 | "../../../../../sandbox//data/", // up 5 in tree, "/sandbox//data/" subdir 407 | "../../../../../sandbox//src/", // up 5 in tree, "/sandbox//src/" subdir 408 | "../../../../../sandbox//inc/", // up 5 in tree, "/sandbox//inc/" subdir 409 | "../../../../../0_Simple//data/", // up 5 in tree, "/0_Simple//" subdir 410 | "../../../../../1_Utilities//data/", // up 5 in tree, "/1_Utilities//" subdir 411 | "../../../../../2_Graphics//data/", // up 5 in tree, "/2_Graphics//" subdir 412 | "../../../../../3_Imaging//data/", // up 5 in tree, "/3_Imaging//" subdir 413 | "../../../../../4_Financial//data/", // up 5 in tree, "/4_Financial//" subdir 414 | "../../../../../5_Simulations//data/",// up 5 in tree, "/5_Simulations//" subdir 415 | "../../../../../6_Advanced//data/", // up 5 in tree, "/6_Advanced//" subdir 416 | "../../../../../7_CUDALibraries//data/", // up 5 in tree, "/7_CUDALibraries//" subdir 417 | "../../../../../8_Android//data/", // up 5 in tree, "/8_Android//" subdir 418 | "../../../../../samples//data/", // up 5 in tree, "/samples//" subdir 419 | "../../../../../common/", // up 5 in tree, "../../../common/" subdir 420 | "../../../../../common/data/", // up 5 in tree, "../../../common/data/" subdir 421 | }; 422 | 423 | // Extract the executable name 424 | std::string executable_name; 425 | 426 | if (executable_path != 0) 427 | { 428 | executable_name = std::string(executable_path); 429 | 430 | #if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64) 431 | // Windows path delimiter 432 | size_t delimiter_pos = executable_name.find_last_of('\\'); 433 | executable_name.erase(0, delimiter_pos + 1); 434 | 435 | if (executable_name.rfind(".exe") != std::string::npos) 436 | { 437 | // we strip .exe, only if the .exe is found 438 | executable_name.resize(executable_name.size() - 4); 439 | } 440 | 441 | #else 442 | // Linux & OSX path delimiter 443 | size_t delimiter_pos = executable_name.find_last_of('/'); 444 | executable_name.erase(0,delimiter_pos+1); 445 | #endif 446 | } 447 | 448 | // Loop over all search paths and return the first hit 449 | for (unsigned int i = 0; i < sizeof(searchPath)/sizeof(char *); ++i) 450 | { 451 | std::string path(searchPath[i]); 452 | size_t executable_name_pos = path.find(""); 453 | 454 | // If there is executable_name variable in the searchPath 455 | // replace it with the value 456 | if (executable_name_pos != std::string::npos) 457 | { 458 | if (executable_path != 0) 459 | { 460 | path.replace(executable_name_pos, strlen(""), executable_name); 461 | } 462 | else 463 | { 464 | // Skip this path entry if no executable argument is given 465 | continue; 466 | } 467 | } 468 | 469 | #ifdef _DEBUG 470 | printf("sdkFindFilePath <%s> in %s\n", filename, path.c_str()); 471 | #endif 472 | 473 | // Test if the file exists 474 | path.append(filename); 475 | FILE *fp; 476 | FOPEN(fp, path.c_str(), "rb"); 477 | 478 | if (fp != NULL) 479 | { 480 | fclose(fp); 481 | // File found 482 | // returning an allocated array here for backwards compatibility reasons 483 | char *file_path = (char *) malloc(path.length() + 1); 484 | STRCPY(file_path, path.length() + 1, path.c_str()); 485 | return file_path; 486 | } 487 | 488 | if (fp) 489 | { 490 | fclose(fp); 491 | } 492 | } 493 | 494 | // File not found 495 | return 0; 496 | } 497 | 498 | #endif 499 | -------------------------------------------------------------------------------- /imageinfo.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "managed.h" 3 | 4 | class __align__(128) ImageInfo : public Managed{ 5 | public: 6 | // Image size 7 | int cols; 8 | int rows; 9 | 10 | // Total number of pixels 11 | int np; 12 | 13 | // Total number of bytes (may be different when padded) 14 | int nb; 15 | }; 16 | -------------------------------------------------------------------------------- /linestate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include // memset() 3 | #include "algorithmparameters.h" 4 | #include "cameraparameters.h" 5 | #include "managed.h" 6 | #include // float4 7 | 8 | class __align__(128) LineState : public Managed { 9 | public: 10 | float4 *norm4; // 3 values for normal and last for d 11 | float *c; // cost 12 | /*float *disp; // disparity*/ 13 | int n; 14 | int s; // stride 15 | int l; // length 16 | void resize(int n) 17 | { 18 | cudaMallocManaged (&c, sizeof(float) * n); 19 | /*cudaMallocManaged (&disp, sizeof(float) * n);*/ 20 | cudaMallocManaged (&norm4, sizeof(float4) * n); 21 | memset (c, 0, sizeof(float) * n); 22 | /*memset (disp, 0, sizeof(float) * n);*/ 23 | memset (norm4, 0, sizeof(float4) * n); 24 | } 25 | ~LineState() 26 | { 27 | cudaFree (c); 28 | cudaFree (norm4); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /main.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef _WIN32 4 | #define NOMINMAX 5 | #include 6 | #include 7 | #endif 8 | 9 | #include "opencv2/calib3d/calib3d.hpp" 10 | #include "opencv2/imgproc/imgproc.hpp" 11 | #include "opencv2/core/core.hpp" 12 | #include "opencv2/highgui/highgui.hpp" 13 | //#include "opencv2/contrib/contrib.hpp" 14 | #if CV_MAJOR_VERSION == 3 15 | #include "opencv2/core/utility.hpp" 16 | #endif 17 | 18 | #include 19 | #include 20 | 21 | using namespace cv; 22 | using namespace std; 23 | 24 | typedef Vec Vec2us; 25 | 26 | // parameters for comparison with ground truth 27 | struct GTcheckParameters { 28 | GTcheckParameters () : gtCheck ( false ), noccCheck ( false ), scale ( 150.0f ), dispTolGT ( 0.5f ), divFactor ( 4.0f ) {} 29 | bool gtCheck; 30 | bool noccCheck; 31 | float scale; // scaling factor just for visualization of error 32 | float dispTolGT; 33 | float dispTolGT2; 34 | //division factor dependent on ground truth data (to get disparity value: imgValue/divFactor) 35 | float divFactor; //Middleburry small images: 4, big images third: 3, Kitti: 255 36 | }; 37 | 38 | //pathes to input images (camera images, ground truth, ...) 39 | struct InputFiles { 40 | InputFiles () : gt_filename ( "" ), gt_nocc_filename ( "" ), occ_filename ( "" ), gt_normal_filename ( "" ), calib_filename ( "" ), images_folder ( "" ), p_folder ( "" ), camera_folder ( "" ),krt_file(""), pmvs_folder("") {} 41 | vector img_filenames; // input camera images (only filenames, path is set in images_folder), names can also be used for calibration data (e.g. for Strecha P, camera) 42 | string gt_filename; // ground truth image 43 | string gt_nocc_filename; // non-occluded ground truth image (as provided e.g. by Kitti) 44 | string occ_filename; // occlusion mask (binary map of all the points that are occluded) (as provided e.g. by Middleburry) 45 | string gt_normal_filename; // ground truth normal map (for Strecha) 46 | string calib_filename; // calibration file containing camera matrices (P) (as provided e.g. by Kitti) 47 | string images_folder; // path to camera input images 48 | string p_folder; // path to camera projection matrix P (Strecha) 49 | string camera_folder; // path to camera calibration matrix K (Strecha) 50 | string krt_file; // path to camera matrixes in middlebury format 51 | string bounding_folder; //path to bounding volume (Strecha) 52 | string seed_file; // path to bounding volume (Strecha) 53 | string pmvs_folder; // path to pmvs folder 54 | }; 55 | 56 | //pathes to output files 57 | struct OutputFiles { 58 | OutputFiles () : parentFolder ( "results" ), disparity_filename ( 0 ) {} 59 | const char* parentFolder; 60 | char* disparity_filename; 61 | }; 62 | 63 | //parameters of algorithms 64 | //struct AlgorithmParameters { 65 | //AlgorithmParameters () : algorithm ( PM_COST ), max_disparity ( 256.0f ), min_disparity ( 0.0f ), box_hsize ( 15 ), box_vsize ( 15 ), tau_color ( 10.0f ), tau_gradient ( 2.0f ), alpha ( 0.9f ), gamma ( 10.0f ), border_value ( -1 ), iterations ( 3 ), color_processing ( false ), dispTol ( 1.0f ), normTol ( 0.1f ), census_epsilon ( 2.5f ), self_similarity_n ( 50 ), cam_scale ( 1.0f ), num_img_processed ( 1 ), costThresh ( 40.0f ), n_best ( 2 ), viewSelection ( false ), good_factor ( 1.8f ), cost_comb ( COMB_BEST_N ), depthMin ( 2.0f ), depthMax ( 20.0f ) {} 66 | //int algorithm; // algorithm cost type 67 | //float max_disparity; // maximal disparity value 68 | //float min_disparity; // minimum disparity value (default 0) 69 | //int box_hsize; // filter kernel width 70 | //int box_vsize; // filter kernel height 71 | //float tau_color; // PM_COST max. threshold for color 72 | //float tau_gradient; // PM_COST max. threshold for gradient 73 | //float alpha; // PM_COST weighting between color and gradient 74 | //float gamma; // parameter for weight function (used e.g. in PM_COST) 75 | //int border_value; // what value should pixel at extended border get (constant or replicate -1) 76 | //int iterations; // number of iterations 77 | //bool color_processing; // use color processing or not (otherwise just grayscale processing) 78 | //float dispTol; //PM Stereo: 1, PM Huber: 0.5 79 | //float normTol; // 0.1 ... about 5.7 degrees 80 | //float census_epsilon; //for census transform 81 | //int self_similarity_n; // number of pixels considered for self similarity 82 | //float cam_scale; //used to rescale K in case of rescaled image size 83 | //int num_img_processed; //number of images that are processed as reference images 84 | //float costThresh; // threshold to decide whether disparity/depth is valid or not 85 | //float good_factor; // for cost aggregation/combination good: factor for truncation 86 | //int n_best; 87 | //int cost_comb; 88 | //bool viewSelection; 89 | //float depthMin; 90 | //float depthMax; 91 | //}; 92 | 93 | struct Camera { 94 | Camera () : P ( Mat::eye ( 3,4,CV_32F ) ), R ( Mat::eye ( 3,3,CV_32F ) ),baseline (0.54f), reference ( false ), depthMin ( 2.0f ), depthMax ( 20.0f ) {} 95 | Mat_ P; 96 | Mat_ P_inv; 97 | Mat_ M_inv; 98 | //Mat_ K; 99 | Mat_ R; 100 | Mat_ R_orig_inv; 101 | Mat_ t; 102 | Vec3f C; 103 | float baseline; 104 | bool reference; 105 | float depthMin; //this could be figured out from the bounding volume (not done right now, but that's why this parameter is here as well and not only in AlgorithmParameters) 106 | float depthMax; //this could be figured out from the bounding volume (not done right now, but that's why this parameter is here as well and not only in AlgorithmParameters) 107 | //int id; //corresponds to the image name id (eg. 0-10), independent of order in argument list, just dependent on name 108 | string id; 109 | Mat_ K; 110 | Mat_ K_inv; 111 | //float f; 112 | }; 113 | 114 | //parameters for camera geometry setup (assuming that K1 = K2 = K, P1 = K [I | 0] and P2 = K [R | t]) 115 | struct CameraParameters { 116 | CameraParameters () : rectified ( false ), idRef ( 0 ) {} 117 | Mat_ K; //if K varies from camera to camera: K and f need to be stored within Camera 118 | Mat_ K_inv; //if K varies from camera to camera: K and f need to be stored within Camera 119 | float f; 120 | bool rectified; 121 | vector cameras; 122 | int idRef; 123 | vector viewSelectionSubset; 124 | }; 125 | 126 | struct Results { 127 | Results () : error_occ ( 1.0f ), error_noc ( 1.0f ), valid_pixels ( 0.0f ), error_valid ( 1.0f ), error_valid_all ( 1.0f ), total_runtime ( 0.0f ), runtime_per_pixel ( 0.0f ) {} 128 | float error_occ; 129 | float error_noc; 130 | float valid_pixels; // passed occlusion check 131 | float valid_pixels_gt; 132 | float error_valid; 133 | float error_valid_all; 134 | double total_runtime; 135 | double runtime_per_pixel; 136 | }; 137 | 138 | struct Plane { 139 | Mat_ normal; 140 | Mat_ d; 141 | void release () { 142 | normal.release (); 143 | d.release (); 144 | } 145 | }; 146 | -------------------------------------------------------------------------------- /managed.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "helper_cuda.h" 4 | 5 | class Managed { 6 | public: 7 | void *operator new(size_t len) { 8 | void *ptr; 9 | checkCudaErrors(cudaMallocManaged(&ptr, len)); 10 | return ptr; 11 | } 12 | 13 | void operator delete(void *ptr) { 14 | cudaFree(ptr); 15 | } 16 | }; 17 | -------------------------------------------------------------------------------- /mathUtils.h: -------------------------------------------------------------------------------- 1 | /* 2 | * some math helper functions 3 | */ 4 | 5 | #pragma once 6 | 7 | #ifndef M_PI 8 | #define M_PI 3.14159265358979323846f 9 | #endif 10 | #define M_PI_float 3.14159265358979323846f 11 | 12 | /* get angle between two vectors in 3D 13 | * Input: v1,v2 - vectors 14 | * Output: angle in radian 15 | */ 16 | static float getAngle ( Vec3f v1, Vec3f v2 ) { 17 | float angle = acosf ( v1.dot ( v2 ) ); 18 | //if angle is not a number the dot product was 1 and thus the two vectors should be identical --> return 0 19 | if ( angle != angle ) 20 | return 0.0f; 21 | //if ( acosf ( v1.dot ( v2 ) ) != acosf ( v1.dot ( v2 ) ) ) 22 | //cout << acosf ( v1.dot ( v2 ) ) << " / " << v1.dot ( v2 )<< " / " << v1<< " / " << v2 << endl; 23 | return angle; 24 | } 25 | 26 | -------------------------------------------------------------------------------- /readmeWindows.txt: -------------------------------------------------------------------------------- 1 | things that needed to be considered when creating the VS 2012 project (Windows): 2 | 3 | windows.h in gipuma.cu (otherwise OpenGL Error) 4 | 5 | direct.h, ctime.h in main.cpp (for mkdir) 6 | 7 | opencv includes for applyColorMap in displayUtils.h 8 | #include 9 | //#include 10 | //#include 11 | 12 | at least for VS 2012 (maybe not any more for VS 2013) not all C++11 functions are already supported 13 | eg. in class variable declaration (int xyz = 0;) 14 | had to be changed in algorithmparameters.h, camera.h and cameraparameters.h 15 | 16 | uint8_t not known (in gipuma.cu) --> include 17 | 18 | globalstate - use pointers! 19 | 20 | Libs: (armadillo), OpenCV 21 | 22 | 23 | Error vc110.pdb not loaded or so - no idea how i fixed it, probably properties config was wrong/missing something 24 | 25 | Error Linker Error runcuda - return type of runcuda differed in .h and .cu 26 | 27 | 28 | 29 | CUDA: 30 | 31 | Parameters: 32 | possibly need to set -rdc=true for dynamic parallelism (in CUDA C/C++ >> Common) 33 | Code Generation: at least compute_35,sm_35 maybe even compute_52,sm_52 (in CUDA C/C++ >> Device) 34 | verbose PTXAS Output (to see printf from device) (in CUDA C/C++ >> Device) 35 | -------------------------------------------------------------------------------- /scripts/dino.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | inputdir="data/dino/" 5 | batch_name="dino" 6 | output_dir_basename="results/$batch_name" 7 | p_folder="data/dino/dino_par.txt" 8 | scale=1 9 | blocksize=11 10 | iter=8 11 | cost_gamma=10 12 | cost_comb="best_n" 13 | n_best=3 14 | depth_max=0.8 15 | depth_min=0.3 16 | image_list_array=`( cd $inputdir && ls *.png) ` 17 | output_dir=${output_dir_basename}/ 18 | 19 | # fuse options 20 | disp_thresh=0.1 21 | normal_thresh=30 22 | num_consistent=3 23 | min_angle=10 24 | max_angle=30 25 | 26 | #warping conf 27 | count=0 28 | for im in $image_list_array 29 | do 30 | echo $count 31 | img=${im%.png} 32 | cmd_file=${output_dir}/$img-cmd.log 33 | image_list=( $im ) 34 | 35 | mkdir -p $output_dir 36 | for ij in $image_list_array 37 | do 38 | if [ $im != $ij ] 39 | then 40 | image_list+=( $ij ) 41 | fi 42 | done 43 | cmd="$prog ${image_list[@]} -images_folder $inputdir -krt_file $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min --min_angle=$min_angle --max_angle=$max_angle" 44 | echo $cmd 45 | $cmd 46 | let "count += 1" 47 | if [ $count -eq -1 ] 48 | then 49 | break 50 | fi 51 | done 52 | echo $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 53 | $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent -remove_black_background 54 | -------------------------------------------------------------------------------- /scripts/dinoRing.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | inputdir="data/dinoRing/" 5 | batch_name="dinoRing" 6 | output_dir_basename="results/$batch_name" 7 | p_folder="data/dinoRing/dinoR_par.txt" 8 | scale=1 9 | blocksize=11 10 | iter=8 11 | cost_gamma=10 12 | cost_comb="best_n" 13 | n_best=3 14 | depth_max=0.8 15 | depth_min=0.3 16 | image_list_array=`( cd $inputdir && ls *.png) ` 17 | output_dir=${output_dir_basename}/ 18 | 19 | # fuse options 20 | disp_thresh=0.5 21 | normal_thresh=30 22 | num_consistent=3 23 | min_angle=5 24 | max_angle=45 25 | 26 | #warping conf 27 | count=0 28 | for im in $image_list_array 29 | do 30 | echo $count 31 | img=${im%.png} 32 | cmd_file=${output_dir}/$img-cmd.log 33 | image_list=( $im ) 34 | 35 | mkdir -p $output_dir 36 | for ij in $image_list_array 37 | do 38 | if [ $im != $ij ] 39 | then 40 | image_list+=( $ij ) 41 | fi 42 | done 43 | cmd="$prog ${image_list[@]} -images_folder $inputdir -krt_file $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min --min_angle=$min_angle --max_angle=$max_angle" 44 | echo $cmd 45 | $cmd 46 | let "count += 1" 47 | if [ $count -eq -1 ] 48 | then 49 | break 50 | fi 51 | done 52 | echo $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 53 | $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent -remove_black_background 54 | -------------------------------------------------------------------------------- /scripts/dinoSparseRing.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | inputdir="data/dinoSparseRing/" 5 | batch_name="dinoSparseRing" 6 | output_dir_basename="results/$batch_name" 7 | p_folder="data/dinoSparseRing/dinoSR_par.txt" 8 | scale=1 9 | blocksize=11 10 | iter=8 11 | cost_gamma=10 12 | cost_comb="best_n" 13 | n_best=2 14 | depth_max=0.8 15 | depth_min=0.3 16 | image_list_array=`( cd $inputdir && ls *.png) ` 17 | output_dir=${output_dir_basename}/ 18 | 19 | # fuse options 20 | disp_thresh=0.5 21 | normal_thresh=30 22 | num_consistent=1 23 | min_angle=5 24 | max_angle=70 25 | 26 | #warping conf 27 | count=0 28 | for im in $image_list_array 29 | do 30 | echo $count 31 | img=${im%.png} 32 | cmd_file=${output_dir}/$img-cmd.log 33 | image_list=( $im ) 34 | 35 | mkdir -p $output_dir 36 | for ij in $image_list_array 37 | do 38 | if [ $im != $ij ] 39 | then 40 | image_list+=( $ij ) 41 | fi 42 | done 43 | cmd="$prog ${image_list[@]} -images_folder $inputdir -krt_file $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min --min_angle=$min_angle --max_angle=$max_angle" 44 | echo $cmd 45 | $cmd 46 | let "count += 1" 47 | if [ $count -eq -1 ] 48 | then 49 | break 50 | fi 51 | done 52 | echo $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 53 | $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent -remove_black_background 54 | -------------------------------------------------------------------------------- /scripts/download-dtu.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | UNZIP_DIR="./data/dtu/" 3 | 4 | function download_and_unzip() { 5 | TMPFILE=`mktemp` 6 | wget "$1" -O $TMPFILE 7 | unzip -d $UNZIP_DIR $TMPFILE 8 | rm $TMPFILE 9 | } 10 | mkdir -p $UNZIP_DIR 11 | 12 | download_and_unzip http://roboimagedata2.compute.dtu.dk/data/MVS/SampleSet.zip 13 | -------------------------------------------------------------------------------- /scripts/download-middlebury.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | UNZIP_DIR="./data/" 3 | 4 | function download_and_unzip() { 5 | TMPFILE=`mktemp` 6 | wget "$1" -O $TMPFILE 7 | unzip -d $UNZIP_DIR $TMPFILE 8 | rm $TMPFILE 9 | } 10 | mkdir -p $UNZIP_DIR 11 | 12 | download_and_unzip http://vision.middlebury.edu/mview/data/data/temple.zip 13 | download_and_unzip http://vision.middlebury.edu/mview/data/data/templeRing.zip 14 | download_and_unzip http://vision.middlebury.edu/mview/data/data/templeSparseRing.zip 15 | 16 | download_and_unzip http://vision.middlebury.edu/mview/data/data/dino.zip 17 | download_and_unzip http://vision.middlebury.edu/mview/data/data/dinoRing.zip 18 | download_and_unzip http://vision.middlebury.edu/mview/data/data/dinoSparseRing.zip 19 | -------------------------------------------------------------------------------- /scripts/dtu_accurate.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | #inputdir="/home/gsilvano/data/DTURobotImageDataSets/SampleSet1/scan1/resize50/" 5 | inputdir="data/dtu/SampleSet/MVS Data/Rectified/scan${1}/" 6 | batch_name="dtu_accurate_${1}" 7 | output_dir_basename="results/$batch_name" 8 | p_folder="data/dtu/calib/" 9 | scale=1 10 | blocksize=25 11 | iter=8 12 | cost_gamma=10 13 | cost_comb="best_n" 14 | n_best=3 15 | depth_max=800 16 | depth_min=300 17 | image_list_array=`( cd "$inputdir" && ls *_3_*) ` 18 | output_dir=${output_dir_basename}/$i/ 19 | min_angle=10 20 | max_angle=30 21 | 22 | # fuse options 23 | disp_thresh=0.1 24 | normal_thresh=30 25 | num_consistent=3 26 | 27 | #warping conf 28 | count=0 29 | for im in $image_list_array 30 | do 31 | echo $count 32 | img=${im%.png} 33 | cmd_file=${output_dir}/$img-cmd.log 34 | image_list=( $im ) 35 | 36 | mkdir -p $output_dir 37 | for ij in $image_list_array 38 | do 39 | if [ $im != $ij ] 40 | then 41 | image_list+=( $ij ) 42 | fi 43 | done 44 | quotedinput=`echo $inputdir | sed "s/ /\\\\ /"` 45 | echo -n $quotedinput 46 | 47 | echo $prog ${image_list[@]} -images_folder "$inputdir" -p_folder $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min -view_selection --min_angle=$min_angle --max_angle=$max_angle 48 | $prog ${image_list[@]} -images_folder "$inputdir" -p_folder $p_folder -output_folder $output_dir -no_display --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min -view_selection --min_angle=$min_angle --max_angle=$max_angle 49 | let "count += 1" 50 | if [ $count -eq -1 ] 51 | then 52 | break 53 | fi 54 | done 55 | echo $warping -input_folder $output_dir -p_folder $p_folder -images_folder "$inputdir" --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 56 | $warping -input_folder $output_dir -p_folder $p_folder -images_folder "$inputdir" --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 57 | -------------------------------------------------------------------------------- /scripts/dtu_fast.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | #inputdir="/home/gsilvano/data/DTURobotImageDataSets/SampleSet1/scan1/resize50/" 5 | inputdir="data/dtu/SampleSet/MVS Data/Rectified/scan${1}/" 6 | batch_name="dtu_fast_${1}" 7 | output_dir_basename="results/$batch_name" 8 | p_folder="data/dtu/calib/" 9 | scale=1 10 | blocksize=15 11 | iter=6 12 | cost_gamma=10 13 | cost_comb="best_n" 14 | n_best=3 15 | depth_max=800 16 | depth_min=300 17 | image_list_array=`( cd "$inputdir" && ls *_3_*) ` 18 | output_dir=${output_dir_basename}/$i/ 19 | min_angle=10 20 | max_angle=30 21 | max_views=9 22 | 23 | # fuse options 24 | disp_thresh=0.1 25 | normal_thresh=30 26 | num_consistent=3 27 | 28 | #warping conf 29 | count=0 30 | for im in $image_list_array 31 | do 32 | echo $count 33 | img=${im%.png} 34 | cmd_file=${output_dir}/$img-cmd.log 35 | image_list=( $im ) 36 | 37 | mkdir -p $output_dir 38 | for ij in $image_list_array 39 | do 40 | if [ $im != $ij ] 41 | then 42 | image_list+=( $ij ) 43 | fi 44 | done 45 | quotedinput=`echo $inputdir | sed "s/ /\\\\ /"` 46 | echo -n $quotedinput 47 | 48 | echo $prog ${image_list[@]} -images_folder "$inputdir" -p_folder $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min -view_selection --min_angle=$min_angle --max_angle=$max_angle --max_views=$max_views 49 | $prog ${image_list[@]} -images_folder "$inputdir" -p_folder $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min -view_selection --min_angle=$min_angle --max_angle=$max_angle --max_views=$max_views 50 | let "count += 1" 51 | if [ $count -eq -1 ] 52 | then 53 | break 54 | fi 55 | done 56 | echo $warping -input_folder $output_dir -p_folder $p_folder -images_folder "$inputdir" --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 57 | $warping -input_folder $output_dir -p_folder $p_folder -images_folder "$inputdir" --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 58 | -------------------------------------------------------------------------------- /scripts/temple.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | inputdir="data/temple" 5 | batch_name="temple" 6 | output_dir_basename="results/$batch_name" 7 | p_folder="data/temple/temple_par.txt" 8 | scale=1 9 | blocksize=11 10 | iter=8 11 | cost_gamma=10 12 | cost_comb="best_n" 13 | n_best=3 14 | depth_max=0.8 15 | depth_min=0.3 16 | image_list_array=`( cd $inputdir && ls *.png) ` 17 | output_dir=${output_dir_basename}/ 18 | 19 | # fuse options 20 | disp_thresh=0.1 21 | normal_thresh=30 22 | num_consistent=3 23 | min_angle=10 24 | max_angle=30 25 | 26 | #warping conf 27 | count=0 28 | for im in $image_list_array 29 | do 30 | echo $count 31 | img=${im%.png} 32 | cmd_file=${output_dir}/$img-cmd.log 33 | image_list=( $im ) 34 | 35 | mkdir -p $output_dir 36 | for ij in $image_list_array 37 | do 38 | if [ $im != $ij ] 39 | then 40 | image_list+=( $ij ) 41 | fi 42 | done 43 | cmd="$prog ${image_list[@]} -images_folder $inputdir -krt_file $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min --min_angle=$min_angle --max_angle=$max_angle" 44 | echo $cmd 45 | $cmd 46 | let "count += 1" 47 | if [ $count -eq -1 ] 48 | then 49 | break 50 | fi 51 | done 52 | echo $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 53 | $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent -remove_black_background 54 | -------------------------------------------------------------------------------- /scripts/templeRing.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | inputdir="data/templeRing/" 5 | batch_name="templeRing" 6 | output_dir_basename="results/$batch_name" 7 | p_folder="data/templeRing/templeR_par.txt" 8 | scale=1 9 | blocksize=11 10 | iter=8 11 | cost_gamma=10 12 | cost_comb="best_n" 13 | n_best=3 14 | depth_max=0.8 15 | depth_min=0.3 16 | image_list_array=`( cd $inputdir && ls *.png) ` 17 | output_dir=${output_dir_basename}/ 18 | 19 | # fuse options 20 | disp_thresh=0.5 21 | normal_thresh=30 22 | num_consistent=3 23 | min_angle=5 24 | max_angle=45 25 | 26 | #warping conf 27 | count=0 28 | for im in $image_list_array 29 | do 30 | echo $count 31 | img=${im%.png} 32 | cmd_file=${output_dir}/$img-cmd.log 33 | image_list=( $im ) 34 | 35 | mkdir -p $output_dir 36 | for ij in $image_list_array 37 | do 38 | if [ $im != $ij ] 39 | then 40 | image_list+=( $ij ) 41 | fi 42 | done 43 | cmd="$prog ${image_list[@]} -images_folder $inputdir -krt_file $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min --min_angle=$min_angle --max_angle=$max_angle" 44 | echo $cmd 45 | $cmd 46 | let "count += 1" 47 | if [ $count -eq -1 ] 48 | then 49 | break 50 | fi 51 | done 52 | echo $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 53 | $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent -remove_black_background 54 | -------------------------------------------------------------------------------- /scripts/templeSparseRing.sh: -------------------------------------------------------------------------------- 1 | #! 2 | prog="./gipuma" 3 | warping="../fusibile/fusibile" 4 | inputdir="data/templeSparseRing/" 5 | batch_name="templeSparseRing" 6 | output_dir_basename="results/$batch_name" 7 | p_folder="data/templeSparseRing/templeSR_par.txt" 8 | scale=1 9 | blocksize=11 10 | iter=8 11 | cost_gamma=10 12 | cost_comb="best_n" 13 | n_best=2 14 | depth_max=0.8 15 | depth_min=0.3 16 | image_list_array=`( cd $inputdir && ls *.png) ` 17 | output_dir=${output_dir_basename}/ 18 | 19 | # fuse options 20 | disp_thresh=0.5 21 | normal_thresh=30 22 | num_consistent=1 23 | min_angle=5 24 | max_angle=70 25 | 26 | #warping conf 27 | count=0 28 | for im in $image_list_array 29 | do 30 | echo $count 31 | img=${im%.png} 32 | cmd_file=${output_dir}/$img-cmd.log 33 | image_list=( $im ) 34 | 35 | mkdir -p $output_dir 36 | for ij in $image_list_array 37 | do 38 | if [ $im != $ij ] 39 | then 40 | image_list+=( $ij ) 41 | fi 42 | done 43 | cmd="$prog ${image_list[@]} -images_folder $inputdir -krt_file $p_folder -output_folder $output_dir -no_display --cam_scale=$scale --iterations=$iter --blocksize=$blocksize --cost_gamma=$cost_gamma --cost_comb=best_n --n_best=$n_best --depth_max=$depth_max --depth_min=$depth_min --min_angle=$min_angle --max_angle=$max_angle" 44 | echo $cmd 45 | $cmd 46 | let "count += 1" 47 | if [ $count -eq -1 ] 48 | then 49 | break 50 | fi 51 | done 52 | echo $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent 53 | $warping -input_folder $output_dir -krt_file $p_folder -images_folder $inputdir --cam_scale=$scale --depth_min=$depth_min --depth_max=$depth_max --disp_thresh=$disp_thresh --normal_thresh=$normal_thresh --num_consistent=$num_consistent -remove_black_background 54 | -------------------------------------------------------------------------------- /vector_operations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include // float4 3 | static __device__ float4 operator*(float4 a, float4 b) { 4 | return make_float4(a.x*b.x, 5 | a.y*b.y, 6 | a.z*b.z, 7 | 0); 8 | } 9 | static __device__ float4 operator-(float4 a, float4 b) { 10 | return make_float4(a.x-b.x, 11 | a.y-b.y, 12 | a.z-b.z, 13 | 0); 14 | } 15 | static __device__ float4 operator-(float4 a) { 16 | return make_float4(-a.x, 17 | -a.y, 18 | -a.z, 19 | 0); 20 | } 21 | static __device__ float4 operator+(float4 a, float4 b) { 22 | return make_float4(a.x+b.x, 23 | a.y+b.y, 24 | a.z+b.z, 25 | 0); 26 | } 27 | static __device__ float4 operator/(float4 a, float k) { 28 | return make_float4(a.x/k, 29 | a.y/k, 30 | a.z/k, 31 | 0); 32 | } 33 | static __device__ float l1_float4 (float4 a) { 34 | return ( fabsf (a.x) + 35 | fabsf (a.y) + 36 | fabsf (a.z))*0.3333333f; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /win32_dirent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Dirent interface for Microsoft Visual Studio 3 | * 4 | * Copyright (C) 1998-2019 Toni Ronkko 5 | * This file is part of dirent. Dirent may be freely distributed 6 | * under the MIT license. For all details and documentation, see 7 | * https://github.com/tronkko/dirent 8 | */ 9 | #ifndef DIRENT_H 10 | #define DIRENT_H 11 | 12 | /* Hide warnings about unreferenced local functions */ 13 | #if defined(__clang__) 14 | # pragma clang diagnostic ignored "-Wunused-function" 15 | #elif defined(_MSC_VER) 16 | # pragma warning(disable:4505) 17 | #elif defined(__GNUC__) 18 | # pragma GCC diagnostic ignored "-Wunused-function" 19 | #endif 20 | 21 | /* 22 | * Include windows.h without Windows Sockets 1.1 to prevent conflicts with 23 | * Windows Sockets 2.0. 24 | */ 25 | #ifndef WIN32_LEAN_AND_MEAN 26 | # define WIN32_LEAN_AND_MEAN 27 | #endif 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | /* Indicates that d_type field is available in dirent structure */ 41 | #define _DIRENT_HAVE_D_TYPE 42 | 43 | /* Indicates that d_namlen field is available in dirent structure */ 44 | #define _DIRENT_HAVE_D_NAMLEN 45 | 46 | /* Entries missing from MSVC 6.0 */ 47 | #if !defined(FILE_ATTRIBUTE_DEVICE) 48 | # define FILE_ATTRIBUTE_DEVICE 0x40 49 | #endif 50 | 51 | /* File type and permission flags for stat(), general mask */ 52 | #if !defined(S_IFMT) 53 | # define S_IFMT _S_IFMT 54 | #endif 55 | 56 | /* Directory bit */ 57 | #if !defined(S_IFDIR) 58 | # define S_IFDIR _S_IFDIR 59 | #endif 60 | 61 | /* Character device bit */ 62 | #if !defined(S_IFCHR) 63 | # define S_IFCHR _S_IFCHR 64 | #endif 65 | 66 | /* Pipe bit */ 67 | #if !defined(S_IFFIFO) 68 | # define S_IFFIFO _S_IFFIFO 69 | #endif 70 | 71 | /* Regular file bit */ 72 | #if !defined(S_IFREG) 73 | # define S_IFREG _S_IFREG 74 | #endif 75 | 76 | /* Read permission */ 77 | #if !defined(S_IREAD) 78 | # define S_IREAD _S_IREAD 79 | #endif 80 | 81 | /* Write permission */ 82 | #if !defined(S_IWRITE) 83 | # define S_IWRITE _S_IWRITE 84 | #endif 85 | 86 | /* Execute permission */ 87 | #if !defined(S_IEXEC) 88 | # define S_IEXEC _S_IEXEC 89 | #endif 90 | 91 | /* Pipe */ 92 | #if !defined(S_IFIFO) 93 | # define S_IFIFO _S_IFIFO 94 | #endif 95 | 96 | /* Block device */ 97 | #if !defined(S_IFBLK) 98 | # define S_IFBLK 0 99 | #endif 100 | 101 | /* Link */ 102 | #if !defined(S_IFLNK) 103 | # define S_IFLNK 0 104 | #endif 105 | 106 | /* Socket */ 107 | #if !defined(S_IFSOCK) 108 | # define S_IFSOCK 0 109 | #endif 110 | 111 | /* Read user permission */ 112 | #if !defined(S_IRUSR) 113 | # define S_IRUSR S_IREAD 114 | #endif 115 | 116 | /* Write user permission */ 117 | #if !defined(S_IWUSR) 118 | # define S_IWUSR S_IWRITE 119 | #endif 120 | 121 | /* Execute user permission */ 122 | #if !defined(S_IXUSR) 123 | # define S_IXUSR 0 124 | #endif 125 | 126 | /* Read group permission */ 127 | #if !defined(S_IRGRP) 128 | # define S_IRGRP 0 129 | #endif 130 | 131 | /* Write group permission */ 132 | #if !defined(S_IWGRP) 133 | # define S_IWGRP 0 134 | #endif 135 | 136 | /* Execute group permission */ 137 | #if !defined(S_IXGRP) 138 | # define S_IXGRP 0 139 | #endif 140 | 141 | /* Read others permission */ 142 | #if !defined(S_IROTH) 143 | # define S_IROTH 0 144 | #endif 145 | 146 | /* Write others permission */ 147 | #if !defined(S_IWOTH) 148 | # define S_IWOTH 0 149 | #endif 150 | 151 | /* Execute others permission */ 152 | #if !defined(S_IXOTH) 153 | # define S_IXOTH 0 154 | #endif 155 | 156 | /* Maximum length of file name */ 157 | #if !defined(PATH_MAX) 158 | # define PATH_MAX MAX_PATH 159 | #endif 160 | #if !defined(FILENAME_MAX) 161 | # define FILENAME_MAX MAX_PATH 162 | #endif 163 | #if !defined(NAME_MAX) 164 | # define NAME_MAX FILENAME_MAX 165 | #endif 166 | 167 | /* File type flags for d_type */ 168 | #define DT_UNKNOWN 0 169 | #define DT_REG S_IFREG 170 | #define DT_DIR S_IFDIR 171 | #define DT_FIFO S_IFIFO 172 | #define DT_SOCK S_IFSOCK 173 | #define DT_CHR S_IFCHR 174 | #define DT_BLK S_IFBLK 175 | #define DT_LNK S_IFLNK 176 | 177 | /* Macros for converting between st_mode and d_type */ 178 | #define IFTODT(mode) ((mode) & S_IFMT) 179 | #define DTTOIF(type) (type) 180 | 181 | /* 182 | * File type macros. Note that block devices, sockets and links cannot be 183 | * distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are 184 | * only defined for compatibility. These macros should always return false 185 | * on Windows. 186 | */ 187 | #if !defined(S_ISFIFO) 188 | # define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) 189 | #endif 190 | #if !defined(S_ISDIR) 191 | # define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) 192 | #endif 193 | #if !defined(S_ISREG) 194 | # define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) 195 | #endif 196 | #if !defined(S_ISLNK) 197 | # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) 198 | #endif 199 | #if !defined(S_ISSOCK) 200 | # define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) 201 | #endif 202 | #if !defined(S_ISCHR) 203 | # define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) 204 | #endif 205 | #if !defined(S_ISBLK) 206 | # define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) 207 | #endif 208 | 209 | /* Return the exact length of the file name without zero terminator */ 210 | #define _D_EXACT_NAMLEN(p) ((p)->d_namlen) 211 | 212 | /* Return the maximum size of a file name */ 213 | #define _D_ALLOC_NAMLEN(p) ((PATH_MAX)+1) 214 | 215 | 216 | #ifdef __cplusplus 217 | extern "C" { 218 | #endif 219 | 220 | 221 | /* Wide-character version */ 222 | struct _wdirent { 223 | /* Always zero */ 224 | long d_ino; 225 | 226 | /* File position within stream */ 227 | long d_off; 228 | 229 | /* Structure size */ 230 | unsigned short d_reclen; 231 | 232 | /* Length of name without \0 */ 233 | size_t d_namlen; 234 | 235 | /* File type */ 236 | int d_type; 237 | 238 | /* File name */ 239 | wchar_t d_name[PATH_MAX+1]; 240 | }; 241 | typedef struct _wdirent _wdirent; 242 | 243 | struct _WDIR { 244 | /* Current directory entry */ 245 | struct _wdirent ent; 246 | 247 | /* Private file data */ 248 | WIN32_FIND_DATAW data; 249 | 250 | /* True if data is valid */ 251 | int cached; 252 | 253 | /* Win32 search handle */ 254 | HANDLE handle; 255 | 256 | /* Initial directory name */ 257 | wchar_t *patt; 258 | }; 259 | typedef struct _WDIR _WDIR; 260 | 261 | /* Multi-byte character version */ 262 | struct dirent { 263 | /* Always zero */ 264 | long d_ino; 265 | 266 | /* File position within stream */ 267 | long d_off; 268 | 269 | /* Structure size */ 270 | unsigned short d_reclen; 271 | 272 | /* Length of name without \0 */ 273 | size_t d_namlen; 274 | 275 | /* File type */ 276 | int d_type; 277 | 278 | /* File name */ 279 | char d_name[PATH_MAX+1]; 280 | }; 281 | typedef struct dirent dirent; 282 | 283 | struct DIR { 284 | struct dirent ent; 285 | struct _WDIR *wdirp; 286 | }; 287 | typedef struct DIR DIR; 288 | 289 | 290 | /* Dirent functions */ 291 | static DIR *opendir (const char *dirname); 292 | static _WDIR *_wopendir (const wchar_t *dirname); 293 | 294 | static struct dirent *readdir (DIR *dirp); 295 | static struct _wdirent *_wreaddir (_WDIR *dirp); 296 | 297 | static int readdir_r( 298 | DIR *dirp, struct dirent *entry, struct dirent **result); 299 | static int _wreaddir_r( 300 | _WDIR *dirp, struct _wdirent *entry, struct _wdirent **result); 301 | 302 | static int closedir (DIR *dirp); 303 | static int _wclosedir (_WDIR *dirp); 304 | 305 | static void rewinddir (DIR* dirp); 306 | static void _wrewinddir (_WDIR* dirp); 307 | 308 | static int scandir (const char *dirname, struct dirent ***namelist, 309 | int (*filter)(const struct dirent*), 310 | int (*compare)(const struct dirent**, const struct dirent**)); 311 | 312 | static int alphasort (const struct dirent **a, const struct dirent **b); 313 | 314 | static int versionsort (const struct dirent **a, const struct dirent **b); 315 | 316 | 317 | /* For compatibility with Symbian */ 318 | #define wdirent _wdirent 319 | #define WDIR _WDIR 320 | #define wopendir _wopendir 321 | #define wreaddir _wreaddir 322 | #define wclosedir _wclosedir 323 | #define wrewinddir _wrewinddir 324 | 325 | 326 | /* Internal utility functions */ 327 | static WIN32_FIND_DATAW *dirent_first (_WDIR *dirp); 328 | static WIN32_FIND_DATAW *dirent_next (_WDIR *dirp); 329 | 330 | static int dirent_mbstowcs_s( 331 | size_t *pReturnValue, 332 | wchar_t *wcstr, 333 | size_t sizeInWords, 334 | const char *mbstr, 335 | size_t count); 336 | 337 | static int dirent_wcstombs_s( 338 | size_t *pReturnValue, 339 | char *mbstr, 340 | size_t sizeInBytes, 341 | const wchar_t *wcstr, 342 | size_t count); 343 | 344 | static void dirent_set_errno (int error); 345 | 346 | 347 | /* 348 | * Open directory stream DIRNAME for read and return a pointer to the 349 | * internal working area that is used to retrieve individual directory 350 | * entries. 351 | */ 352 | static _WDIR* 353 | _wopendir( 354 | const wchar_t *dirname) 355 | { 356 | _WDIR *dirp; 357 | DWORD n; 358 | wchar_t *p; 359 | 360 | /* Must have directory name */ 361 | if (dirname == NULL || dirname[0] == '\0') { 362 | dirent_set_errno (ENOENT); 363 | return NULL; 364 | } 365 | 366 | /* Allocate new _WDIR structure */ 367 | dirp = (_WDIR*) malloc (sizeof (struct _WDIR)); 368 | if (!dirp) { 369 | return NULL; 370 | } 371 | 372 | /* Reset _WDIR structure */ 373 | dirp->handle = INVALID_HANDLE_VALUE; 374 | dirp->patt = NULL; 375 | dirp->cached = 0; 376 | 377 | /* 378 | * Compute the length of full path plus zero terminator 379 | * 380 | * Note that on WinRT there's no way to convert relative paths 381 | * into absolute paths, so just assume it is an absolute path. 382 | */ 383 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 384 | /* Desktop */ 385 | n = GetFullPathNameW (dirname, 0, NULL, NULL); 386 | #else 387 | /* WinRT */ 388 | n = wcslen (dirname); 389 | #endif 390 | 391 | /* Allocate room for absolute directory name and search pattern */ 392 | dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16); 393 | if (dirp->patt == NULL) { 394 | goto exit_closedir; 395 | } 396 | 397 | /* 398 | * Convert relative directory name to an absolute one. This 399 | * allows rewinddir() to function correctly even when current 400 | * working directory is changed between opendir() and rewinddir(). 401 | * 402 | * Note that on WinRT there's no way to convert relative paths 403 | * into absolute paths, so just assume it is an absolute path. 404 | */ 405 | #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) 406 | /* Desktop */ 407 | n = GetFullPathNameW (dirname, n, dirp->patt, NULL); 408 | if (n <= 0) { 409 | goto exit_closedir; 410 | } 411 | #else 412 | /* WinRT */ 413 | wcsncpy_s (dirp->patt, n+1, dirname, n); 414 | #endif 415 | 416 | /* Append search pattern \* to the directory name */ 417 | p = dirp->patt + n; 418 | switch (p[-1]) { 419 | case '\\': 420 | case '/': 421 | case ':': 422 | /* Directory ends in path separator, e.g. c:\temp\ */ 423 | /*NOP*/; 424 | break; 425 | 426 | default: 427 | /* Directory name doesn't end in path separator */ 428 | *p++ = '\\'; 429 | } 430 | *p++ = '*'; 431 | *p = '\0'; 432 | 433 | /* Open directory stream and retrieve the first entry */ 434 | if (!dirent_first (dirp)) { 435 | goto exit_closedir; 436 | } 437 | 438 | /* Success */ 439 | return dirp; 440 | 441 | /* Failure */ 442 | exit_closedir: 443 | _wclosedir (dirp); 444 | return NULL; 445 | } 446 | 447 | /* 448 | * Read next directory entry. 449 | * 450 | * Returns pointer to static directory entry which may be overwritten by 451 | * subsequent calls to _wreaddir(). 452 | */ 453 | static struct _wdirent* 454 | _wreaddir( 455 | _WDIR *dirp) 456 | { 457 | struct _wdirent *entry; 458 | 459 | /* 460 | * Read directory entry to buffer. We can safely ignore the return value 461 | * as entry will be set to NULL in case of error. 462 | */ 463 | (void) _wreaddir_r (dirp, &dirp->ent, &entry); 464 | 465 | /* Return pointer to statically allocated directory entry */ 466 | return entry; 467 | } 468 | 469 | /* 470 | * Read next directory entry. 471 | * 472 | * Returns zero on success. If end of directory stream is reached, then sets 473 | * result to NULL and returns zero. 474 | */ 475 | static int 476 | _wreaddir_r( 477 | _WDIR *dirp, 478 | struct _wdirent *entry, 479 | struct _wdirent **result) 480 | { 481 | WIN32_FIND_DATAW *datap; 482 | 483 | /* Read next directory entry */ 484 | datap = dirent_next (dirp); 485 | if (datap) { 486 | size_t n; 487 | DWORD attr; 488 | 489 | /* 490 | * Copy file name as wide-character string. If the file name is too 491 | * long to fit in to the destination buffer, then truncate file name 492 | * to PATH_MAX characters and zero-terminate the buffer. 493 | */ 494 | n = 0; 495 | while (n < PATH_MAX && datap->cFileName[n] != 0) { 496 | entry->d_name[n] = datap->cFileName[n]; 497 | n++; 498 | } 499 | entry->d_name[n] = 0; 500 | 501 | /* Length of file name excluding zero terminator */ 502 | entry->d_namlen = n; 503 | 504 | /* File type */ 505 | attr = datap->dwFileAttributes; 506 | if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { 507 | entry->d_type = DT_CHR; 508 | } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { 509 | entry->d_type = DT_DIR; 510 | } else { 511 | entry->d_type = DT_REG; 512 | } 513 | 514 | /* Reset dummy fields */ 515 | entry->d_ino = 0; 516 | entry->d_off = 0; 517 | entry->d_reclen = sizeof (struct _wdirent); 518 | 519 | /* Set result address */ 520 | *result = entry; 521 | 522 | } else { 523 | 524 | /* Return NULL to indicate end of directory */ 525 | *result = NULL; 526 | 527 | } 528 | 529 | return /*OK*/0; 530 | } 531 | 532 | /* 533 | * Close directory stream opened by opendir() function. This invalidates the 534 | * DIR structure as well as any directory entry read previously by 535 | * _wreaddir(). 536 | */ 537 | static int 538 | _wclosedir( 539 | _WDIR *dirp) 540 | { 541 | int ok; 542 | if (dirp) { 543 | 544 | /* Release search handle */ 545 | if (dirp->handle != INVALID_HANDLE_VALUE) { 546 | FindClose (dirp->handle); 547 | } 548 | 549 | /* Release search pattern */ 550 | free (dirp->patt); 551 | 552 | /* Release directory structure */ 553 | free (dirp); 554 | ok = /*success*/0; 555 | 556 | } else { 557 | 558 | /* Invalid directory stream */ 559 | dirent_set_errno (EBADF); 560 | ok = /*failure*/-1; 561 | 562 | } 563 | return ok; 564 | } 565 | 566 | /* 567 | * Rewind directory stream such that _wreaddir() returns the very first 568 | * file name again. 569 | */ 570 | static void 571 | _wrewinddir( 572 | _WDIR* dirp) 573 | { 574 | if (dirp) { 575 | /* Release existing search handle */ 576 | if (dirp->handle != INVALID_HANDLE_VALUE) { 577 | FindClose (dirp->handle); 578 | } 579 | 580 | /* Open new search handle */ 581 | dirent_first (dirp); 582 | } 583 | } 584 | 585 | /* Get first directory entry (internal) */ 586 | static WIN32_FIND_DATAW* 587 | dirent_first( 588 | _WDIR *dirp) 589 | { 590 | WIN32_FIND_DATAW *datap; 591 | DWORD error; 592 | 593 | /* Open directory and retrieve the first entry */ 594 | dirp->handle = FindFirstFileExW( 595 | dirp->patt, FindExInfoStandard, &dirp->data, 596 | FindExSearchNameMatch, NULL, 0); 597 | if (dirp->handle != INVALID_HANDLE_VALUE) { 598 | 599 | /* a directory entry is now waiting in memory */ 600 | datap = &dirp->data; 601 | dirp->cached = 1; 602 | 603 | } else { 604 | 605 | /* Failed to open directory: no directory entry in memory */ 606 | dirp->cached = 0; 607 | datap = NULL; 608 | 609 | /* Set error code */ 610 | error = GetLastError (); 611 | switch (error) { 612 | case ERROR_ACCESS_DENIED: 613 | /* No read access to directory */ 614 | dirent_set_errno (EACCES); 615 | break; 616 | 617 | case ERROR_DIRECTORY: 618 | /* Directory name is invalid */ 619 | dirent_set_errno (ENOTDIR); 620 | break; 621 | 622 | case ERROR_PATH_NOT_FOUND: 623 | default: 624 | /* Cannot find the file */ 625 | dirent_set_errno (ENOENT); 626 | } 627 | 628 | } 629 | return datap; 630 | } 631 | 632 | /* 633 | * Get next directory entry (internal). 634 | * 635 | * Returns 636 | */ 637 | static WIN32_FIND_DATAW* 638 | dirent_next( 639 | _WDIR *dirp) 640 | { 641 | WIN32_FIND_DATAW *p; 642 | 643 | /* Get next directory entry */ 644 | if (dirp->cached != 0) { 645 | 646 | /* A valid directory entry already in memory */ 647 | p = &dirp->data; 648 | dirp->cached = 0; 649 | 650 | } else if (dirp->handle != INVALID_HANDLE_VALUE) { 651 | 652 | /* Get the next directory entry from stream */ 653 | if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) { 654 | /* Got a file */ 655 | p = &dirp->data; 656 | } else { 657 | /* The very last entry has been processed or an error occurred */ 658 | FindClose (dirp->handle); 659 | dirp->handle = INVALID_HANDLE_VALUE; 660 | p = NULL; 661 | } 662 | 663 | } else { 664 | 665 | /* End of directory stream reached */ 666 | p = NULL; 667 | 668 | } 669 | 670 | return p; 671 | } 672 | 673 | /* 674 | * Open directory stream using plain old C-string. 675 | */ 676 | static DIR* 677 | opendir( 678 | const char *dirname) 679 | { 680 | struct DIR *dirp; 681 | 682 | /* Must have directory name */ 683 | if (dirname == NULL || dirname[0] == '\0') { 684 | dirent_set_errno (ENOENT); 685 | return NULL; 686 | } 687 | 688 | /* Allocate memory for DIR structure */ 689 | dirp = (DIR*) malloc (sizeof (struct DIR)); 690 | if (!dirp) { 691 | return NULL; 692 | } 693 | { 694 | int error; 695 | wchar_t wname[PATH_MAX + 1]; 696 | size_t n; 697 | 698 | /* Convert directory name to wide-character string */ 699 | error = dirent_mbstowcs_s( 700 | &n, wname, PATH_MAX + 1, dirname, PATH_MAX + 1); 701 | if (error) { 702 | /* 703 | * Cannot convert file name to wide-character string. This 704 | * occurs if the string contains invalid multi-byte sequences or 705 | * the output buffer is too small to contain the resulting 706 | * string. 707 | */ 708 | goto exit_free; 709 | } 710 | 711 | 712 | /* Open directory stream using wide-character name */ 713 | dirp->wdirp = _wopendir (wname); 714 | if (!dirp->wdirp) { 715 | goto exit_free; 716 | } 717 | 718 | } 719 | 720 | /* Success */ 721 | return dirp; 722 | 723 | /* Failure */ 724 | exit_free: 725 | free (dirp); 726 | return NULL; 727 | } 728 | 729 | /* 730 | * Read next directory entry. 731 | */ 732 | static struct dirent* 733 | readdir( 734 | DIR *dirp) 735 | { 736 | struct dirent *entry; 737 | 738 | /* 739 | * Read directory entry to buffer. We can safely ignore the return value 740 | * as entry will be set to NULL in case of error. 741 | */ 742 | (void) readdir_r (dirp, &dirp->ent, &entry); 743 | 744 | /* Return pointer to statically allocated directory entry */ 745 | return entry; 746 | } 747 | 748 | /* 749 | * Read next directory entry into called-allocated buffer. 750 | * 751 | * Returns zero on success. If the end of directory stream is reached, then 752 | * sets result to NULL and returns zero. 753 | */ 754 | static int 755 | readdir_r( 756 | DIR *dirp, 757 | struct dirent *entry, 758 | struct dirent **result) 759 | { 760 | WIN32_FIND_DATAW *datap; 761 | 762 | /* Read next directory entry */ 763 | datap = dirent_next (dirp->wdirp); 764 | if (datap) { 765 | size_t n; 766 | int error; 767 | 768 | /* Attempt to convert file name to multi-byte string */ 769 | error = dirent_wcstombs_s( 770 | &n, entry->d_name, PATH_MAX + 1, datap->cFileName, PATH_MAX + 1); 771 | 772 | /* 773 | * If the file name cannot be represented by a multi-byte string, 774 | * then attempt to use old 8+3 file name. This allows traditional 775 | * Unix-code to access some file names despite of unicode 776 | * characters, although file names may seem unfamiliar to the user. 777 | * 778 | * Be ware that the code below cannot come up with a short file 779 | * name unless the file system provides one. At least 780 | * VirtualBox shared folders fail to do this. 781 | */ 782 | if (error && datap->cAlternateFileName[0] != '\0') { 783 | error = dirent_wcstombs_s( 784 | &n, entry->d_name, PATH_MAX + 1, 785 | datap->cAlternateFileName, PATH_MAX + 1); 786 | } 787 | 788 | if (!error) { 789 | DWORD attr; 790 | 791 | /* Length of file name excluding zero terminator */ 792 | entry->d_namlen = n - 1; 793 | 794 | /* File attributes */ 795 | attr = datap->dwFileAttributes; 796 | if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) { 797 | entry->d_type = DT_CHR; 798 | } else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) { 799 | entry->d_type = DT_DIR; 800 | } else { 801 | entry->d_type = DT_REG; 802 | } 803 | 804 | /* Reset dummy fields */ 805 | entry->d_ino = 0; 806 | entry->d_off = 0; 807 | entry->d_reclen = sizeof (struct dirent); 808 | 809 | } else { 810 | 811 | /* 812 | * Cannot convert file name to multi-byte string so construct 813 | * an erroneous directory entry and return that. Note that 814 | * we cannot return NULL as that would stop the processing 815 | * of directory entries completely. 816 | */ 817 | entry->d_name[0] = '?'; 818 | entry->d_name[1] = '\0'; 819 | entry->d_namlen = 1; 820 | entry->d_type = DT_UNKNOWN; 821 | entry->d_ino = 0; 822 | entry->d_off = -1; 823 | entry->d_reclen = 0; 824 | 825 | } 826 | 827 | /* Return pointer to directory entry */ 828 | *result = entry; 829 | 830 | } else { 831 | 832 | /* No more directory entries */ 833 | *result = NULL; 834 | 835 | } 836 | 837 | return /*OK*/0; 838 | } 839 | 840 | /* 841 | * Close directory stream. 842 | */ 843 | static int 844 | closedir( 845 | DIR *dirp) 846 | { 847 | int ok; 848 | if (dirp) { 849 | 850 | /* Close wide-character directory stream */ 851 | ok = _wclosedir (dirp->wdirp); 852 | dirp->wdirp = NULL; 853 | 854 | /* Release multi-byte character version */ 855 | free (dirp); 856 | 857 | } else { 858 | 859 | /* Invalid directory stream */ 860 | dirent_set_errno (EBADF); 861 | ok = /*failure*/-1; 862 | 863 | } 864 | return ok; 865 | } 866 | 867 | /* 868 | * Rewind directory stream to beginning. 869 | */ 870 | static void 871 | rewinddir( 872 | DIR* dirp) 873 | { 874 | /* Rewind wide-character string directory stream */ 875 | _wrewinddir (dirp->wdirp); 876 | } 877 | 878 | /* 879 | * Scan directory for entries. 880 | */ 881 | static int 882 | scandir( 883 | const char *dirname, 884 | struct dirent ***namelist, 885 | int (*filter)(const struct dirent*), 886 | int (*compare)(const struct dirent**, const struct dirent**)) 887 | { 888 | struct dirent **files = NULL; 889 | size_t size = 0; 890 | size_t allocated = 0; 891 | const size_t init_size = 1; 892 | DIR *dir = NULL; 893 | struct dirent *entry; 894 | struct dirent *tmp = NULL; 895 | size_t i; 896 | int result = 0; 897 | 898 | /* Open directory stream */ 899 | dir = opendir (dirname); 900 | if (dir) { 901 | 902 | /* Read directory entries to memory */ 903 | while (1) { 904 | 905 | /* Enlarge pointer table to make room for another pointer */ 906 | if (size >= allocated) { 907 | void *p; 908 | size_t num_entries; 909 | 910 | /* Compute number of entries in the enlarged pointer table */ 911 | if (size < init_size) { 912 | /* Allocate initial pointer table */ 913 | num_entries = init_size; 914 | } else { 915 | /* Double the size */ 916 | num_entries = size * 2; 917 | } 918 | 919 | /* Allocate first pointer table or enlarge existing table */ 920 | p = realloc (files, sizeof (void*) * num_entries); 921 | if (p != NULL) { 922 | /* Got the memory */ 923 | files = (dirent**) p; 924 | allocated = num_entries; 925 | } else { 926 | /* Out of memory */ 927 | result = -1; 928 | break; 929 | } 930 | 931 | } 932 | 933 | /* Allocate room for temporary directory entry */ 934 | if (tmp == NULL) { 935 | tmp = (struct dirent*) malloc (sizeof (struct dirent)); 936 | if (tmp == NULL) { 937 | /* Cannot allocate temporary directory entry */ 938 | result = -1; 939 | break; 940 | } 941 | } 942 | 943 | /* Read directory entry to temporary area */ 944 | if (readdir_r (dir, tmp, &entry) == /*OK*/0) { 945 | 946 | /* Did we get an entry? */ 947 | if (entry != NULL) { 948 | int pass; 949 | 950 | /* Determine whether to include the entry in result */ 951 | if (filter) { 952 | /* Let the filter function decide */ 953 | pass = filter (tmp); 954 | } else { 955 | /* No filter function, include everything */ 956 | pass = 1; 957 | } 958 | 959 | if (pass) { 960 | /* Store the temporary entry to pointer table */ 961 | files[size++] = tmp; 962 | tmp = NULL; 963 | 964 | /* Keep up with the number of files */ 965 | result++; 966 | } 967 | 968 | } else { 969 | 970 | /* 971 | * End of directory stream reached => sort entries and 972 | * exit. 973 | */ 974 | qsort (files, size, sizeof (void*), 975 | (int (*) (const void*, const void*)) compare); 976 | break; 977 | 978 | } 979 | 980 | } else { 981 | /* Error reading directory entry */ 982 | result = /*Error*/ -1; 983 | break; 984 | } 985 | 986 | } 987 | 988 | } else { 989 | /* Cannot open directory */ 990 | result = /*Error*/ -1; 991 | } 992 | 993 | /* Release temporary directory entry */ 994 | free (tmp); 995 | 996 | /* Release allocated memory on error */ 997 | if (result < 0) { 998 | for (i = 0; i < size; i++) { 999 | free (files[i]); 1000 | } 1001 | free (files); 1002 | files = NULL; 1003 | } 1004 | 1005 | /* Close directory stream */ 1006 | if (dir) { 1007 | closedir (dir); 1008 | } 1009 | 1010 | /* Pass pointer table to caller */ 1011 | if (namelist) { 1012 | *namelist = files; 1013 | } 1014 | return result; 1015 | } 1016 | 1017 | /* Alphabetical sorting */ 1018 | static int 1019 | alphasort( 1020 | const struct dirent **a, const struct dirent **b) 1021 | { 1022 | return strcoll ((*a)->d_name, (*b)->d_name); 1023 | } 1024 | 1025 | /* Sort versions */ 1026 | static int 1027 | versionsort( 1028 | const struct dirent **a, const struct dirent **b) 1029 | { 1030 | /* FIXME: implement strverscmp and use that */ 1031 | return alphasort (a, b); 1032 | } 1033 | 1034 | /* Convert multi-byte string to wide character string */ 1035 | static int 1036 | dirent_mbstowcs_s( 1037 | size_t *pReturnValue, 1038 | wchar_t *wcstr, 1039 | size_t sizeInWords, 1040 | const char *mbstr, 1041 | size_t count) 1042 | { 1043 | int error; 1044 | 1045 | #if defined(_MSC_VER) && _MSC_VER >= 1400 1046 | 1047 | /* Microsoft Visual Studio 2005 or later */ 1048 | error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count); 1049 | 1050 | #else 1051 | 1052 | /* Older Visual Studio or non-Microsoft compiler */ 1053 | size_t n; 1054 | 1055 | /* Convert to wide-character string (or count characters) */ 1056 | n = mbstowcs (wcstr, mbstr, sizeInWords); 1057 | if (!wcstr || n < count) { 1058 | 1059 | /* Zero-terminate output buffer */ 1060 | if (wcstr && sizeInWords) { 1061 | if (n >= sizeInWords) { 1062 | n = sizeInWords - 1; 1063 | } 1064 | wcstr[n] = 0; 1065 | } 1066 | 1067 | /* Length of resulting multi-byte string WITH zero terminator */ 1068 | if (pReturnValue) { 1069 | *pReturnValue = n + 1; 1070 | } 1071 | 1072 | /* Success */ 1073 | error = 0; 1074 | 1075 | } else { 1076 | 1077 | /* Could not convert string */ 1078 | error = 1; 1079 | 1080 | } 1081 | 1082 | #endif 1083 | return error; 1084 | } 1085 | 1086 | /* Convert wide-character string to multi-byte string */ 1087 | static int 1088 | dirent_wcstombs_s( 1089 | size_t *pReturnValue, 1090 | char *mbstr, 1091 | size_t sizeInBytes, /* max size of mbstr */ 1092 | const wchar_t *wcstr, 1093 | size_t count) 1094 | { 1095 | int error; 1096 | 1097 | #if defined(_MSC_VER) && _MSC_VER >= 1400 1098 | 1099 | /* Microsoft Visual Studio 2005 or later */ 1100 | error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count); 1101 | 1102 | #else 1103 | 1104 | /* Older Visual Studio or non-Microsoft compiler */ 1105 | size_t n; 1106 | 1107 | /* Convert to multi-byte string (or count the number of bytes needed) */ 1108 | n = wcstombs (mbstr, wcstr, sizeInBytes); 1109 | if (!mbstr || n < count) { 1110 | 1111 | /* Zero-terminate output buffer */ 1112 | if (mbstr && sizeInBytes) { 1113 | if (n >= sizeInBytes) { 1114 | n = sizeInBytes - 1; 1115 | } 1116 | mbstr[n] = '\0'; 1117 | } 1118 | 1119 | /* Length of resulting multi-bytes string WITH zero-terminator */ 1120 | if (pReturnValue) { 1121 | *pReturnValue = n + 1; 1122 | } 1123 | 1124 | /* Success */ 1125 | error = 0; 1126 | 1127 | } else { 1128 | 1129 | /* Cannot convert string */ 1130 | error = 1; 1131 | 1132 | } 1133 | 1134 | #endif 1135 | return error; 1136 | } 1137 | 1138 | /* Set errno variable */ 1139 | static void 1140 | dirent_set_errno( 1141 | int error) 1142 | { 1143 | #if defined(_MSC_VER) && _MSC_VER >= 1400 1144 | 1145 | /* Microsoft Visual Studio 2005 and later */ 1146 | _set_errno (error); 1147 | 1148 | #else 1149 | 1150 | /* Non-Microsoft compiler or older Microsoft compiler */ 1151 | errno = error; 1152 | 1153 | #endif 1154 | } 1155 | 1156 | 1157 | #ifdef __cplusplus 1158 | } 1159 | #endif 1160 | #endif /*DIRENT_H*/ 1161 | --------------------------------------------------------------------------------