Skip to content

Commit

Permalink
[testing] scripted comparison with vlfeat
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Griwodz committed Mar 7, 2021
1 parent 5a295bb commit cb24f0d
Show file tree
Hide file tree
Showing 14 changed files with 868 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for Cuda CC 7 cards (RTX 2080) [PR](https://github.com/alicevision/popsift/pull/67)
- Support for Boost 1.70 [PR](https://github.com/alicevision/popsift/pull/65)
- Support for device selection and multiple GPUs [PR](https://github.com/alicevision/popsift/pull/121)
- Test: adding descriptor comparator [PR](https://github.com/alicevision/popsift/pull/115)

### Fixed
- CMake: fixes to allow building on Windows using vcpkg [PR](https://github.com/alicevision/popsift/pull/92)
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ if(PopSift_BUILD_EXAMPLES)
add_subdirectory(application)
endif()

if(PopSift_USE_TEST_CMD)
add_subdirectory(compareSiftFiles)
endif()

38 changes: 38 additions & 0 deletions src/compareSiftFiles/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
if(NOT CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
# I am top-level project, i.e. I am not being include by another project
cmake_minimum_required(VERSION 3.12)
project(PopSiftCompareDescriptors LANGUAGES CXX)

include(GNUInstallDirs)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
endif()

if(PopSift_BOOST_USE_STATIC_LIBS)
set(Boost_USE_STATIC_LIBS ON)
endif()
find_package(Boost 1.53.0 REQUIRED COMPONENTS filesystem program_options system)
if(WIN32)
add_definitions("-DBOOST_ALL_NO_LIB")
endif(WIN32)

#############################################################
# compareSiftFiles
#############################################################

add_executable(popsift-compareSiftFiles
compareSiftFiles.cpp
csf_feat.cpp csf_feat.h
csf_options.cpp csf_options.h)

target_include_directories(popsift-compareSiftFiles PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(popsift-compareSiftFiles PUBLIC ${Boost_LIBRARIES})

set_property(TARGET popsift-compareSiftFiles PROPERTY CXX_STANDARD 14)

#############################################################
# installation
#############################################################

install(TARGETS popsift-compareSiftFiles DESTINATION ${CMAKE_INSTALL_BINDIR})
131 changes: 131 additions & 0 deletions src/compareSiftFiles/compareSiftFiles.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstring>

#include <boost/program_options.hpp>

#include "csf_feat.h"
#include "csf_options.h"

using namespace std;

typedef vector<float> desc_t;

/** Read a file containing SIFT descriptors
*/
void readFile( vector<feat_t>& vec, const std::string& filename );

/** Write the average descriptor differences to file
* @param file The output file
* @param stats A 128-float vector containing the sum of differences
* @param sz The number of samples that have been collected in stats
*/
void writeSummary( ostream& file, const vector<float>& stats, int sz );

/** Open a new stream or return the default stream. The default stream is
* returned if the name is empty or opening the stream fails.
* @param name A string containing the name of the file to open or empty
* @param default_stream The default stream to return
*/
ostream* openOutputFile( const string& name, ostream* default_stream );

int main( int argc, char* argv[] )
{
Parameters param;

parseargs( argc, argv, param );

vector<feat_t> l_one;
vector<feat_t> l_two;

readFile( l_one, param.input[0] );
readFile( l_two, param.input[1] );

ostream* outfile = openOutputFile( param.outfile_name, &cout );
ostream* descfile = openOutputFile( param.descfile_name, nullptr );

int len = l_one.size();
int ct = 0;
float nextpercent = 10;

vector<float> desc_stats( 128, 0.0f );

ostream* print_dists = param.descfile_verbose ? descfile : 0;

for( auto l : l_one )
{
l.compareBestMatch( *outfile, print_dists, l_two, desc_stats, param.briefinfo );
ct++;
if( float(ct * 100) / len >= float(nextpercent) )
{
cerr << nextpercent << "% " << ct << endl;
nextpercent += 10;
}
}

if( descfile )
{
writeSummary( *descfile, desc_stats, l_one.size() );
}

if( ! param.outfile_name.empty() )
{
delete outfile;
}
}

void writeSummary( ostream& descfile, const vector<float>& desc_stats, int sz )
{
descfile << "========== Summary Stats ==========" << endl
<< "Average values:" << endl
<< setprecision(3);
for( int i=0; i<128; i++ )
{
if( i%32==0 ) descfile << "X=0 | ";
if( i%32==8 ) descfile << "X=1 | ";
if( i%32==16 ) descfile << "X=2 | ";
if( i%32==24 ) descfile << "X=3 | ";
float d = desc_stats[i] / sz;
descfile << setw(8) << d << " ";
if( i%8==7 ) descfile << endl;
}
descfile << endl;
}

void readFile( vector<feat_t>& vec, const std::string& filename )
{
ifstream infile( filename );

if( ! infile.good() )
{
cerr << "File " << filename << " is not open." << endl;
exit( -1 );
}

int lines_read = readFeats( vec, infile );
cerr << "Read " << lines_read << " lines from " << filename << endl;
}

ostream* openOutputFile( const string& outfile_name, ostream* default_stream )
{
ostream* outfile = default_stream;
if( outfile_name.empty() ) return outfile;

ostream* o = new ofstream( outfile_name );
if( o->good() )
{
outfile = o;
}
else
{
delete o;
}

return outfile;
}

Loading

0 comments on commit cb24f0d

Please sign in to comment.