Skip to content

Commit cb24f0d

Browse files
author
Carsten Griwodz
committed
[testing] scripted comparison with vlfeat
1 parent 5a295bb commit cb24f0d

14 files changed

Lines changed: 868 additions & 0 deletions

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
- Support for Cuda CC 7 cards (RTX 2080) [PR](https://github.com/alicevision/popsift/pull/67)
2525
- Support for Boost 1.70 [PR](https://github.com/alicevision/popsift/pull/65)
2626
- Support for device selection and multiple GPUs [PR](https://github.com/alicevision/popsift/pull/121)
27+
- Test: adding descriptor comparator [PR](https://github.com/alicevision/popsift/pull/115)
2728

2829
### Fixed
2930
- CMake: fixes to allow building on Windows using vcpkg [PR](https://github.com/alicevision/popsift/pull/92)

src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,7 @@ if(PopSift_BUILD_EXAMPLES)
150150
add_subdirectory(application)
151151
endif()
152152

153+
if(PopSift_USE_TEST_CMD)
154+
add_subdirectory(compareSiftFiles)
155+
endif()
156+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
2+
# I am top-level project, i.e. I am not being include by another project
3+
cmake_minimum_required(VERSION 3.12)
4+
project(PopSiftCompareDescriptors LANGUAGES CXX)
5+
6+
include(GNUInstallDirs)
7+
8+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
9+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
10+
endif()
11+
12+
if(PopSift_BOOST_USE_STATIC_LIBS)
13+
set(Boost_USE_STATIC_LIBS ON)
14+
endif()
15+
find_package(Boost 1.53.0 REQUIRED COMPONENTS filesystem program_options system)
16+
if(WIN32)
17+
add_definitions("-DBOOST_ALL_NO_LIB")
18+
endif(WIN32)
19+
20+
#############################################################
21+
# compareSiftFiles
22+
#############################################################
23+
24+
add_executable(popsift-compareSiftFiles
25+
compareSiftFiles.cpp
26+
csf_feat.cpp csf_feat.h
27+
csf_options.cpp csf_options.h)
28+
29+
target_include_directories(popsift-compareSiftFiles PUBLIC ${Boost_INCLUDE_DIRS})
30+
target_link_libraries(popsift-compareSiftFiles PUBLIC ${Boost_LIBRARIES})
31+
32+
set_property(TARGET popsift-compareSiftFiles PROPERTY CXX_STANDARD 14)
33+
34+
#############################################################
35+
# installation
36+
#############################################################
37+
38+
install(TARGETS popsift-compareSiftFiles DESTINATION ${CMAKE_INSTALL_BINDIR})
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#include <iostream>
2+
#include <iomanip>
3+
#include <fstream>
4+
#include <sstream>
5+
#include <cmath>
6+
#include <vector>
7+
#include <algorithm>
8+
#include <cstring>
9+
10+
#include <boost/program_options.hpp>
11+
12+
#include "csf_feat.h"
13+
#include "csf_options.h"
14+
15+
using namespace std;
16+
17+
typedef vector<float> desc_t;
18+
19+
/** Read a file containing SIFT descriptors
20+
*/
21+
void readFile( vector<feat_t>& vec, const std::string& filename );
22+
23+
/** Write the average descriptor differences to file
24+
* @param file The output file
25+
* @param stats A 128-float vector containing the sum of differences
26+
* @param sz The number of samples that have been collected in stats
27+
*/
28+
void writeSummary( ostream& file, const vector<float>& stats, int sz );
29+
30+
/** Open a new stream or return the default stream. The default stream is
31+
* returned if the name is empty or opening the stream fails.
32+
* @param name A string containing the name of the file to open or empty
33+
* @param default_stream The default stream to return
34+
*/
35+
ostream* openOutputFile( const string& name, ostream* default_stream );
36+
37+
int main( int argc, char* argv[] )
38+
{
39+
Parameters param;
40+
41+
parseargs( argc, argv, param );
42+
43+
vector<feat_t> l_one;
44+
vector<feat_t> l_two;
45+
46+
readFile( l_one, param.input[0] );
47+
readFile( l_two, param.input[1] );
48+
49+
ostream* outfile = openOutputFile( param.outfile_name, &cout );
50+
ostream* descfile = openOutputFile( param.descfile_name, nullptr );
51+
52+
int len = l_one.size();
53+
int ct = 0;
54+
float nextpercent = 10;
55+
56+
vector<float> desc_stats( 128, 0.0f );
57+
58+
ostream* print_dists = param.descfile_verbose ? descfile : 0;
59+
60+
for( auto l : l_one )
61+
{
62+
l.compareBestMatch( *outfile, print_dists, l_two, desc_stats, param.briefinfo );
63+
ct++;
64+
if( float(ct * 100) / len >= float(nextpercent) )
65+
{
66+
cerr << nextpercent << "% " << ct << endl;
67+
nextpercent += 10;
68+
}
69+
}
70+
71+
if( descfile )
72+
{
73+
writeSummary( *descfile, desc_stats, l_one.size() );
74+
}
75+
76+
if( ! param.outfile_name.empty() )
77+
{
78+
delete outfile;
79+
}
80+
}
81+
82+
void writeSummary( ostream& descfile, const vector<float>& desc_stats, int sz )
83+
{
84+
descfile << "========== Summary Stats ==========" << endl
85+
<< "Average values:" << endl
86+
<< setprecision(3);
87+
for( int i=0; i<128; i++ )
88+
{
89+
if( i%32==0 ) descfile << "X=0 | ";
90+
if( i%32==8 ) descfile << "X=1 | ";
91+
if( i%32==16 ) descfile << "X=2 | ";
92+
if( i%32==24 ) descfile << "X=3 | ";
93+
float d = desc_stats[i] / sz;
94+
descfile << setw(8) << d << " ";
95+
if( i%8==7 ) descfile << endl;
96+
}
97+
descfile << endl;
98+
}
99+
100+
void readFile( vector<feat_t>& vec, const std::string& filename )
101+
{
102+
ifstream infile( filename );
103+
104+
if( ! infile.good() )
105+
{
106+
cerr << "File " << filename << " is not open." << endl;
107+
exit( -1 );
108+
}
109+
110+
int lines_read = readFeats( vec, infile );
111+
cerr << "Read " << lines_read << " lines from " << filename << endl;
112+
}
113+
114+
ostream* openOutputFile( const string& outfile_name, ostream* default_stream )
115+
{
116+
ostream* outfile = default_stream;
117+
if( outfile_name.empty() ) return outfile;
118+
119+
ostream* o = new ofstream( outfile_name );
120+
if( o->good() )
121+
{
122+
outfile = o;
123+
}
124+
else
125+
{
126+
delete o;
127+
}
128+
129+
return outfile;
130+
}
131+

0 commit comments

Comments
 (0)