Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | PointedEar | 1 | #if !defined CD_CNTRLLR |
2 | #define CD_CNTRLLR |
||
3 | |||
4 | #include <opencv2/core/core.hpp> |
||
5 | #include <opencv2/highgui/highgui.hpp> |
||
6 | #include "colordetector.h" |
||
7 | |||
8 | class ColorDetectController { |
||
9 | |||
10 | private: |
||
11 | |||
12 | static ColorDetectController *singleton; // pointer to the singleton |
||
13 | |||
14 | ColorDetector *cdetect; |
||
15 | |||
16 | // The image to be processed |
||
17 | cv::Mat image; |
||
18 | cv::Mat result; |
||
19 | |||
20 | public: |
||
21 | ColorDetectController() { // private constructor |
||
22 | |||
23 | //setting up the application |
||
24 | cdetect= new ColorDetector(); |
||
25 | } |
||
26 | |||
27 | // Sets the color distance threshold |
||
28 | void setColorDistanceThreshold(int distance) { |
||
29 | |||
30 | cdetect->setColorDistanceThreshold(distance); |
||
31 | } |
||
32 | |||
33 | // Gets the color distance threshold |
||
34 | int getColorDistanceThreshold() const { |
||
35 | |||
36 | return cdetect->getColorDistanceThreshold(); |
||
37 | } |
||
38 | |||
39 | // Sets the color to be detected |
||
40 | void setTargetColor(unsigned char red, unsigned char green, unsigned char blue) { |
||
41 | |||
42 | cdetect->setTargetColor(red,green,blue); |
||
43 | } |
||
44 | |||
45 | // Gets the color to be detected |
||
46 | void getTargetColor(unsigned char &red, unsigned char &green, unsigned char &blue) const { |
||
47 | |||
48 | cv::Vec3b color= cdetect->getTargetColor(); |
||
49 | |||
50 | red= color[2]; |
||
51 | green= color[1]; |
||
52 | blue= color[0]; |
||
53 | } |
||
54 | |||
55 | // Sets the input image. Reads it from file. |
||
56 | bool setInputImage(std::string filename) { |
||
57 | |||
58 | image= cv::imread(filename); |
||
59 | |||
60 | if (!image.data) |
||
61 | return false; |
||
62 | else |
||
63 | return true; |
||
64 | } |
||
65 | |||
66 | // Returns the current input image. |
||
67 | const cv::Mat getInputImage() const { |
||
68 | |||
69 | return image; |
||
70 | } |
||
71 | |||
72 | // Performs image processing. |
||
73 | void process() { |
||
74 | |||
75 | result= cdetect->process(image); |
||
76 | } |
||
77 | |||
78 | |||
79 | // Returns the image result from the latest processing. |
||
80 | const cv::Mat getLastResult() const { |
||
81 | |||
82 | return result; |
||
83 | } |
||
84 | |||
85 | // Deletes all processor objects created by the controller. |
||
86 | ~ColorDetectController() { |
||
87 | |||
88 | delete cdetect; |
||
89 | } |
||
90 | |||
91 | // Singleton static members |
||
92 | static ColorDetectController *getInstance() { |
||
93 | |||
94 | if (singleton == 0) |
||
95 | singleton= new ColorDetectController; |
||
96 | |||
97 | return singleton; |
||
98 | } |
||
99 | |||
100 | // Releases the singleton instance of this controller. |
||
101 | static void destroy() { |
||
102 | |||
103 | if (singleton != 0) { |
||
104 | delete singleton; |
||
105 | singleton= 0; |
||
106 | } |
||
107 | } |
||
108 | }; |
||
109 | |||
110 | #endif |