Skip to content

Commit 2178992

Browse files
author
Carsten Griwodz
authored
Merge pull request #30 from alicevision/extremum-filter-grid-2
Extremum filter grid 2
2 parents 169167b + 6e418b6 commit 2178992

28 files changed

+2020
-703
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ else()
2121
message(STATUS "Building in ${CMAKE_BUILD_TYPE} configuration")
2222
endif()
2323

24-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
2524
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
2625
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
26+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
27+
set(CMAKE_CXX_STANDARD 11)
28+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2729

2830
# set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -G")
2931
# set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -G")

src/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CUDA_INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
44

55
CUDA_ADD_LIBRARY(popsift STATIC
66
popsift/popsift.cu popsift/popsift.h
7+
popsift/features.cu popsift/features.h
78
popsift/sift_constants.cu popsift/sift_constants.h
89
popsift/sift_conf.cu popsift/sift_conf.h
910
popsift/gauss_filter.cu popsift/gauss_filter.h
@@ -33,8 +34,8 @@ CUDA_ADD_LIBRARY(popsift STATIC
3334
popsift/common/clamp.h
3435
popsift/common/plane_2d.cu popsift/common/plane_2d.h
3536
popsift/common/write_plane_2d.cu popsift/common/write_plane_2d.h
36-
popsift/common/debug_macros.cpp popsift/common/debug_macros.h
37-
popsift/common/device_prop.cpp popsift/common/device_prop.h
37+
popsift/common/debug_macros.cu popsift/common/debug_macros.h
38+
popsift/common/device_prop.cu popsift/common/device_prop.h
3839
popsift/common/warp_bitonic_sort.h
3940
popsift/common/excl_blk_prefix_sum.h
4041
popsift/common/vec_macros.h

src/application/CMakeLists.txt

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,55 @@ endif()
1515
find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options system filesystem)
1616
find_package(DevIL REQUIRED COMPONENTS IL ILU) # yields IL_FOUND, IL_LIBRARIES, IL_INCLUDE_DIR
1717

18-
add_executable(popsift-demo main.cpp pgmread.cpp pgmread.h)
19-
20-
set_property(TARGET popsift-demo PROPERTY CXX_STANDARD 11)
18+
set(PD_INCLUDE_DIRS ${Boost_INCLUDE_DIRS})
19+
set(PD_LINK_LIBS ${Boost_LIBRARIES} ${CUDA_CUDADEVRT_LIBRARY})
2120

2221
if(IL_FOUND OR DevIL_FOUND)
2322
message(STATUS "DevIL found")
24-
target_compile_options(popsift-demo PRIVATE -DUSE_DEVIL)
25-
target_include_directories(popsift-demo PUBLIC ${Boost_INCLUDE_DIRS} ${IL_INCLUDE_DIR})
26-
target_compile_definitions(popsift-demo PRIVATE ${Boost_DEFINITIONS} BOOST_ALL_DYN_LINK BOOST_ALL_NO_LIB)
27-
target_link_libraries(popsift-demo PUBLIC PopSift::popsift ${Boost_LIBRARIES} ${CUDA_CUDADEVRT_LIBRARY} ${IL_LIBRARIES} ${ILU_LIBRARIES})
23+
set(PD_COMPILE_OPTIONS "-DUSE_DEVIL")
24+
list(APPEND PD_INCLUDE_DIRS ${IL_INCLUDE_DIR})
25+
list(APPEND PD_LINK_LIBS ${IL_LIBRARIES} ${ILU_LIBRARIES})
2826
else()
2927
message(STATUS "DevIL not found")
30-
target_include_directories(popsift-demo PUBLIC ${Boost_INCLUDE_DIRS})
31-
target_compile_definitions(popsift-demo PRIVATE ${Boost_DEFINITIONS} BOOST_ALL_DYN_LINK BOOST_ALL_NO_LIB)
32-
target_link_libraries(popsift-demo PUBLIC PopSift::popsift ${Boost_LIBRARIES} ${CUDA_CUDADEVRT_LIBRARY})
28+
set(PD_COMPILE_OPTIONS "" )
3329
endif()
3430

3531
if(USE_NVTX_PROFILING)
36-
target_link_libraries(popsift-demo PUBLIC ${CUDA_NVTX_LIBRARY})
32+
list(APPEND PD_LINK_LIBS ${CUDA_NVTX_LIBRARY})
3733
endif(USE_NVTX_PROFILING)
3834

35+
#############################################################
36+
# popsift-demo
37+
#############################################################
38+
39+
add_executable(popsift-demo main.cpp pgmread.cpp pgmread.h)
40+
41+
set_property(TARGET popsift-demo PROPERTY CXX_STANDARD 11)
42+
43+
target_compile_options(popsift-demo PRIVATE ${PD_COMPILE_OPTIONS} )
44+
target_include_directories(popsift-demo PUBLIC ${PD_INCLUDE_DIRS})
45+
target_compile_definitions(popsift-demo PRIVATE ${Boost_DEFINITIONS} BOOST_ALL_DYN_LINK BOOST_ALL_NO_LIB)
46+
target_link_libraries(popsift-demo PUBLIC PopSift::popsift ${PD_LINK_LIBS})
47+
48+
set_target_properties(popsift-demo PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
49+
50+
#############################################################
51+
# popsift-match
52+
#############################################################
53+
54+
add_executable(popsift-match match.cpp pgmread.cpp pgmread.h)
55+
56+
set_property(TARGET popsift-match PROPERTY CXX_STANDARD 11)
57+
58+
target_compile_options(popsift-match PRIVATE ${PD_COMPILE_OPTIONS} )
59+
target_include_directories(popsift-match PUBLIC ${PD_INCLUDE_DIRS})
60+
target_compile_definitions(popsift-match PRIVATE ${Boost_DEFINITIONS} BOOST_ALL_DYN_LINK BOOST_ALL_NO_LIB)
61+
target_link_libraries(popsift-match PUBLIC PopSift::popsift ${PD_LINK_LIBS})
62+
63+
set_target_properties(popsift-match PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
3964

40-
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR})
41-
set_target_properties(popsift-demo PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}" )
65+
#############################################################
66+
# installation
67+
#############################################################
4268

4369
install(TARGETS popsift-demo DESTINATION bin)

src/application/main.cpp

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
#include <boost/filesystem.hpp>
2121

2222
#include <popsift/popsift.h>
23+
#include <popsift/features.h>
2324
#include <popsift/sift_conf.h>
2425
#include <popsift/common/device_prop.h>
2526

2627
#ifdef USE_DEVIL
2728
#include <devil_cpp_wrapper.hpp>
28-
#else
29-
#include "pgmread.h"
3029
#endif
30+
#include "pgmread.h"
3131

3232
#ifdef USE_NVTX
3333
#include <nvToolsExtCuda.h>
@@ -42,6 +42,7 @@ static bool print_dev_info = false;
4242
static bool print_time_info = false;
4343
static bool write_as_uchar = false;
4444
static bool dont_write = false;
45+
static bool pgmread_loading = false;
4546

4647
static void parseargs(int argc, char** argv, popsift::Config& config, string& inputFile) {
4748
using namespace boost::program_options;
@@ -78,7 +79,8 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in
7879
("desc-mode", value<std::string>()->notifier([&](const std::string& s) { config.setDescMode(s); }),
7980
"Choice of descriptor extraction modes:\n"
8081
"loop, iloop, grid, igrid, notile\n"
81-
"Default is OpenCV-like horizontal scan, computing only valid points (loop), grid extracts only useful points but rounds them, iloop uses linear texture and rotated gradiant fetching. igrid is grid with linear interpolation. notile is like igrid but avoids redundant gradiant fetching.")
82+
"Default is loop\n"
83+
"loop is OpenCV-like horizontal scanning, computing only valid points, grid extracts only useful points but rounds them, iloop uses linear texture and rotated gradiant fetching. igrid is grid with linear interpolation. notile is like igrid but avoids redundant gradiant fetching.")
8284
("popsift-mode", bool_switch()->notifier([&](bool b) { if(b) config.setMode(popsift::Config::PopSift); }),
8385
"During the initial upscale, shift pixels by 1. In extrema refinement, steps up to 0.6, do not reject points when reaching max iterations, "
8486
"first contrast threshold is .8 * peak thresh. Shift feature coords octave 0 back to original pos.")
@@ -97,7 +99,10 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in
9799
"Direct each octave from upscaled orig instead of blurred level.")
98100
("root-sift", bool_switch()->notifier([&](bool b) { if(b) config.setUseRootSift(true); }),
99101
"Use the L1-based norm for OpenMVG rather than L2-based as in OpenCV")
100-
("norm-multi", value<int>()->notifier([&](int i) {config.setNormalizationMultiplier(i); }), "Multiply the descriptor by pow(2,<int>).");
102+
("norm-multi", value<int>()->notifier([&](int i) {config.setNormalizationMultiplier(i); }), "Multiply the descriptor by pow(2,<int>).")
103+
("filter-max-extrema", value<int>()->notifier([&](int f) {config.setFilterMaxExtrema(f); }), "Approximate max number of extrema.")
104+
("filter-grid", value<int>()->notifier([&](int f) {config.setFilterGridSize(f); }), "Grid edge length for extrema filtering (ie. value 4 leads to a 4x4 grid)")
105+
("filter-sort", value<std::string>()->notifier([&](const std::string& s) {config.setFilterSorting(s); }), "Sort extrema in each cell by scale, either random (default), up or down");
101106

