-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththresholder.h
More file actions
63 lines (54 loc) · 2.15 KB
/
thresholder.h
File metadata and controls
63 lines (54 loc) · 2.15 KB
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
/*
* Vectorix -- line-based image vectorizer
* (c) 2016 Jan Hadrava <had@atrey.karlin.mff.cuni.cz>
*/
#ifndef VECTORIX__THRESHOLDER_H
#define VECTORIX__THRESHOLDER_H
#include <opencv2/opencv.hpp>
#include "parameters.h"
#include "logger.h"
namespace vectorix {
class thresholder {
public:
thresholder(parameters ¶ms): par(¶ms) {
int *param_vectorizer_verbosity;
par->bind_param(param_vectorizer_verbosity, "vectorizer_verbosity", (int) log_level::warning);
log.set_verbosity((log_level) *param_vectorizer_verbosity);
par->add_comment("Phase 1: Thresholding");
par->add_comment("Invert colors: 0: white lines, 1: black lines");
par->bind_param(param_invert_input, "invert_colors", 1);
par->add_comment("Threshold type: 0: Otsu's algorithm, 1: Fixed value");
par->bind_param(param_threshold_type, "threshold_type", 0);
par->add_comment("Threshold value: 0-255");
par->bind_param(param_threshold, "threshold", 127);
par->add_comment("Adaptive threshold size: 3, 5, 7, ...");
par->bind_param(param_adaptive_threshold_size, "adaptive_threshold_size", 7);
par->add_comment("Save thresholded image to file: empty: no output");
par->bind_param(param_save_threshold_name, "file_threshold_output", (std::string) "");
par->add_comment("Fill holes (of given size) in lines: 0 = no filling");
par->bind_param(param_fill_holes, "fill_holes", 0);
par->add_comment("Remove dust (with smaller grains): 0 = no change");
par->bind_param(param_dust_size, "dust_size", 0);
par->add_comment("Save image with filled holes (and removed dust) to file: empty = no output");
par->bind_param(param_save_filled_name, "file_filled_output", (std::string) "");
}
void run(const cv::Mat &original, cv::Mat &binary);
void interactive(cv::TrackbarCallback onChange = 0, void *userdata = 0);
private:
int *param_invert_input;
int *param_threshold_type;
int *param_threshold;
int *param_adaptive_threshold_size;
std::string *param_save_threshold_name;
int *param_fill_holes;
int *param_dust_size;
std::string *param_save_filled_name;
logger log;
parameters *par;
cv::Mat grayscale;
cv::Mat binary;
cv::Mat filled;
int max_image_size;
};
}; // namespace
#endif