| 170 | |
| 171 | template <typename T> |
| 172 | SimpleTensor<float> crop_and_resize(const SimpleTensor<T> &src, |
| 173 | const SimpleTensor<float> &boxes, |
| 174 | SimpleTensor<int32_t> box_ind, |
| 175 | Coordinates2D crop_size, |
| 176 | InterpolationPolicy method, |
| 177 | float extrapolation_value) |
| 178 | { |
| 179 | ARM_COMPUTE_ERROR_ON(src.shape().num_dimensions() > 4); |
| 180 | ARM_COMPUTE_ERROR_ON(src.data_layout() != DataLayout::NHWC); |
| 181 | |
| 182 | const TensorShape out_shape(src.shape()[0], crop_size.x, crop_size.y, boxes.shape()[1]); |
| 183 | SimpleTensor<float> out{out_shape, DataType::F32, 1, QuantizationInfo(), DataLayout::NHWC}; |
| 184 | |
| 185 | const TensorShape scaled_image_shape(src.shape()[0], crop_size.x, crop_size.y); |
| 186 | |
| 187 | for (uint32_t i = 0; i < boxes.shape()[1]; ++i) |
| 188 | { |
| 189 | Coordinates start = Coordinates( |
| 190 | std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(1, i)))) * (src.shape()[1] - 1) + 0.5f), |
| 191 | std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(0, i)))) * (src.shape()[2] - 1) + 0.5f)); |
| 192 | Coordinates end = Coordinates( |
| 193 | std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(3, i)))) * (src.shape()[1] - 1) + 0.5f), |
| 194 | std::floor((*reinterpret_cast<const float *>(boxes(Coordinates(2, i)))) * (src.shape()[2] - 1) + 0.5f)); |
| 195 | SimpleTensor<float> cropped = crop_image(src, start, end, box_ind[i], extrapolation_value); |
| 196 | SimpleTensor<float> scaled = scale_image(cropped, scaled_image_shape, method, extrapolation_value); |
| 197 | std::copy_n(reinterpret_cast<float *>(scaled.data()), scaled.num_elements(), |
| 198 | reinterpret_cast<float *>(out(Coordinates(0, 0, 0, i)))); |
| 199 | } |
| 200 | return out; |
| 201 | } |
| 202 | |
| 203 | template SimpleTensor<float> crop_and_resize(const SimpleTensor<float> &src, |
| 204 | const SimpleTensor<float> &boxes, |
no test coverage detected