1 /* 2 * Copyright (c) 2018 Arm Limited. 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to 8 * deal in the Software without restriction, including without limitation the 9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 10 * sell copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in all 14 * copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 #ifndef ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET 25 #define ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET 26 27 #include "tests/TypePrinter.h" 28 #include "tests/validation/Helpers.h" 29 #include "utils/TypePrinter.h" 30 31 namespace arm_compute 32 { 33 namespace test 34 { 35 namespace datasets 36 { 37 class OpticalFlowDataset 38 { 39 public: 40 using type = std::tuple<std::string, std::string, OpticalFlowParameters, size_t, size_t>; 41 42 struct iterator 43 { iteratoriterator44 iterator(std::vector<std::string>::const_iterator old_image_it, 45 std::vector<std::string>::const_iterator new_image_it, 46 std::vector<OpticalFlowParameters>::const_iterator params_it, 47 std::vector<size_t>::const_iterator num_levels_it, 48 std::vector<size_t>::const_iterator num_keypoints_it) 49 : _old_image_it{ std::move(old_image_it) }, 50 _new_image_it{ std::move(new_image_it) }, 51 _params_it{ std::move(params_it) }, 52 _num_levels_it{ std::move(num_levels_it) }, 53 _num_keypoints_it{ std::move(num_keypoints_it) } 54 { 55 } 56 descriptioniterator57 std::string description() const 58 { 59 std::stringstream description; 60 description << "NumLevels=" << *_num_levels_it << ":"; 61 description << "NumKeypoints=" << *_num_keypoints_it << ":"; 62 description << "Termination=" << _params_it->termination << ":"; 63 description << "Epsilon=" << _params_it->epsilon << ":"; 64 description << "NumIterations=" << _params_it->num_iterations << ":"; 65 description << "WindowDimension=" << _params_it->window_dimension << ":"; 66 description << "InitialEstimate=" << std::boolalpha << _params_it->use_initial_estimate; 67 68 return description.str(); 69 } 70 71 OpticalFlowDataset::type operator*() const 72 { 73 return std::make_tuple(*_old_image_it, *_new_image_it, *_params_it, *_num_levels_it, *_num_keypoints_it); 74 } 75 76 iterator &operator++() 77 { 78 ++_old_image_it; 79 ++_new_image_it; 80 ++_params_it; 81 ++_num_levels_it; 82 ++_num_keypoints_it; 83 84 return *this; 85 } 86 87 private: 88 std::vector<std::string>::const_iterator _old_image_it; 89 std::vector<std::string>::const_iterator _new_image_it; 90 std::vector<OpticalFlowParameters>::const_iterator _params_it; 91 std::vector<size_t>::const_iterator _num_levels_it; 92 std::vector<size_t>::const_iterator _num_keypoints_it; 93 }; 94 begin()95 iterator begin() const 96 { 97 return iterator(_old_image.begin(), 98 _new_image.begin(), 99 _params.begin(), 100 _num_levels.begin(), 101 _num_keypoints.begin()); 102 } 103 size()104 int size() const 105 { 106 return std::min(_old_image.size(), std::min(_new_image.size(), std::min(_params.size(), std::min(_num_levels.size(), _num_keypoints.size())))); 107 } 108 add_config(std::string old_image,std::string new_image,OpticalFlowParameters params,size_t num_levels,size_t num_keypoints)109 void add_config(std::string old_image, std::string new_image, OpticalFlowParameters params, size_t num_levels, size_t num_keypoints) 110 { 111 _old_image.emplace_back(std::move(old_image)); 112 _new_image.emplace_back(std::move(new_image)); 113 _params.emplace_back(params); 114 _num_levels.emplace_back(num_levels); 115 _num_keypoints.emplace_back(num_keypoints); 116 } 117 118 protected: 119 OpticalFlowDataset() = default; 120 OpticalFlowDataset(OpticalFlowDataset &&) = default; 121 122 private: 123 std::vector<std::string> _old_image{}; 124 std::vector<std::string> _new_image{}; 125 std::vector<OpticalFlowParameters> _params{}; 126 std::vector<size_t> _num_levels{}; 127 std::vector<size_t> _num_keypoints{}; 128 }; 129 130 // *INDENT-OFF* 131 // clang-format off 132 class SmallOpticalFlowDataset final : public OpticalFlowDataset 133 { 134 public: SmallOpticalFlowDataset()135 SmallOpticalFlowDataset() 136 { 137 // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints 138 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, true), 3, 1000); 139 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, true), 3, 1000); 140 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 1000); 141 } 142 }; 143 144 class LargeOpticalFlowDataset final : public OpticalFlowDataset 145 { 146 public: LargeOpticalFlowDataset()147 LargeOpticalFlowDataset() 148 { 149 // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints 150 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, true), 3, 10000); 151 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, true), 3, 10000); 152 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 10000); 153 154 // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints 155 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, false), 3, 10000); 156 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, false), 3, 10000); 157 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, false), 3, 10000); 158 } 159 }; 160 // clang-format on 161 // *INDENT-ON* 162 163 } // namespace datasets 164 } // namespace test 165 } // namespace arm_compute 166 #endif /* ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET */ 167