5 #include <opencv2/opencv.hpp>
7 #include <vision_module/Tools/LineSegment.hpp>
8 #include <vision_module/Tools/General.hpp>
13 void CallBackFuncCT(
int event,
int x,
int y,
int flags,
void* userdata);
23 vector<vector<Point> > Contours;
26 vector<Scalar> colors;
28 inline ContourTester(Size box,
size_t _max = 2,
string _name =
30 name(_name), Max(_max)
32 Image = Mat::zeros(box, CV_8UC3);
35 setMouseCallback(name, CallBackFuncCT,
this);
36 Contours.push_back(vector<Point>());
37 colors.push_back(randColor());
39 inline bool IsReady(
size_t count)
41 return Contours.size() > count
42 && Contours[Contours.size() - 1].size() > 2;
46 return Contours.size() > Max && Contours[Contours.size() - 1].size() > 2;
48 inline void Show(
int wait = 1)
50 for (
size_t i = 0; i < Contours.size(); i++)
52 if (Contours.size() - 1 == i)
54 drawContours(Image, Contours, i, redColor(), 2);
58 drawContours(Image, Contours, i, colors[i], 1);
61 if(Contours[Contours.size() - 1].size() == 1)
63 circle(Image,Contours[Contours.size() - 1][0],2,redColor(),1);
67 Image = Mat::zeros(Image.size(), CV_8UC3);
71 void CallBackFuncCT(
int event,
int x,
int y,
int flags,
void* userdata)
74 if (event == EVENT_RBUTTONUP)
76 if (data->Contours[data->Contours.size() - 1].size() > 0)
78 data->Contours[data->Contours.size() - 1].pop_back();
82 if (data->Contours.size() > 1)
84 data->Contours.pop_back();
85 data->colors.pop_back();
89 else if (event == EVENT_MBUTTONDOWN)
91 if (data->Contours[data->Contours.size() - 1].size() < 3)
93 data->Contours.push_back(vector<Point>());
94 data->colors.push_back(randColor());
96 else if (event == EVENT_LBUTTONUP)
98 data->Contours[data->Contours.size() - 1].push_back(Point(x, y));
A container class for testing countours.
Definition: ContourTester.hpp:19