23 #ifndef _ARMARX_COMPONENT_ROBDEKON_DenseCRFSegmentationProcessor_H
24 #define _ARMARX_COMPONENT_ROBDEKON_DenseCRFSegmentationProcessor_H
32 #include <ArmarXCore/interface/observers/ObserverInterface.h>
33 #include <RobotAPI/interface/visualization/DebugDrawerInterface.h>
37 #include <ArmarXGui/interface/RemoteGuiInterface.h>
42 #include <VisionX/interface/components/DenseCRFSegmentationProcessorInterface.h>
49 #include <pcl/point_types.h>
51 #include <boost/graph/filtered_graph.hpp>
58 (
int, num_classes, AX_DESCRIPTION(
"Number of maximal object classes in an image"),
59 AX_DEFAULT(20), AX_MIN(1), AX_MAX(255), AX_NO_REMOTE_GUI()),
60 (
float, ground_truth_prob, AX_DESCRIPTION(
61 "Number of maximal object classes in an image"), AX_DEFAULT(
62 0.5), AX_MIN(0), AX_MAX(1), AX_DECIMALS(2), AX_STEPS(100)),
63 (
bool, use_vertex_only_graph, AX_DESCRIPTION(
64 "If true, the graph is not computed via a voxel grid and"
65 " therefore has no edges between the vertices. This also means the"
66 " curvature is not signed in this case."), AX_DEFAULT(
false)),
67 (
bool, use_approximate_voxels, AX_DESCRIPTION(
68 "If true & UseVertexOnlyGraph is true, the downsampling"
69 " uses the ApproximateVoxelGrid for downsampling instead of the normal"
70 "VoxelGrid"), AX_DEFAULT(
false)),
71 (
float, voxel_resolution, AX_DESCRIPTION(
72 "Resolution of the Voxels used as Vertices of the Graph"), AX_DEFAULT(
73 0.05), AX_MIN(0.01), AX_MAX(.02), AX_DECIMALS(3), AX_STEPS(100)),
74 (
int, map_iterations, AX_DESCRIPTION(
75 "Number of iterations used for the map"), AX_DEFAULT(
76 5), AX_MIN(1), AX_MAX(100))
80 (
bool, provide_graph_pclouds, AX_DESCRIPTION(
81 "If true a segmentation for each timestep"
82 "is provided as result cloud"), AX_DEFAULT(
false),
84 (
bool, provide_confidence_pclouds, AX_DESCRIPTION(
85 "If true a confidence for each timestep"
86 "is provided as result cloud"), AX_DEFAULT(
false),
88 (
bool, colorize_confidence_pclouds, AX_DESCRIPTION(
89 "If true the confidence pclouds are colorized"), AX_DEFAULT(
false),
94 AX_DESCRIPTION(
"If true xyz values are used for edge computation"),
96 (
float, xyz_influence,
97 AX_DESCRIPTION(
"Weight for the influence of position in the edge computation"),
98 AX_DEFAULT(0), AX_MIN(-2), AX_MAX(2), AX_DECIMALS(1), AX_STEPS(100)),
100 AX_DESCRIPTION(
"If true normal values are used for edge computation"),
102 (
float, normals_influence,
103 AX_DESCRIPTION(
"Weight for the influence of normals in the edge computation"),
104 AX_DEFAULT(0), AX_MIN(-2), AX_MAX(2), AX_DECIMALS(1), AX_STEPS(100)),
106 AX_DESCRIPTION(
"If true RGB values are used for edge computation"),
108 (
float, rgb_influence,
109 AX_DESCRIPTION(
"Weight for the influence of color in the edge computation"),
110 AX_DEFAULT(0), AX_MIN(-2), AX_MAX(2), AX_DECIMALS(1), AX_STEPS(100)),
111 (
bool, use_curvature,
112 AX_DESCRIPTION(
"If true curvature values are used for edge computation"),
114 (
float, curvature_influence,
115 AX_DESCRIPTION(
"Weight for the influence of curvature in the edge computation"),
116 AX_DEFAULT(0), AX_MIN(-2), AX_MAX(2), AX_DECIMALS(1), AX_STEPS(100)),
118 AX_DESCRIPTION(
"If true time values are used for edge computation"),
120 (
float, time_influence,
121 AX_DESCRIPTION(
"Weight for the influence of time in the edge computation"),
122 AX_DEFAULT(0), AX_MIN(-2), AX_MAX(2), AX_DECIMALS(1), AX_STEPS(100)),
124 AX_DESCRIPTION(
"If true the influence values are combined before they are given to DenseCRF"),
126 (
float, potts_compatibilty,
127 AX_DESCRIPTION(
"Weight factor for the Potts Compatibility"),
128 AX_DEFAULT(10), AX_MIN(0.5), AX_MAX(50), AX_DECIMALS(1), AX_STEPS(200))
132 (armarx::densecrf::config::general, general),
133 (armarx::densecrf::config::output, out),
134 (armarx::densecrf::config::edge_comp, edge)
176 return "DenseCRFSegmentationProcessor";
181 void setEdgeWeights(
float xyz,
float rgb,
float normals,
float curvature,
float time,
const Ice::Current& current)
override;
216 template <
typename TimestampMap>
217 struct vertex_timestamp_unequal_filter
219 vertex_timestamp_unequal_filter() =
default;
221 vertex_timestamp_unequal_filter(
TimestampMap tsm,
double ts) : m_tsm(tsm), m_ts(ts)
225 template <
typename Vertex>
226 bool operator()(
const Vertex&
v)
const
229 double current_ts = get(m_tsm,
v);
230 return abs(m_ts - current_ts) > 0.00001;
237 template <
typename TimestampMap>
238 struct vertex_timestamp_equal_filter
240 vertex_timestamp_equal_filter() =
default;
242 vertex_timestamp_equal_filter(
TimestampMap tsm,
double ts) : m_tsm(tsm), m_ts(ts)
246 template <
typename Vertex>
247 bool operator()(
const Vertex&
v)
const
250 double current_ts = get(m_tsm,
v);
251 return abs(m_ts - current_ts) < 0.00001;
259 double initial_time_;
263 std::deque<Graph> graph_queue_;
264 std::deque<double> timestamp_queue_;
266 void computeGraphUsingVoxelGrid(
const PointCloudT::Ptr inputCloudPtr);
268 void computeVertexOnlyGraph(pcl::PointCloud<PointT>::Ptr input_cloud_ptr);
270 void generateRandomClassLabels();
272 void relabelPointCloud(pcl::PointCloud<PointT>::Ptr input_cloud_ptr);
278 void updatePersistentGraph();
280 void addGraphToPersistentGraph(
Graph& graph);
282 void addCurrentGraphToPersistentGraph();
284 void removeGraphFromPersistentGraph(
Graph& graph);
286 void removeCurrentGraphFromPersistentGraph();
288 void removeTimestampFromPersistentGraph(
double ts);
298 template <
typename FilterT>
302 typedef boost::filtered_graph<GraphWithTimestamp, boost::keep_all, FilterT> FilteredGraph;
303 typedef typename boost::graph_traits<FilteredGraph>::vertex_iterator FilteredVertexIterator;
304 FilteredGraph filtered_graph = boost::make_filtered_graph(*persistent_graph_ptr_, boost::keep_all(),
306 FilteredVertexIterator vi, v_end;
311 int num_vertices = 0;
312 for (boost::tie(vi, v_end) = boost::vertices(filtered_graph); vi != v_end; ++vi)
315 VertexWTsId new_vertex = boost::add_vertex(temp_graph);
316 boost::put(temp_tsm, new_vertex, get(tsm, *vi));
317 boost::put(temp_cm, new_vertex, get(cm, *vi));
318 PointWithNormalT point = filtered_graph.m_g.m_graph.m_point_cloud->points[*vi];
319 temp_graph[new_vertex] = point;
326 pcl::PointCloud<pcl::PointXYZL>::ConstPtr selectRandomSeeds();
328 Eigen::MatrixXf computeRandomUnaryEnergy(
int num_points);
330 void provideAllGraphs();
331 void provideAllConfidences();
333 WriteBufferedTripleBuffer<armarx::densecrf::config::data> config_;
334 std::mutex write_mutex_;