segmentation
All Data Structures Namespaces Files Functions Variables Modules Pages
dispBlobberModule.hpp
1 /*
2  * Copyright (C) 2015 iCub Facility - Istituto Italiano di Tecnologia
3  * Authors: Tanis Mar, Giulia Pasquale
4  * email: tanis.mar@iit.it, giulia.pasquale@iit.it
5  * Permission is granted to copy, distribute, and/or modify this program
6  * under the terms of the GNU General Public License, version 2 or any
7  * later version published by the Free Software Foundation.
8  *
9  * A copy of the license can be found at
10  * http://www.robotcub.org/icub/license/gpl.txt
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15  * Public License for more details
16  */
17 
18 #ifndef __DISPBLOBBERMODULE_H__
19 #define __DISPBLOBBERMODULE_H__
20 
21 #include <yarp/os/BufferedPort.h>
22 #include <yarp/os/RpcClient.h>
23 #include <yarp/os/RFModule.h>
24 #include <yarp/os/Network.h>
25 #include <yarp/os/Time.h>
26 #include <yarp/os/Stamp.h>
27 
28 #include <yarp/sig/Vector.h>
29 #include <yarp/sig/Image.h>
30 
31 #include <time.h>
32 #include <string>
33 #include <iostream>
34 #include <mutex>
35 
36 #include "dispBlobber.hpp"
37 
38 class DispBlobberPort : public yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelBgr> >
39 {
40 private:
41 
42  std::string moduleName;
43 
44  yarp::os::ResourceFinder *moduleRF;
45 
46  std::string imgInPortName;
47 
48  std::string blobsOutPortName;
49  std::string blobsOutPortRightName;
50  std::string points3dOutPortName;
51 
52  std::string roiOutPortName;
53  std::string roiOutPortRightName;
54 
55  std::string cropOutPortName;
56  std::string optOutPortName;
57 
58  yarp::os::BufferedPort<yarp::os::Bottle> blobsOutPort;
59  yarp::os::BufferedPort<yarp::os::Bottle> blobsOutPortRight;
60  yarp::os::BufferedPort<yarp::os::Bottle> points3dOutPort;
61 
62  yarp::os::BufferedPort<yarp::os::Bottle> roiOutPort;
63  yarp::os::BufferedPort<yarp::os::Bottle> roiOutPortRight;
64 
65  yarp::os::BufferedPort< yarp::sig::ImageOf<yarp::sig::PixelBgr> > cropOutPort;
66  yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono> > optOutPort;
67 
68  yarp::os::RpcClient sfmRpcPort;
69 
70  std::vector<cv::Mat> imagesMatBuffer;
71 
72  dispBlobber *blobExtractor;
73 
74  int cropSize;
75 
76 public:
77 
78  DispBlobberPort( const std::string &moduleName, yarp::os::ResourceFinder &module );
79 
80  bool open();
81  void close();
82  void onRead( yarp::sig::ImageOf<yarp::sig::PixelBgr> &img );
83  void interrupt();
84 
85  bool setMargin(int mrg);
86  bool setThresh(int low);
87 
88  std::mutex mtx;
89 
90 };
91 
92 class DispBlobberModule : public yarp::os::RFModule
93 {
94 
95  std::string moduleName;
96 
97  std::string handlerPortName;
98  yarp::os::RpcServer handlerPort;
99 
100  DispBlobberPort *blobPort;
101  bool closing;
102 
103 public:
104 
105  bool configure(yarp::os::ResourceFinder &rf); // configure all the module parameters and return true if successful
106  bool interruptModule(); // interrupt, e.g., the ports
107  bool close(); // close and shut down the module
108 
109  double getPeriod();
110  bool updateModule();
111  bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply);
112 };
113 
114 #endif
115 //empty line to make gcc happy