-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[testing] scripted comparison with vlfeat
- Loading branch information
Carsten Griwodz
committed
Mar 7, 2021
1 parent
5a295bb
commit cb24f0d
Showing
14 changed files
with
868 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
Oops, something went wrong.