102107
}
103108
options_description informational("Informational");
@@ -106,8 +111,11 @@ static void parseargs(int argc, char** argv, popsift::Config& config, string& in
106111
("print-gauss-tables", bool_switch()->notifier([&](bool b) { if(b) config.setPrintGaussTables(); }), "A debug output printing Gauss filter size and tables")
107112
("print-dev-info", bool_switch(&print_dev_info)->default_value(false), "A debug output printing CUDA device information")
108113
("print-time-info", bool_switch(&print_time_info)->default_value(false), "A debug output printing image processing time after load()")
109-
("write-as-uchar", bool_switch(&write_as_uchar)->default_value(false), "Output descriptors rounded to int Scaling to sensible ranges is not automatic, should be combined with --norm-multi=9 or similar")
110-
("dont-write", bool_switch(&dont_write)->default_value(false), "Suppress descriptor output");
114+
("write-as-uchar", bool_switch(&write_as_uchar)->default_value(false), "Output descriptors rounded to int.\n"
115+
"Scaling to sensible ranges is not automatic, should be combined with --norm-multi=9 or similar")
116+
("dont-write", bool_switch(&dont_write)->default_value(false), "Suppress descriptor output")
117+
("pgmread-loading", bool_switch(&pgmread_loading)->default_value(false), "Use the old image loader instead of LibDevIL")
118+
;
111119

112120
//("test-direct-scaling")
113121
}
@@ -157,46 +165,61 @@ SiftJob* process_image( const string& inputFile, PopSift& PopSift )
157165
int w;
158166
int h;
159167
unsigned char* image_data;
168+
SiftJob* job;
160169

