00001
00024 #ifndef __D_CV_GUI__
00025 #define __D_CV_GUI__
00026
00027 #include <vector>
00028 #include <queue>
00029 #include <opencv/cv.h>
00030 #include <string>
00031
00032 namespace DUtilsCV
00033 {
00034
00036 class GUI
00037 {
00038 public:
00039 class MouseHandler;
00040
00041 public:
00042
00044 enum tKey
00045 {
00046 NO_KEY = 0,
00047 BACKSPACE = 8,
00048 TAB = 9,
00049 ESC = 27,
00050 ENTER = 10,
00051 SPACEBAR = 32,
00052 LEFT_ARROW = 81,
00053 UP_ARROW = 82,
00054 RIGHT_ARROW = 83,
00055 DOWN_ARROW = 84,
00056 PAGE_UP = 85,
00057 PAGE_DOWN = 86,
00058 HOME = 80,
00059 END = 87,
00060 INS = 99,
00061
00062
00063 KP_CENTER = -99,
00064 KP_SW = -100,
00065 KP_SE = -101,
00066 KP_NE = -102,
00067 KP_S = -103,
00068 KP_E = -104,
00069 KP_N = -105,
00070 KP_W = -106,
00071 KP_NW = -107,
00072 KP_INS = -98,
00073 KP_SUP = -97,
00074 KP_ENTER = -115,
00075 KP_PLUS = -85,
00076 KP_MINUS = -83,
00077 KP_SLASH = -81,
00078 KP_ASTERISK = -86,
00079 KP_POINT = -82,
00080
00081 KP_0 = -80,
00082 KP_1 = -79,
00083 KP_2 = -78,
00084 KP_3 = -77,
00085 KP_4 = -76,
00086 KP_5 = -75,
00087 KP_6 = -74,
00088 KP_7 = -73,
00089 KP_8 = -72,
00090 KP_9 = -71
00091 };
00092
00094 typedef std::string tWinHandler;
00095
00096 public:
00097
00109 static int showImage(const cv::Mat &image, bool autosize = true,
00110 tWinHandler *hwnd = NULL, int timeout = 0);
00111
00124 static int showImageInfo(const cv::Mat &image, bool autosize = true,
00125 tWinHandler *hwnd = NULL);
00126
00132 static bool windowExists(const tWinHandler &hwnd);
00133
00138 static void destroyWindow(const tWinHandler &hwnd);
00139
00148 static bool showSystemImage(const cv::Mat &image,
00149 const std::string &tmp_file = "tmp.png",
00150 const std::string &app = "eog");
00151
00152 };
00153
00154
00155
00156
00160 class GUI::MouseHandler
00161 {
00162 public:
00163
00165 struct tEvent
00166 {
00167 int x, y;
00168 int event;
00169 int flags;
00170
00171 tEvent(){}
00172 tEvent(int _x, int _y, int _event, int _flags)
00173 : x(_x), y(_y), event(_event), flags(_flags){}
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186 };
00187
00188 public:
00189
00193 MouseHandler();
00194
00198 virtual ~MouseHandler();
00199
00207 void attach(const tWinHandler &hwnd,
00208 const std::vector<int> &events = std::vector<int>());
00209
00215 void attachToClicks(const tWinHandler &hwnd);
00216
00222 void attachToMotions(const tWinHandler &hwnd);
00223
00228 inline bool attached() const { return m_attached; }
00229
00234 void listen(int event);
00235
00239 void listenToAll();
00240
00245 void ignore(int event);
00246
00252 bool get(tEvent &event);
00253
00258 inline bool empty() const;
00259
00260 protected:
00261
00270 static void callbackHandlerFunction(int event, int x, int y, int flags,
00271 void *pMouseHandler);
00272
00273 protected:
00274
00275 bool m_attached;
00276
00278 std::queue<tEvent> m_events;
00279
00281 std::vector<int> m_valid_events;
00282
00283 };
00284
00285 inline bool GUI::MouseHandler::empty() const
00286 {
00287 return m_events.empty();
00288 }
00289
00290 }
00291
00292 #endif
00293