-
Notifications
You must be signed in to change notification settings - Fork 2
/
cvplot.hxx
169 lines (130 loc) · 3.29 KB
/
cvplot.hxx
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// Matlab style plot functions for OpenCV by Changbo (zoccob@gmail).
// plot and label:
//
// template<typename T>
// void plot(const string figure_name, const T* p, int count, int step = 1,
// int R = -1, int G = -1, int B = -1);
//
// figure_name: required. multiple calls of this function with same figure_name
// plots multiple curves on a single graph.
// p : required. pointer to data.
// count : required. number of data.
// step : optional. step between data of two points, default 1.
// R, G,B : optional. assign a color to the curve.
// if not assigned, the curve will be assigned a unique color automatically.
//
// void label(string lbl):
//
// label the most recently added curve with lbl.
//
//
//
//
#pragma once
#if WIN32
#define snprintf sprintf_s
#endif
#include <vector>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;
using namespace std;
namespace CvPlot
{
// A curve.
class Series
{
public:
// number of points
unsigned int count;
float *data;
// name of the curve
string label;
// allow automatic curve color
bool auto_color;
cv::Scalar color;
Series(void);
Series(const Series& s);
~Series(void);
// release memory
void Clear();
void SetData(int n, float *p);
void SetColor(cv::Scalar color, bool auto_color = true);
void SetColor(int R, int G, int B, bool auto_color = true);
};
// a figure comprises of several curves
class Figure
{
private:
// window name
string figure_name;
cv::Size figure_size;
// margin size
int border_size;
cv::Scalar backgroud_color;
cv::Scalar axis_color;
cv::Scalar text_color;
// several curves
vector<Series> plots;
// manual or automatic range
bool custom_range_y;
float y_max;
float y_min;
float y_scale;
bool custom_range_x;
float x_max;
float x_min;
float x_scale;
// automatically change color for each curve
int color_index;
public:
Figure(const string name);
~Figure();
string GetFigureName();
Series* Add(const Series &s);
void DrawLabels(cv::Mat &output, int posx, int posy);
// show plot window
void Show();
void Clear();
void setCustomYRange(float ymin, float ymax)
{
custom_range_y=true;
y_max=ymax;
y_min=ymin;
}
private:
Figure();
void DrawAxis(cv::Mat &output);
void DrawPlots(cv::Mat &output);
// call before plot
void Initialize();
cv::Scalar GetAutoColor();
};
// manage plot windows
class PlotManager
{
private:
vector<Figure> figure_list;
Series *active_series;
Figure *active_figure;
public:
// now useless
bool HasFigure(string wnd);
Figure* FindFigure(string wnd);
Figure* AddFigure(string wnd)
{
Figure new_figure(wnd);
figure_list.push_back(wnd);
return FindFigure(wnd);
}
void Plot(const string figure_name, const float* p, int count, int step,
int R, int G, int B);
void Label(string lbl);
};
// handle different data types; static mathods;
template<typename T>
void plot(const string figure_name, const T* p, int count, int step = 1,
int R = -1, int G = -1, int B = -1);
void label(string lbl);
PlotManager *getPlotManager();
};