161-
nvtxRangePushA( "load and convert image" );
162170
#ifdef USE_DEVIL
163-
ilImage img;
164-
if( img.Load( inputFile.c_str() ) == false ) {
165-
cerr << "Could not load image " << inputFile << endl;
166-
return 0;
167-
}
168-
if( img.Convert( IL_LUMINANCE ) == false ) {
169-
cerr << "Failed converting image " << inputFile << " to unsigned greyscale image" << endl;
170-
exit( -1 );
171-
}
172-
w = img.Width();
173-
h = img.Height();
174-
cout << "Loading " << w << " x " << h << " image " << inputFile << endl;
175-
image_data = img.GetData();
176-
#else
177-
image_data = readPGMfile( inputFile, w, h );
178-
if( image_data == 0 ) {
179-
exit( -1 );
171+
if( not pgmread_loading )
172+
{
173+
nvtxRangePushA( "load and convert image - devil" );
174+
175+
ilImage img;
176+
if( img.Load( inputFile.c_str() ) == false ) {
177+
cerr << "Could not load image " << inputFile << endl;
178+
return 0;
179+
}
180+
if( img.Convert( IL_LUMINANCE ) == false ) {
181+
cerr << "Failed converting image " << inputFile << " to unsigned greyscale image" << endl;
182+
exit( -1 );
183+
}
184+
w = img.Width();
185+
h = img.Height();
186+
cout << "Loading " << w << " x " << h << " image " << inputFile << endl;
187+
image_data = img.GetData();
188+
189+
nvtxRangePop( ); // "load and convert image - devil"
190+
191+
// PopSift.init( w, h );
192+
job = PopSift.enqueue( w, h, image_data );
193+
194+
img.Clear();
180195
}
196+
else
181197
#endif
182-
nvtxRangePop( );
198+
{
199+
nvtxRangePushA( "load and convert image - pgmread" );
183200

184-
// PopSift.init( w, h );
185-
SiftJob* job = PopSift.enqueue( w, h, image_data );
201+
image_data = readPGMfile( inputFile, w, h );
202+
if( image_data == 0 ) {
203+
exit( -1 );
204+
}
186205

187-
#ifdef USE_DEVIL
188-
img.Clear();
189-
#else
190-
delete [] image_data;
191-
#endif
206+
nvtxRangePop( ); // "load and convert image - pgmread"
207+
208+
// PopSift.init( w, h );
209+
job = PopSift.enqueue( w, h, image_data );
210+
211+
delete [] image_data;
212+
}
192213

193214
return job;
194215
}
195216

196217
void read_job( SiftJob* job, bool really_write )
197218
{
198219
popsift::Features* feature_list = job->get();
199-
cerr << "Number of features: " << feature_list->size() << endl;
220+
cerr << "Number of feature points: " << feature_list->getFeatureCount()
221+
<< " number of feature descriptors: " << feature_list->getDescriptorCount()
222+
<< endl;
200223

201224
if( really_write ) {
202225
nvtxRangePushA( "Writing features to disk" );
@@ -207,7 +230,7 @@ void read_job( SiftJob* job, bool really_write )
207230
delete feature_list;
208231

209232
if( really_write ) {
210-
nvtxRangePop( );
233+
nvtxRangePop( ); // Writing features to disk
211234
}
212235
}
213236

0 commit comments

Comments
 (0)