| 152 | } |
| 153 | |
| 154 | void |
| 155 | trainTemplate (const PointCloudXYZRGBA::ConstPtr & input, const std::vector<bool> &foreground_mask, |
| 156 | pcl::LINEMOD & linemod) |
| 157 | { |
| 158 | pcl::ColorGradientModality<pcl::PointXYZRGBA> color_grad_mod; |
| 159 | color_grad_mod.setInputCloud (input); |
| 160 | color_grad_mod.processInputData (); |
| 161 | |
| 162 | pcl::SurfaceNormalModality<pcl::PointXYZRGBA> surface_norm_mod; |
| 163 | surface_norm_mod.setInputCloud (input); |
| 164 | surface_norm_mod.processInputData (); |
| 165 | |
| 166 | std::vector<pcl::QuantizableModality*> modalities (2); |
| 167 | modalities[0] = &color_grad_mod; |
| 168 | modalities[1] = &surface_norm_mod; |
| 169 | |
| 170 | std::size_t min_x (input->width), min_y (input->height), max_x (0), max_y (0); |
| 171 | pcl::MaskMap mask_map (input->width, input->height); |
| 172 | for (std::size_t j = 0; j < input->height; ++j) |
| 173 | { |
| 174 | for (std::size_t i = 0; i < input->width; ++i) |
| 175 | { |
| 176 | mask_map (i,j) = foreground_mask[j*input->width+i]; |
| 177 | if (foreground_mask[j*input->width+i]) |
| 178 | { |
| 179 | min_x = std::min (min_x, i); |
| 180 | max_x = std::max (max_x, i); |
| 181 | min_y = std::min (min_y, j); |
| 182 | max_y = std::max (max_y, j); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | std::vector<pcl::MaskMap*> masks (2); |
| 188 | masks[0] = &mask_map; |
| 189 | masks[1] = &mask_map; |
| 190 | |
| 191 | pcl::RegionXY region; |
| 192 | region.x = static_cast<int> (min_x); |
| 193 | region.y = static_cast<int> (min_y); |
| 194 | region.width = static_cast<int> (max_x - min_x + 1); |
| 195 | region.height = static_cast<int> (max_y - min_y + 1); |
| 196 | |
| 197 | printf ("%d %d %d %d\n", region.x, region.y, region.width, region.height); |
| 198 | |
| 199 | linemod.createAndAddTemplate (modalities, masks, region); |
| 200 | } |
| 201 | |
| 202 | void |
| 203 | compute (const PointCloudXYZRGBA::ConstPtr & input, float min_depth, float max_depth, float max_height, |
no test coverage detected