vision
Loading...
Searching...
No Matches
SegmentorThread.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __SEGMENTOR_THREAD_HPP__
4#define __SEGMENTOR_THREAD_HPP__
5
6#include <yarp/os/RFModule.h>
7#include <yarp/os/Network.h>
8#include <yarp/os/Port.h>
9#include <yarp/os/BufferedPort.h>
10#include <yarp/os/PeriodicThread.h>
11#include <yarp/os/Property.h>
12
13#include <yarp/dev/all.h>
14#include <yarp/dev/IRGBDSensor.h>
15
16#include <yarp/sig/all.h>
17
18#define DEFAULT_ALGORITHM "blueMinusRed"
19#define DEFAULT_LOCATE "centroid"
20#define DEFAULT_MAX_NUM_BLOBS 2
21#define DEFAULT_MORPH_CLOSING 2
22#define DEFAULT_MORPH_OPENING 0
23#define DEFAULT_OUT_FEATURES "mmX mmY mmZ" // it's a bottle!!
24#define DEFAULT_OUT_FEATURES_FORMAT 0 // 0=bottled,1=minimal
25#define DEFAULT_OUT_IMAGE 1
26#define DEFAULT_RATE_MS 20
27#define DEFAULT_SEE_BOUNDING 3
28#define DEFAULT_THRESHOLD 55
29
30//VoxelOccupancy Constants
31#define DEFAULT_SEARCH_AREA_DILATATION 10
32#define DEFAULT_DEPTH_LOW_THRESHOLD 0.730 //m; TV Dimensions
33#define DEFAULT_DEPTH_HIGH_THRESHOLD 1.25 //m; TV Dimensions
34#define DEFAULT_OCCUPANCY_THRESHOLD 100
35#define DEFAULT_VOXEL_RESOLUTION 4 //this is the number of voxel per row.
36#define DEFAULT_UTILITY_DEPTH_LOW_THRESHOLD 1.350 //m;
37#define DEFAULT_UTILITY_DEPTH_HIGH_THRESHOLD 1.450 //mm;
38#define DEFAULT_NUMBER_UTILITY_VOXELS 4
39// W and H threshold are as a function of the total value.
40#define DEFAULT_LOW_W_THRESHOLD 0.17
41#define DEFAULT_HIGH_W_THRESHOLD 0.87
42#define DEFAULT_LOW_H_THRESHOLD 0.45
43#define DEFAULT_HIGH_H_THRESHOLD 0.52
44
45namespace roboticslab
46{
47
53class DataProcessor : public yarp::os::PortReader
54{
55 virtual bool read(yarp::os::ConnectionReader& connection)
56 {
57 yarp::os::Bottle b;
58 b.read(connection);
59 // process data in b
60 printf("Got %s\n", b.toString().c_str());
61
62 if (waitForFirst)
63 {
64 xKeep = b.get(0).asInt32();
65 yKeep = b.get(1).asInt32();
66 waitForFirst = false;
67 }
68 else
69 {
70 if (b.get(0).asInt32() < xKeep || b.get(1).asInt32() < yKeep)
71 {
72 x = 0;
73 y = 0;
74 w = 0;
75 h = 0;
76 }
77 else
78 {
79 x = xKeep;
80 y = yKeep;
81 w = b.get(0).asInt32() - x;
82 h = b.get(1).asInt32() - y;
83 }
84
85 waitForFirst = true;
86 }
87
88 return true;
89 }
90
91public:
92 void reset()
93 {
94 waitForFirst = true;
95 x = y = w = h = 0;
96 xKeep = yKeep = 0;
97 }
98
99 int xKeep, yKeep;
100 int x, y, w, h;
101 bool waitForFirst;
102};
103
109class SegmentorThread : public yarp::os::PeriodicThread {
110private:
111 yarp::dev::IRGBDSensor *iRGBDSensor;
112 yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono16> > *pOutImg; // for testing
113 yarp::os::Port *pOutPort;
114 //
115 std::string algorithm;
116 std::string locate;
117 int maxNumBlobs;
118 double morphClosing;
119 double morphOpening;
120 int outFeaturesFormat;
121 int outImage;
122 int seeBounding;
123 int threshold;
124 //
125 double fx_d,fy_d,cx_d,cy_d,fx_rgb,fy_rgb,cx_rgb,cy_rgb;
126 //
127 yarp::os::Bottle outFeatures;
128 //
129 int cropSelector;
130 yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> >* outCropSelectorImg;
131 yarp::os::Port* inCropSelectorPort;
132 DataProcessor processor;
133
134 //VoxelOccupancy specific variables
135 int searchAreaDilatation;
136 float depthLowThreshold;
137 float depthHighThreshold;
138 int occupancyThreshold;
139 int voxelResolution;
140 float utilityDepthLowThreshold;
141 float utilityDepthHighThreshold;
142 int numberUtilityVoxels;
143 float lowWThreshold;
144 float highWThreshold;
145 float lowHThreshold;
146 float highHThreshold;
147public:
148 SegmentorThread() : PeriodicThread(DEFAULT_RATE_MS * 0.001) {}
149
150 void setIRGBDSensor(yarp::dev::IRGBDSensor * _iRGBDSensor);
151 void setOutImg(yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelMono16> > * _pOutImg);
152 void setOutPort(yarp::os::Port *_pOutPort);
153 void init(yarp::os::ResourceFinder &rf);
154 void run(); // The periodical function
155
156 void setCropSelector(int cropSelector) { this->cropSelector = cropSelector; }
157 void setOutCropSelectorImg(yarp::os::BufferedPort<yarp::sig::ImageOf<yarp::sig::PixelRgb> >* outCropSelectorImg) { this->outCropSelectorImg = outCropSelectorImg; }
158 void setInCropSelectorPort(yarp::os::Port* inCropSelectorPort) { this->inCropSelectorPort = inCropSelectorPort; }
159
160};
161
162} // namespace roboticslab
163
164#endif // __SEGMENTOR_THREAD_HPP__
165
Implements voxelOccupancyDetection callback on Bottle.
Definition SegmentorThread.hpp:54
Implements voxelOccupancyDetection PeriodicThread.
Definition SegmentorThread.hpp:109
The main, catch-all namespace for Robotics Lab UC3M.
Definition groups.dox:5