| 236 | |
| 237 | template <typename image_type, typename feature_type> |
| 238 | void extract_feature_pixel_values ( |
| 239 | const image_type& img_, |
| 240 | const rectangle& rect, |
| 241 | const matrix<float,0,1>& current_shape, |
| 242 | const matrix<float,0,1>& reference_shape, |
| 243 | const std::vector<unsigned long>& reference_pixel_anchor_idx, |
| 244 | const std::vector<dlib::vector<float,2> >& reference_pixel_deltas, |
| 245 | std::vector<feature_type>& feature_pixel_values |
| 246 | ) |
| 247 | /*! |
| 248 | requires |
| 249 | - image_type == an image object that implements the interface defined in |
| 250 | dlib/image_processing/generic_image.h |
| 251 | - reference_pixel_anchor_idx.size() == reference_pixel_deltas.size() |
| 252 | - current_shape.size() == reference_shape.size() |
| 253 | - reference_shape.size()%2 == 0 |
| 254 | - max(mat(reference_pixel_anchor_idx)) < reference_shape.size()/2 |
| 255 | ensures |
| 256 | - #feature_pixel_values.size() == reference_pixel_deltas.size() |
| 257 | - for all valid i: |
| 258 | - #feature_pixel_values[i] == the value of the pixel in img_ that |
| 259 | corresponds to the pixel identified by reference_pixel_anchor_idx[i] |
| 260 | and reference_pixel_deltas[i] when the pixel is located relative to |
| 261 | current_shape rather than reference_shape. |
| 262 | !*/ |
| 263 | { |
| 264 | const matrix<float,2,2> tform = matrix_cast<float>(find_tform_between_shapes(reference_shape, current_shape).get_m()); |
| 265 | const point_transform_affine tform_to_img = unnormalizing_tform(rect); |
| 266 | |
| 267 | const rectangle area = get_rect(img_); |
| 268 | |
| 269 | const_image_view<image_type> img(img_); |
| 270 | feature_pixel_values.resize(reference_pixel_deltas.size()); |
| 271 | for (unsigned long i = 0; i < feature_pixel_values.size(); ++i) |
| 272 | { |
| 273 | // Compute the point in the current shape corresponding to the i-th pixel and |
| 274 | // then map it from the normalized shape space into pixel space. |
| 275 | point p = tform_to_img(tform*reference_pixel_deltas[i] + location(current_shape, reference_pixel_anchor_idx[i])); |
| 276 | if (area.contains(p)) |
| 277 | feature_pixel_values[i] = get_pixel_intensity(img[p.y()][p.x()]); |
| 278 | else |
| 279 | feature_pixel_values[i] = 0; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | } // end namespace impl |
| 284 |
no test coverage detected