-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.hpp
149 lines (114 loc) · 3.21 KB
/
main.hpp
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
//
// test-color.hpp
// FetchMyBeer
//
// Created by Sami Farhat on 12/06/2016.
//
//
#ifndef test_color_hpp
#define test_color_hpp
#include <opencv2/opencv.hpp>
#include <map>
#include <vector>
#include <string>
#include "Trackbar.hpp"
#define CTRL_HLOW "hlow"
#define CTRL_HHIGH "hhigh"
#define CTRL_VLOW "vlow"
#define CTRL_VHIGH "vhigh"
#define CTRL_SLOW "slow"
#define CTRL_SHIGH "shigh"
#define CTRL_C "C"
#define CTRL_BLOCKSIZE "BlockSize"
#define CTRL_MIN_AREA "MinArea" // minimum area that a contour must satisfy
#define CTRL_COLOR_THRESH "ColorThresh" // which color do we want to threshold against
/** when set to non-zero this displays info on the console */
//#define CONSOLE_DEBUG 1
using std::map;
using std::vector;
using std::string;
using cv::Scalar;
std::string ctrlKeys[] = {
CTRL_C,
CTRL_BLOCKSIZE,
CTRL_MIN_AREA,
CTRL_COLOR_THRESH
};
const char* DISPLAY = "display";
const char* COLOR_CONTROLS = "colorControls";
const char* WINDOW_CONTROLS = "controls";
cv::RNG rng(12345);
Scalar whiteColor(255,255,255);
enum FMB_Colors {
NONE = 0,
BLUE = 1,
GREEN = 2,
RED = 3
} FMB_Colors;
/**
* @class HSV color range
*/
class FMB_ColorRange {
public:
/** constructor */
FMB_ColorRange(cv::Scalar _lowColor, cv::Scalar _highColor)
{
lowColor = _lowColor;
highColor = _highColor;
}
Scalar getLowColor() { return lowColor; }
Scalar getHighColor() { return highColor; }
private:
Scalar lowColor;
Scalar highColor;
};
/**
* @class Main
*/
class Main {
public:
/** initialise */
void init();
/** start running (too vague I know) */
void start();
/** thresholds the image for colors in the ranges given in controls dict */
void colorThreshold(cv::InputArray in, cv::OutputArray out);
void highlightContours(cv::InputOutputArray img,
std::vector<std::vector<cv::Point>> contours);
/** de-initialise */
void deinit();
int getColorRangesCount() { return colorRangesCount; }
std::map<enum FMB_Colors, vector<FMB_ColorRange*>> getColorRanges() {
return colorRanges;
}
map<string, Trackbar*> getControls() { return controls; }
// TODO(sami): return const_iterator instead of the whole vector
/** returns a vector of trackbars that control HSV ranges */
vector<Trackbar*> getHSVTrackbars();
private:
struct TrackbarData {
/** reference to main class, this is to allow access Main's functions inside
* trackbarChange */
Main* main;
/** name of the trackbar that incurred the change event */
std::string name;
};
std::map<enum FMB_Colors, vector<FMB_ColorRange*>> colorRanges;
map<string, Trackbar*> controls;
/**
* this variable facilitates accessing the right color-control keys from the
* 'controls' map. It allows us to get the values for keys like HHIGH_1, HHIGH_2
* the 1 and 2.. are known through this variable
* The expected value fo 'colorRangesCount' is 2 because of the presence of RED
* which needs two ranges in the HSV spectrum.
*/
int colorRangesCount = -1;
// -------
// Methods
// -------
/** */
void createTrackbars();
/** */
void initColorRanges();
};
#endif /* test_color_hpp */