segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
SegmModule.h
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2012 Elena Ceseracciu, RBCS - Istituto Italiano di Tecnologia
5  * CopyPolicy: Released under the terms of the GNU GPL v2.0 and later.
6  *
7  */
8 
9 #ifndef __SEGMMODULE__
10 #define __SEGMMODULE__
11 
12 #include <mutex>
13 
14 // yarp
15 #include <yarp/os/all.h>
16 #include <yarp/sig/all.h>
17 #include <yarp/os/RFModule.h>
18 #include <yarp/os/ResourceFinder.h>
19 #include <yarp/os/Stamp.h>
20 
27 #include "image.h"
28 #include "misc.h"
29 #include "SegmentationModuleInterface.h" //Thrift interface
30 
31 class GBSegmModule : public yarp::os::RFModule, public yarp::sig::SegmentationModuleInterface {
32 
33 private:
34  double _timestart;
35 
36  float sigma;
37  float k;
38  int min_size;
39  int num_components;
40 
41  image<rgb> *input;
42  image<rgb> *seg;
43 
44  std::mutex segMutex;
45 
46  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _imgPort; //input image
47  // yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _rawPort; //raw image
48  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _viewPort; //output image - segmentation (modes of each detected object), edges, etc (configurable)
49  // yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelInt> > _labelPort; //output image with labels
50  // yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > _filtPort; //output the mean shift filtered image
51  yarp::os::Port _configPort; //to configure the module
52  // yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono> > _labelViewPort; //to visualize the labels
53 
54  yarp::os::Stamp _stamp;
55 
56 public:
57  GBSegmModule();
58  ~GBSegmModule();
59 
60  virtual bool configure (yarp::os::ResourceFinder &rf);
61  //virtual bool open(yarp::os::Searchable& config);
62  virtual bool close();
63  virtual bool interruptModule();
64  virtual bool updateModule();
65 
66  bool attach(yarp::os::Port &source)
67  {
68  return this->yarp().attachAsServer(source);
69  }
70 
71  // rpc interface on _configPort
72  virtual void set_sigma(const double newValue);
73  virtual void set_k(const double newValue);
74  virtual void set_minRegion(const double newValue);
75  virtual double get_sigma();
76  virtual double get_k();
77  virtual double get_minRegion();
78  virtual int32_t get_num_components();
79  virtual std::vector<yarp::sig::Pixel> get_component_around(const yarp::sig::Pixel& objCenter);
80 };
81 
82 
83 #endif
84 
Segmentation Module.
Definition: SegmModule.h:31
virtual std::vector< yarp::sig::Pixel > get_component_around(const yarp::sig::Pixel &objCenter)
Get the list of pixels corresponding to the component to which a given pixel belongs.
Definition: SegmModule.cpp:71
virtual void set_k(const double newValue)
Set k (scale factor for boundary-detection threshold function) parameter for the algorithm.
Definition: SegmModule.cpp:65
virtual double get_minRegion()
Get minRegion parameter for the algorithm, i.e., the minimum size of any segmented component.
Definition: SegmModule.cpp:69
virtual void set_sigma(const double newValue)
Set sigma (smoothing) parameter for the algorithm.
Definition: SegmModule.cpp:64
virtual double get_k()
Get k (scale factor for boundary-detection threshold function) parameter for the algorithm.
Definition: SegmModule.cpp:68
virtual int32_t get_num_components()
Get the number of segmented components that have been detected in the last provided image.
Definition: SegmModule.cpp:70
virtual void set_minRegion(const double newValue)
Set minRegion parameter for the algorithm, i.e., the minimum size of any segmented component.
Definition: SegmModule.cpp:66
virtual double get_sigma()
Get sigma (smoothing) parameter for the algorithm.
Definition: SegmModule.cpp:67
Pixel position in the image frame.
Definition: Pixel.h:28
Interface for module that performs graph-based segmentation.