-
Notifications
You must be signed in to change notification settings - Fork 1
/
stripes_solver.h
139 lines (110 loc) · 3.78 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
#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 <ocr_extractor.h>
#include <fragment.h>
#include <path_manager.h>
#include <utils.h>
#include <KM.h>
// #include <compatibility_net.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:
Metric metric_mode;
Composition composition_mode;
bool real_flag;
vector<StripePair> stripe_pairs;
vector<StripePair> stripe_pairs_pixel;
void save_result(const string & case_name, bool benchmark_flag);
// Tesseract
const string tesseract_model_path {"data/tesseract_model/"};
// tesseract::TessBaseAPI * ocr;
const double conf_thres {70};
const double lambda_ = 0.3;
const double filter_rate = 0.3;
// Compatibility
// const int symbols_n = 64;
// const cv::Size cp_net_img_size {64, 64};
// const string saved_model_folder = "data/saved_models/";
vector<char> symbols;
// OcrExtractor ocr_ectractor;
// CompatibilityNet cp_net;
// Device device {kCPU};
// Metric word-path
string white_chars, black_chars;
int candidate_seqs_n {10};
int candidate_seq_len {10};
const int candidate_factor {5};
vector< vector<double> > low_level_graph;
double m_metric_char(const cv::Mat & piece0, const cv::Mat & piece1, tesseract::TessBaseAPI * ocr, int idx=0);
// double m_metric_comp_eva(const cv::Mat & piece0, const cv::Mat & piece1);
void m_metric_word();
vector< vector<int> > reassemble_greedy();
void reassemble_GCOM();
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);
void pair_merge_frags(vector< vector<int> > & fragments);
void finetune_sols(const vector< vector<int> > & fragments);
};
static omp_lock_t omp_lock;
#endif