segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
EdisonSegmModule.h
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2009 Alex Bernardino, Vislab, IST/ISR
5  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
6  *
7  */
8 
9 #ifndef __EDISONSEGMMODULE__
10 #define __EDISONSEGMMODULE__
11 
12  // std
13 #include <stdio.h>
14 
15 
16 // OpenCV
17 #include <opencv2/opencv.hpp>
18 
19 // yarp
20 #include <yarp/os/all.h>
21 #include <yarp/sig/all.h>
22 #include <yarp/os/RFModule.h>
23 #include <yarp/os/ResourceFinder.h>
24 #include <yarp/os/Stamp.h>
25 
32 #include <segm/msImageProcessor.h>
33 #include "SegmentationModule.h"
34 
35 class EdisonSegmModule : public yarp::os::RFModule, public SegmentationModule {
36 
37 private:
38  double _timestart;
39  int orig_height_, height_, orig_width_, width_, dim_; //input image dimensions
40 
41  //internal storage for the input image - must be RGB
42  yarp::sig::ImageOf<yarp::sig::PixelRgb> inputImage;
43  unsigned char * inputImage_;
44 
45  //internal storage for hsv image, only needed for dim = 1.
46  yarp::sig::ImageOf<yarp::sig::PixelRgb> inputHsv;
47  unsigned char * inputHsv_;
48 
49  //internal storage for hue channel, only needed for dim = 1.
50  yarp::sig::ImageOf<yarp::sig::PixelMono> inputHue;
51  unsigned char * inputHue_;
52 
53  //store the weight maps
54  yarp::sig::ImageOf<yarp::sig::PixelFloat> gradMap;
55  float * gradMap_;
56 
57  yarp::sig::ImageOf<yarp::sig::PixelFloat> confMap;
58  float * confMap_;
59 
60  yarp::sig::ImageOf<yarp::sig::PixelFloat> weightMap;
61  float * weightMap_;
62 
63  //float * custMap_; //????? Is this really needed
64 
65  //storage for the output images
66  yarp::sig::ImageOf<yarp::sig::PixelRgb> filtImage;
67  unsigned char * filtImage_;
68 
69  yarp::sig::ImageOf<yarp::sig::PixelRgb> segmImage;
70  unsigned char * segmImage_;
71 
72  yarp::sig::ImageOf<yarp::sig::PixelInt> labelImage;
73 
74  yarp::sig::ImageOf<yarp::sig::PixelMono> labelView; // for visualizing the labels - debug stuff
75 
76  //store the output edges and boundaries
77  int *edges_, numEdges_;
78  int *boundaries_, numBoundaries_;
79 
80  //parameters for mean shift
81  int sigmaS; //spatial bandwidth
82  float sigmaR; //range bandwidth
83  int minRegion; //area of the smallest objects to consider
84 
85  //parameters for synergistic segmentation
86  int gradWindRad; //Gradient Window Radius
87  float threshold; //Edge Strength Threshold [0,1]
88  float mixture; //Mixture Parameter [0,1]
89 
90  SpeedUpLevel speedup; //{NO_SPEEDUP, MED_SPEEDUP, HIGH_SPEEDUP}
91  void setSpeedUpValue(int newSpeedUpValue);
92 
93  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _imgPort; //input image
94  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _rawPort; //raw image
95  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _viewPort; //output image - segmentation (modes of each detected object), edges, etc (configurable)
96  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelInt> > _labelPort; //output image with labels
97  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _filtPort; //output the mean shift filtered image
98  yarp::os::Port _configPort; //to configure the module
99  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono> > _labelViewPort; //to visualize the labels
100 
101  yarp::os::Stamp _stamp;
102 
103 public:
105  ~EdisonSegmModule();
106 
107  virtual bool configure (yarp::os::ResourceFinder &rf);
108  //virtual bool open(yarp::os::Searchable& config);
109  virtual bool close();
110  virtual bool interruptModule();
111  virtual bool updateModule();
112 
113  bool attach(yarp::os::Port &source)
114  {
115  return this->yarp().attachAsServer(source);
116  }
117 
118  // rpc interface on _configPort
119  virtual void set_sigmaS(const double newValue){sigmaS=(int)newValue;};
120  virtual void set_sigmaR(const double newValue){sigmaR=(float)newValue;};
121  virtual void set_minRegion(const double newValue){minRegion=(int)newValue;};
122  virtual void set_gradWindRad(const double newValue){gradWindRad=(int)newValue;};
123  virtual void set_threshold(const double newValue){newValue <=1 ? threshold=(float)newValue: threshold=1; if (threshold <0) threshold =0;};
124  virtual void set_mixture(const double newValue){newValue <=1 ? mixture=(float)newValue: mixture=1; if (mixture<0 ) mixture=0;};
125  virtual void set_speedup(const SpeedUpLevelComm newSpeedLevel){setSpeedUpValue(newSpeedLevel);};
126  virtual double get_sigmaS(){return sigmaS;};
127  virtual double get_sigmaR(){return sigmaR;};
128  virtual double get_minRegion(){return minRegion;};
129  virtual double get_gradWindRad(){return gradWindRad;};
130  virtual double get_threshold(){return threshold;};
131  virtual double get_mixture(){return mixture;};
132  virtual SpeedUpLevelComm get_speedup(){return SpeedUpLevelComm(speedup);};
133 
134 };
135 
136 
137 #endif
138 
Edison Segmentation Module.