-
Notifications
You must be signed in to change notification settings - Fork 1
/
stripes_solver.h
102 lines (78 loc) · 2.46 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
#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 <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 <compatibility_net.h>
#include <stripe_pair.h>
using namespace std;
class StripesSolver {
public:
enum Metric {
PIXEL,
WORD,
COMP_EVA
};
enum Composition {
GREEDY,
GREEDY_PROBABILITY
};
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;
// Path
PathManager path_manager;
StripesSolver(const string & _puzzle_foler, int _stripes_n, int _samples_n);
~StripesSolver();
void m_metric();
bool reassemble(Metric _metric_mode, Composition _composition_mode);
cv::Mat compose_img(const vector<int> & composition_order);
cv::Mat add_seams(const cv::Mat & img, const vector<int> & composition_order);
void save_result(const string & case_name);
private:
Metric metric_mode;
Composition composition_mode;
vector<StripePair> stripe_pairs;
// Tesseract
const string tesseract_model_path {"data/tesseract_model/"};
tesseract::TessBaseAPI * ocr;
const double conf_thres {80};
// Compatibility
const double filter_rate = 1;
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
int sols_n = 10;
vector< vector<double> > pixel_graph;
double m_metric_pixel(const cv::Mat & piece0, const cv::Mat & piece1);
double m_metric_word(const cv::Mat & piece0, const cv::Mat & piece1);
double m_metric_comp_eva(const cv::Mat & piece0, const cv::Mat & piece1);
vector< vector<int> > reassemble_greedy(bool probability_flag=false);
void reassemble_greedy_probability();
cv::Mat word_detection( const cv::Mat & img,
const vector<int> & sol,
int sol_cnt=1);
void finetune_sols(const vector< vector<int> > & composition_orders);
};
#endif