$search
00001 #ifndef GCAPPLICATION 00002 #define GCAPPLICATION 00003 00004 #include <opencv2/highgui/highgui.hpp> 00005 #include <opencv2/core/core.hpp> 00006 #include <opencv2/imgproc/imgproc.hpp> 00007 #include <iostream> 00008 #include <ros/ros.h> 00009 00010 using namespace std; 00011 using namespace cv; 00012 00013 class GCApplication 00014 { 00015 public: 00016 /* States of grabbing/marking action */ 00017 enum GrabState { NOT_SET, IN_PROCESS, SET }; 00018 00019 /* States of OpenCV window -- updated if the window has been redisplayed 00020 * since the last change to the image, stale otherwise. */ 00021 enum WinImageState { UPDATED, STALE }; 00022 00023 /* Allowed background colors for OpenCV window */ 00024 enum WinColor { BLACK, GRAY, WHITE, GREEN, BLUE }; 00025 00026 /* Marker for default rectangle. */ 00027 static const Rect DEFAULT_RECT; 00028 00029 /* Constructor/destructor */ 00030 GCApplication(const string& _name, Mat _img); 00031 ~GCApplication(); 00032 00033 /* Accessors for application state */ 00034 inline bool initialized() { return initialized_; } 00035 void initializedIs(bool); 00036 00037 /* Accessors/mutators for base image and mask */ 00038 inline Mat image() { return image_; } 00039 void imageIs(const Mat&); 00040 inline Mat mask() { return mask_; } 00041 Mat binaryMask(); 00042 00043 /* Mutator for GC rectangle. */ 00044 void rectIs(const Rect&); 00045 00046 /* Accessors/mutators for OpenCV window attributes */ 00047 inline string winName() { return win_name_; } 00048 inline WinImageState winImageState() { return win_image_state_; } 00049 void winImageStateIs(WinImageState); 00050 inline WinColor winColor() { return win_color_; } 00051 void winColorIs(WinColor _c); 00052 00053 /* Accessor for state variables */ 00054 inline GrabState rectState() { return rect_state_; } 00055 00056 /* Mouse callback for image topic subscription */ 00057 void mouseClick( int event, int x, int y, int flags); 00058 00059 /* Iteration control accessors */ 00060 inline int iterCount() const { return iter_count_; } 00061 void iterCountIs(int _icnt); 00062 inline void iterCountInc() { iterCountIs(iterCount()+1); } 00063 00064 private: 00065 /* Transfer marked rectangle to mask image */ 00066 void setRectInMask(); 00067 /* Transfer marked labels to mask image */ 00068 void setLblsInMask( int flags, Point p, bool isPr ); 00069 00070 /* Current state of OpenCV window image */ 00071 WinImageState win_image_state_; 00072 WinColor win_color_; 00073 00074 /* Segmentation process data */ 00075 string win_name_; // Name of OpenCV window 00076 Mat image_; // image to be segmented 00077 Mat mask_; // fg/bg mask for grabcut algo. 00078 Mat bgd_model_, fgd_model_; // temporary arrays used in segmentation 00079 Rect rect_; // marked rectangle 00080 vector<Point> fgd_pxls_; // definite foreground points 00081 vector<Point> bgd_pxls_; // definite background points 00082 vector<Point> pr_fgd_pxls_; // probable foreground points 00083 vector<Point> pr_bgd_pxls_; // probable background points 00084 int iter_count_; // number of most recent completed iteration 00085 00086 /* Current state of grabbing / marking process */ 00087 GrabState rect_state_, lbls_state_, pr_lbls_state_; 00088 00089 /* Used to allow client to return application to uninitialized state. */ 00090 bool initialized_; 00091 00092 }; 00093 00094 00095 #endif