-
Notifications
You must be signed in to change notification settings - Fork 1
/
stripes_solver.h
155 lines (120 loc) · 4.07 KB
/
stripes_solver.h
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef STRIPES_SOLVER_H
#define STRIPES_SOLVER_H
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <numeric>
#include <vector>
#include <deque>
#include <string>
#include <omp.h>
#include <map>
#include <random>
#include <tesseract/baseapi.h>
#include <opencv2/opencv.hpp>
#include <fragment.h>
#include <path_manager.h>
#include <utils.h>
#include <KM.h>
#include <stripe_pair.h>
using namespace std;
class StripesSolver {
public:
enum Metric {
PIXEL,
CHAR,
WORD,
// COMP_EVA
};
enum Composition {
GREEDY,
GCOM,
GREEDY_GCOM,
GT,
USER,
};
const string puzzle_folder;
const int stripes_n;
vector<int> gt_order;
vector<cv::Mat> stripes;
vector<int> composition_order;
cv::Mat composition_img;
cv::Mat composition_img_seams;
cv::Mat composition_img_bar;
double composition_score;
// Path
PathManager path_manager;
StripesSolver(const string & _puzzle_foler, int _stripes_n, int _samples_n, bool _real_flag);
~StripesSolver();
void m_metric();
bool reassemble(Metric _metric_mode,
Composition _composition_mode,
const string & case_name,
bool benchmark_flag);
cv::Mat compose_img(const vector<int> & composition_order,
bool shift_flag=false,
vector<int> * seq_x=nullptr);
cv::Mat add_seams( const cv::Mat & img,
const vector<int> & composition_order,
bool print_flag=true,
const vector<int> * seq_x=nullptr);
cv::Mat add_colorbar( const cv::Mat & img,
const vector<int> & composition_order,
bool print_flag,
const vector<int> * seq_x=nullptr);
private:
vector<time_t> ts_arr;
Metric metric_mode;
Composition composition_mode;
bool real_flag;
vector<StripePair> stripe_pairs;
void save_result(const string & case_name, bool benchmark_flag);
// Tesseract
const string tesseract_model_path {"data/tesseract_model/"};
// -- For synthetic cases
const double word_conf_thres {70};
const double lambda0 = 0.3;
const double lambda1 = 0.5;
const double U_a = 2;
const double filter_rate = 0.7;
const int candidate_factor {4};
// ---------------------
// -- For physically cases: --
// Common parameters, #samples = 10000
// const double word_conf_thres {70};// 60
// const double lambda0 = 0.5;
// const double lambda1 = 0.7;
// const double U_a = 1;
// For Real Case 1
// const double filter_rate = 0.2;
// const int candidate_factor {5};
// For Real Case 2
// const double filter_rate = 0.5;
// const int candidate_factor {3};
// For Real Case 3
// const double filter_rate = 0.6;
// const int candidate_factor {5};
// ---------------------
// Metric word-path
string white_chars, black_chars;
int candidate_seqs_n {10}; // Placeholder
int candidate_seq_len {10}; // Placeholder
vector< vector<double> > low_level_graph;
double m_metric_char(const cv::Mat & piece0, const cv::Mat & piece1, tesseract::TessBaseAPI * ocr, int idx=0);
void m_metric_word();
vector< vector<int> > reassemble_greedy();
void reassemble_GCOM();
// For word-path
void compute_mutual_graph(vector< vector<double> > & mutual_graph);
void stochastic_search( vector<int> & seq, const vector< vector<StripePair> > & compose_next);
void compute_word_scores(const vector< vector<int> > & candidate_seqs);
cv::Mat word_detection( const cv::Mat & img,
const vector<int> & seq,
vector<int> & seq_x,
tesseract::TessBaseAPI * ocr);
// For bigraph
void compute_bigraph_w(vector< vector<int> > & fragments, vector< vector<double> > & bigraph_w);
void optimal_match(vector< vector<int> > & fragments);
};
static omp_lock_t omp_lock;
#endif