-
Notifications
You must be signed in to change notification settings - Fork 5
/
extract_features.cpp
134 lines (109 loc) · 4.24 KB
/
extract_features.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*------------------------------------------------------*/
/* Copyright 2013, Dmytro Mishkin [email protected] */
/*------------------------------------------------------*/
#undef __STRICT_ANSI__
#include <fstream>
#include <string>
#include <iomanip>
#include <sys/time.h>
#include <map>
#include "io_mods.h"
#include "detectors/mser/extrema/extrema.h"
#include "detectors/helpers.h"
#include "matching/siftdesc.h"
#include "synth-detection.hpp"
#include "detectors/affinedetectors/scale-space-detector.hpp"
#include "detectors/detectors_parameters.hpp"
#include "descriptors_parameters.hpp"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "matching.hpp"
#include "configuration.hpp"
#include "imagerepresentation.h"
#include "correspondencebank.h"
#ifdef WITH_ORSA
#include "orsa.h"
#endif
#ifdef _OPENMP
#include <omp.h>
#endif
using namespace std;
const int nn_n = 50; //number of nearest neighbours retrieved to get 1st inconsistent
inline static bool endsWith(const std::string& str, const std::string& suffix)
{
return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix);
}
int main(int argc, char **argv)
{
if ((argc < 4))
{
std::cerr << " ************************************************************************** " << std::endl
<< " ******** Two-view Matching with On-Demand Synthesis ********************** " << std::endl
<< " ************************************************************************** " << std::endl
<< "Usage: " << argv[0] << " imgIn1.png keys-1.txt config_iter.ini iters.ini" << std::endl
<< "- imgIn1.png: input images " << std::endl
<< "- keys1.txt: affine regions and their descriptors of the two images." << std::endl
<< "- config_iter.ini: input file with detectors and descriptors paramaters [optional, default = 'config_iter.ini'] " << std::endl
<< "- iters.ini: input file with parameters of iterative view synthesis [optional, default= 'iters.ini']" << std::endl
<< " ******************************************************************************* " << std::endl;
return 1;
}
long c_start = getMilliSecs();
double time1;
TimeLog TimingLog;
logs log1;
/// Parameters reading
configs Config1;
if (getCLIparamExtractFeatures(Config1,argc,argv)) return 1;
int VERB = Config1.OutputParam.verbose;
/// Input images reading
cv::Mat img1;
SynthImage tilt_img1;
tilt_img1.id=0;
img1 = cv::imread(Config1.CLIparams.img1_fname,Config1.LoadColor); // load grayscale; Try RGB?
if(!img1.data) {
std::cerr << "Could not open or find the image1 " << Config1.CLIparams.img1_fname << std::endl;
return 1;
}
/// Data structures preparation
ImageRepresentation ImgRep1;
if (Config1.CLIparams.doCLAHE)
{
long clahe_start = getMilliSecs();
Ptr<CLAHE> clahe = createCLAHE();
clahe->setClipLimit(4);
cv::Mat img1_clahe;
clahe->apply(img1,img1_clahe);
double time2 = ((double)(getMilliSecs() - clahe_start))/1000;
if (VERB) std::cerr << " CLAHE done in " << time2<< " seconds" << endl;
ImgRep1 = ImageRepresentation(img1_clahe,Config1.CLIparams.img1_fname);
}
else
{
ImgRep1 = ImageRepresentation(img1,Config1.CLIparams.img1_fname);
}
/// Affine regions detection
std::cerr << "View synthesis, detection and description..." << endl;
#ifdef _OPENMP
omp_set_nested(1);
#endif
ImgRep1.SynthDetectDescribeKeypoints(Config1.ItersParam[0],
Config1.DetectorsPars,
Config1.DescriptorPars,
Config1.DomOriPars);
TimeLog img1time = ImgRep1.GetTimeSpent();
/// Writing images and logs
std::cerr << "Writing files... " << endl;
if (Config1.OutputParam.outputMikFormat) {
// ImgRep1.SaveRegionsMichal(Config1.CLIparams.k1_fname,ios::binary);
ImgRep1.SaveRegionsMichal(Config1.CLIparams.k1_fname, 123);
} else {
if (endsWith(Config1.CLIparams.k1_fname,".npz")){
ImgRep1.SaveRegionsNPZ(Config1.CLIparams.k1_fname);
} else {
ImgRep1.SaveRegions(Config1.CLIparams.k1_fname,0);
}
// ImgRep1.SaveRegionsAMatrix(Config1.CLIparams.k1_fname);
}
return 0;
}