| 104 | } |
| 105 | |
| 106 | void |
| 107 | compute (const PointCloudXYZRGBA::ConstPtr & input, const char * templates_filename) |
| 108 | { |
| 109 | pcl::LINEMOD linemod; |
| 110 | |
| 111 | // Load the templates from disk |
| 112 | linemod.loadTemplates (templates_filename); |
| 113 | |
| 114 | // Match the templates to the provided image |
| 115 | std::vector<pcl::LINEMODDetection> detections = matchTemplates (input, linemod); |
| 116 | |
| 117 | // Output the position and score of the best match for each template |
| 118 | for (std::size_t i = 0; i < detections.size (); ++i) |
| 119 | { |
| 120 | const LINEMODDetection & d = detections[i]; |
| 121 | printf ("%lu: %d %d %d %f\n", i, d.x, d.y, d.template_id, d.score); |
| 122 | } |
| 123 | |
| 124 | /*// Visualization code for testing purposes (requires libpng++) |
| 125 | int i = 0; |
| 126 | png::image<png::rgb_pixel> image (640, 480); |
| 127 | for (std::size_t y = 0; y < image.get_height (); ++y) |
| 128 | { |
| 129 | for (std::size_t x = 0; x < image.get_width (); ++x) |
| 130 | { |
| 131 | const pcl::PointXYZRGBA & p = (*input)[i++]; |
| 132 | image[y][x] = png::rgb_pixel(p.r, p.g, p.b); |
| 133 | } |
| 134 | } |
| 135 | // Draw a green box around the object |
| 136 | for (std::size_t i = 0; i < detections.size (); ++i) |
| 137 | { |
| 138 | const LINEMODDetection & d = detections[i]; |
| 139 | if (d.score < 0.6) |
| 140 | continue; |
| 141 | |
| 142 | const pcl::SparseQuantizedMultiModTemplate & tmplt = linemod.getTemplate (d.template_id); |
| 143 | int w = tmplt.region.width; |
| 144 | int h = tmplt.region.height; |
| 145 | for (int x = d.x; x < d.x+w; ++x) |
| 146 | { |
| 147 | image[d.y][x] = png::rgb_pixel(0, 255, 0); |
| 148 | image[d.y+h-1][x] = png::rgb_pixel(0, 255, 0); |
| 149 | } |
| 150 | for (int y = d.y; y < d.y+h; ++y) |
| 151 | { |
| 152 | image[y][d.x] = png::rgb_pixel(0, 255, 0); |
| 153 | image[y][d.x+w-1] = png::rgb_pixel(0, 255, 0); |
| 154 | } |
| 155 | } |
| 156 | image.write("output.png"); |
| 157 | */ |
| 158 | } |
| 159 | |
| 160 | /* ---[ */ |
| 161 | int |
no test coverage detected