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
   | #include "Common.hpp" #include "MyDraw.hpp"
  class Segmentation: public Draw { public:          Segmentation(int width, int height, unsigned topk = 5, short t = 3);     Segmentation(Size sz, unsigned topk = 5, short t = 3);          void Segment(Mat& depth);     void Segment(Mat& depth, Mat& color);           * @brief DFS: depth first search with recurrsive methold, but easy to stack overflow      * @param depth         depth data      * @param visit         marked visited point      * @param cur           current point position      * @param threshold     the max value between extend point      * @param v             from current point, a segment point set      */     void DFS(Mat& depth, Mat& visit, Point cur, short& threshold, PointSet& v);           * @brief NonRecursive: prevent stack overflow      * @param depth     depth data      * @param visit     marked visited point      * @param cur       current point position      * @param pSet      from current point, a segment point set      */     void NonRecursive(Mat& depth, Mat& visit, Point& cur, PointSet& pSet);          void completeDepth(Mat& depth);          void clear();          SegmentSet& getMainRegions()    {return mainRegions_;}     SegmentSet& getBlackRegions()   {return blackRegions_;}     vector<double>& getDistance()    {return distance_;}
  private:           * @brief regionMerge: merge small region and black points to Main Regions      * @param depth     depth data      * @param minSim    0.0 - 1.0      */     void regionMerge(Mat& depth, double minSim);           * @brief hullBoundBox: get the each region convexHull's bounding box      * @param hull  the vertices of Convex hull      * @return bounding box      */     Rect hullBoundBox(PointSet& hull);           * @brief isRegionInsideHull: determine if small or black regions belongs to one Main Region      * @param pSet      small region / black region      * @param hull      Convex hull      * @param minSim    0.0 - 1.0      * @return  in / not in      */     bool isRegionInsideHull(PointSet& pSet, PointSet& hull, double minSim);     bool isRegionInsideHull(PointSet& pSet, PointSet& hull, PointSet& seg, double minSim);          void randColor();          virtual void drawRotateRect(Mat& src, RotatedRect& rr);     virtual void drawConvexHull(Mat& src, PointSet& hull, Scalar color);     virtual void drawBlack(SegmentSet& blackRegions, Mat& disp, Vec3b& color);     virtual void draw(SegmentSet& segment, Mat& disp, vector<Vec3b>& colors);     virtual void drawBoundBox(SegmentSet& segment, vector<double>& distance, Mat& color, Mat& depth);     virtual void drawRegions(SegmentSet& segment, Mat& color, Mat& depth, Mat& disp);     virtual void drawSobel(Mat& depth);
  private:          static const vector<Point> _DIRECTIONS_;          static const vector<Point> _DIR_;          vector<Vec3b> colors_;          Rect RANGE_;          short threshold_;          unsigned topk_;          SegmentSet mainRegions_;     SegmentSet blackRegions_;     vector<double> distance_; };
   |