12 #include <ros/console.h>
43 DepthRenderer(cv::Mat& z_buffer_)
44 :
geo::RenderResult(z_buffer_.cols, z_buffer_.rows), z_buffer(z_buffer_)
50 float& old_depth = z_buffer.at<
float>(y, x);
51 if (old_depth == 0 || depth < old_depth)
65 const geo::Pose3D& sensor_pose,
double background_padding)
72 DepthRenderer res(depth_model);
76 if (!e->visual() || !e->has_pose())
80 opt.
setMesh(e->visual()->getMesh(), sensor_pose.
inverse() * e->pose());
88 for(
unsigned int i = 0; i < size; ++i)
91 float dm = depth_model.at<
float>(i);
92 if (dm > 0 && ds > 0 && ds > dm - background_padding)
106 min_buffer = cv::Mat(height, width, CV_32FC1, 0.0);
107 max_buffer = cv::Mat(height, width, CV_32FC1, 0.0);
121 if (d_min == 0 || depth < d_min)
135 const geo::Pose3D& shape_pose, cv::Mat& filtered_depth_image)
const
151 cam_model.
render(opt, res);
164 if (d_min > 0 && d_max > 0 && d >= d_min && d <= d_max)
165 filtered_depth_image.at<
float>(i) = d;
182 ROS_DEBUG(
"Cluster with depth image of size %i, %i", width, height);
184 cv::Mat visited(height, width, CV_8UC1, cv::Scalar(0));
187 for(
int x = 0; x < width; ++x)
189 visited.at<
unsigned char>(0, x) = 1;
190 visited.at<
unsigned char>(1, x) = 1;
191 visited.at<
unsigned char>(height - 1, x) = 1;
192 visited.at<
unsigned char>(height - 2, x) = 1;
195 for(
int y = 0; y < height; ++y)
197 visited.at<
unsigned char>(y, 0) = 1;
198 visited.at<
unsigned char>(y, 1) = 1;
199 visited.at<
unsigned char>(y, width - 1) = 1;
200 visited.at<
unsigned char>(y, width - 2) = 1;
203 int dirs[] = { -1, 1, -width, width,
204 -2, 2, -width * 2, width * 2};
206 ROS_DEBUG(
"Creating clusters");
207 unsigned int size = width * height;
208 for(
unsigned int i_pixel = 0; i_pixel < size; ++i_pixel)
212 if (d == 0 || d != d)
220 visited.at<
unsigned char>(i_pixel) = 1;
227 unsigned int p1 = Q.front();
233 cluster.pixel_indices.push_back(p1);
236 for(
int dir = 0; dir < 8; ++dir)
238 unsigned int p2 = p1 + dirs[dir];
247 if (visited.at<
unsigned char>(p2) == 0 && std::abs<float>(p2_d - p1_d) < 0.05)
250 visited.at<
unsigned char>(p2) = 1;
259 if (
cluster.pixel_indices.size() < 100)
270 ROS_DEBUG(
"Computing min and max of cluster");
272 for(
unsigned int j = 0; j <
cluster.points.size(); ++j)
281 z_min = std::min<float>(z_min, p_map.
z);
282 z_max = std::max<float>(z_max, p_map.
z);
286 cluster.chull.complete =
false;