segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
lumaChroma.h
1 /*
2  * Copyright (C) 2011 Department of Robotics Brain and Cognitive Sciences - Istituto Italiano di Tecnologia
3  * Authors: Vadim Tikhanoff
4  * email: vadim.tikhanoff@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef __ICUB_LUMACHROMA_H__
20 #define __ICUB_LUMACHROMA_H__
21 
22 #include <iostream>
23 #include <string>
24 #include <mutex>
25 
26 #include <yarp/sig/Image.h>
27 #include <yarp/os/BufferedPort.h>
28 #include <yarp/os/RFModule.h>
29 #include <yarp/os/Network.h>
30 #include <yarp/os/Time.h>
31 
32 #include <opencv2/opencv.hpp>
33 
34 #include "centsur.h"
35 
36 class PROCThread : public yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> >
37 {
38 private:
39  bool check;
40  std::string moduleName; //string containing module name
41  std::string whichPort; //string containing the default output name
42  std::string inputPortName; //string containing input port name
43  std::string outputPortName; //string containing output default port name for propagating same input image
44  std::string outputPortName1; //string containing output port name, intensity or hue
45  std::string outputPortName2; //string containing output port name, UV or saturation
46  std::string outputPortName3; //string containing output port name, value
47  std::string outputPortNameDefault; //string containing output port name, default
48 
49  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> > imageOutPort; //output port propagating input Image
50  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono> > imageOutPort1; //output port intensity or hue process
51  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono> > imageOutPort2; //output port colour(UV) or saturation process
52  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono> > imageOutPort3; //output port value process
53 
54  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono> > defaultPortOut; //default output port for all image types
55 
56  yarp::sig::ImageOf<yarp::sig::PixelRgb> *inputExtImage; // extended input image
57 
58  yarp::sig::ImageOf<yarp::sig::PixelMono> *img_Y; // extended output image, also reused for hsv
59  yarp::sig::ImageOf<yarp::sig::PixelMono> *img_UV; // extended output image, also reused for hsv
60  yarp::sig::ImageOf<yarp::sig::PixelMono> *img_V; // extended output image, also reused for hsv
61  yarp::sig::ImageOf<yarp::sig::PixelMono> *img_out_Y; // output image, also reused for hsv
62  yarp::sig::ImageOf<yarp::sig::PixelMono> *img_out_UV; // output image, also reused for hsv
63  yarp::sig::ImageOf<yarp::sig::PixelMono> *img_out_V; // output image, only used for hsv
64 
65  cv::Size srcsize, origsize; // sises used for calculations
66  int ncsscale; // center surround scale
67  bool allocated; // flag to check if the variables have been already allocated
68  bool isYUV; // flag to check which process to run (YUV or HSV)
69 
70  std::mutex mtx;
71  CentSur * centerSurr;
72  cv::Mat orig, uvimg, csTot32f;
73 
79  yarp::sig::ImageOf<yarp::sig::PixelRgb>* extender(yarp::sig::ImageOf<yarp::sig::PixelRgb>& inputOrigImage, int maxSize);
80 
81 public:
87  PROCThread(const std::string &moduleName, const std::string &imgType, const std::string &whichPort);
88 
92  ~PROCThread();
93 
94  bool open();
95  void close();
96  void onRead(yarp::sig::ImageOf<yarp::sig::PixelRgb> &img);
97  void allocate(yarp::sig::ImageOf<yarp::sig::PixelRgb> &img);
98  void deallocate();
99  void interrupt();
100 
101  void afterStart(bool s)
102  {
103  if (s)
104  std::cout<<"Thread started successfully"<< std::endl;
105  else
106  std::cout<<"Thread did not start"<< std::endl;
107  }
108 };
109 
110 class lumaChroma : public yarp::os::RFModule
111 {
112  /* module parameters */
113  std::string moduleName; //string containing the module name passed to the thread
114  std::string imageType; //string containing the image type passed to the thread
115  std::string handlerPortName; //string containing the name of the handler port
116  std::string whichPort; //string containing the name of the defualt port
117 
118  yarp::os::Port handlerPort; //port to handle messages
119 
120  /* pointer to the working thread */
121  PROCThread *procThread;
122 
123 public:
124 
125  bool configure(yarp::os::ResourceFinder &rf); // configure all the module parameters and return true if successful
126  bool interruptModule(); // interrupt, e.g., the ports
127  bool close(); // close and shut down the module
128  bool respond(const yarp::os::Bottle& command, yarp::os::Bottle& reply);
129  double getPeriod();
130  bool updateModule();
131 };
132 
133 #endif
134 
135 //empty line to make gcc happy
136 
137 
An implementation modelling the centre-surround response, used for construction of spatial uniqueness...