|
1 | 1 | #ifndef CAFFE_DATA_TRANSFORMER_HPP
|
2 | 2 | #define CAFFE_DATA_TRANSFORMER_HPP
|
3 | 3 |
|
| 4 | +#ifdef USE_OPENCV |
| 5 | + |
| 6 | +#include <opencv2/core/core.hpp> |
| 7 | + |
| 8 | +#endif // USE_OPENCV |
| 9 | + |
4 | 10 | #include <string>
|
5 | 11 | #include <vector>
|
6 | 12 |
|
@@ -49,6 +55,46 @@ class DataTransformer {
|
49 | 55 | void CopyPtrEntry(shared_ptr<Datum> datum, Dtype* transformed_ptr, size_t& out_sizeof_element,
|
50 | 56 | bool output_labels, Dtype* label);
|
51 | 57 |
|
| 58 | +#ifdef USE_OPENCV |
| 59 | + /** |
| 60 | + * @brief Whether there are any "variable_sized" transformations defined |
| 61 | + * in the data layer's transform_param block. |
| 62 | + */ |
| 63 | + bool var_sized_transforms_enabled() const; |
| 64 | + |
| 65 | + /** |
| 66 | + * @brief Calculate the final shape from applying the "variable_sized" |
| 67 | + * transformations defined in the data layer's transform_param block |
| 68 | + * on the provided image, without actually performing any transformations. |
| 69 | + * |
| 70 | + * @param orig_shape |
| 71 | + * The shape of the data to be transformed. |
| 72 | + */ |
| 73 | + vector<int> var_sized_transforms_shape(const vector<int>& orig_shape) const; |
| 74 | + |
| 75 | + /** |
| 76 | + * @brief Applies "variable_sized" transformations defined in the data layer's |
| 77 | + * transform_param block to the data. |
| 78 | + * |
| 79 | + * @param old_datum |
| 80 | + * The source Datum containing data of arbitrary shape. |
| 81 | + * @param new_datum |
| 82 | + * The destination Datum that will store transformed data of a fixed |
| 83 | + * shape. Suitable for other transformations. |
| 84 | + */ |
| 85 | + shared_ptr<Datum> VariableSizedTransforms(shared_ptr<Datum> old_datum); |
| 86 | + |
| 87 | + bool var_sized_image_random_resize_enabled() const; |
| 88 | + vector<int> var_sized_image_random_resize_shape(const vector<int>& prev_shape) const; |
| 89 | + cv::Mat& var_sized_image_random_resize(cv::Mat& img); |
| 90 | + bool var_sized_image_random_crop_enabled() const; |
| 91 | + vector<int> var_sized_image_random_crop_shape(const vector<int>& prev_shape) const; |
| 92 | + cv::Mat& var_sized_image_random_crop(const cv::Mat& img); |
| 93 | + bool var_sized_image_center_crop_enabled() const; |
| 94 | + vector<int> var_sized_image_center_crop_shape(const vector<int>& prev_shape) const; |
| 95 | + cv::Mat& var_sized_image_center_crop(const cv::Mat& img); |
| 96 | +#endif |
| 97 | + |
52 | 98 | /**
|
53 | 99 | * @brief Applies the transformation defined in the data layer's
|
54 | 100 | * transform_param block to the data.
|
@@ -137,6 +183,20 @@ class DataTransformer {
|
137 | 183 | const std::array<unsigned int, 3>& rand);
|
138 | 184 | #endif // USE_OPENCV
|
139 | 185 |
|
| 186 | + vector<int> InferDatumShape(const Datum& datum); |
| 187 | +#ifdef USE_OPENCV |
| 188 | + vector<int> InferCVMatShape(const cv::Mat& img); |
| 189 | +#endif // USE_OPENCV |
| 190 | + |
| 191 | + /** |
| 192 | + * @brief Infers the shape of transformed_blob will have when |
| 193 | + * the transformation is applied to the data. |
| 194 | + * |
| 195 | + * @param bottom_shape |
| 196 | + * The shape of the data to be transformed. |
| 197 | + */ |
| 198 | + vector<int> InferBlobShape(const vector<int>& bottom_shape, bool use_gpu = false); |
| 199 | + |
140 | 200 | /**
|
141 | 201 | * @brief Infers the shape of transformed_blob will have when
|
142 | 202 | * the transformation is applied to the data.
|
@@ -180,6 +240,12 @@ class DataTransformer {
|
180 | 240 | #ifndef CPU_ONLY
|
181 | 241 | GPUMemory::Workspace mean_values_gpu_;
|
182 | 242 | #endif
|
| 243 | +#ifdef USE_OPENCV |
| 244 | + cv::Mat varsz_orig_img_; |
| 245 | + cv::Mat varsz_rand_resize_img_; |
| 246 | + cv::Mat varsz_rand_crop_img_; |
| 247 | + cv::Mat varsz_center_crop_img_; |
| 248 | +#endif |
183 | 249 | };
|
184 | 250 |
|
185 | 251 | } // namespace caffe
|
|
0 commit comments