blob: 9e247206f828784ec4f0d25c06854d5ca3880f97 [file] [log] [blame]
John Richardson8de92612018-02-22 14:09:31 +00001/*
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/validation/Helpers.h"
28#include "utils/TypePrinter.h"
29
30namespace arm_compute
31{
32namespace test
33{
34namespace datasets
35{
36class OpticalFlowDataset
37{
38public:
39 using type = std::tuple<std::string, std::string, OpticalFlowParameters, size_t, size_t>;
40
41 struct iterator
42 {
43 iterator(std::vector<std::string>::const_iterator old_image_it,
44 std::vector<std::string>::const_iterator new_image_it,
45 std::vector<OpticalFlowParameters>::const_iterator params_it,
46 std::vector<size_t>::const_iterator num_levels_it,
47 std::vector<size_t>::const_iterator num_keypoints_it)
48 : _old_image_it{ std::move(old_image_it) },
49 _new_image_it{ std::move(new_image_it) },
50 _params_it{ std::move(params_it) },
51 _num_levels_it{ std::move(num_levels_it) },
52 _num_keypoints_it{ std::move(num_keypoints_it) }
53 {
54 }
55
56 std::string description() const
57 {
58 std::stringstream description;
59 description << "NumLevels=" << *_num_levels_it << ":";
60 description << "NumKeypoints=" << *_num_keypoints_it << ":";
61 description << "Termination=" << _params_it->termination << ":";
62 description << "Epsilon=" << _params_it->epsilon << ":";
63 description << "NumIterations=" << _params_it->num_iterations << ":";
64 description << "WindowDimension=" << _params_it->window_dimension << ":";
65 description << "InitialEstimate=" << std::boolalpha << _params_it->use_initial_estimate;
66
67 return description.str();
68 }
69
70 OpticalFlowDataset::type operator*() const
71 {
72 return std::make_tuple(*_old_image_it, *_new_image_it, *_params_it, *_num_levels_it, *_num_keypoints_it);
73 }
74
75 iterator &operator++()
76 {
77 ++_old_image_it;
78 ++_new_image_it;
79 ++_params_it;
80 ++_num_levels_it;
81 ++_num_keypoints_it;
82
83 return *this;
84 }
85
86 private:
87 std::vector<std::string>::const_iterator _old_image_it;
88 std::vector<std::string>::const_iterator _new_image_it;
89 std::vector<OpticalFlowParameters>::const_iterator _params_it;
90 std::vector<size_t>::const_iterator _num_levels_it;
91 std::vector<size_t>::const_iterator _num_keypoints_it;
92 };
93
94 iterator begin() const
95 {
96 return iterator(_old_image.begin(),
97 _new_image.begin(),
98 _params.begin(),
99 _num_levels.begin(),
100 _num_keypoints.begin());
101 }
102
103 int size() const
104 {
105 return std::min(_old_image.size(), std::min(_new_image.size(), std::min(_params.size(), std::min(_num_levels.size(), _num_keypoints.size()))));
106 }
107
108 void add_config(std::string old_image, std::string new_image, OpticalFlowParameters params, size_t num_levels, size_t num_keypoints)
109 {
110 _old_image.emplace_back(std::move(old_image));
111 _new_image.emplace_back(std::move(new_image));
112 _params.emplace_back(params);
113 _num_levels.emplace_back(num_levels);
114 _num_keypoints.emplace_back(num_keypoints);
115 }
116
117protected:
118 OpticalFlowDataset() = default;
119 OpticalFlowDataset(OpticalFlowDataset &&) = default;
120
121private:
122 std::vector<std::string> _old_image{};
123 std::vector<std::string> _new_image{};
124 std::vector<OpticalFlowParameters> _params{};
125 std::vector<size_t> _num_levels{};
126 std::vector<size_t> _num_keypoints{};
127};
128
129// *INDENT-OFF*
130// clang-format off
131class SmallOpticalFlowDataset final : public OpticalFlowDataset
132{
133public:
134 SmallOpticalFlowDataset()
135 {
136 // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints
137 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, true), 3, 1000);
138 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, true), 3, 1000);
139 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 1000);
140 }
141};
142
143class LargeOpticalFlowDataset final : public OpticalFlowDataset
144{
145public:
146 LargeOpticalFlowDataset()
147 {
148 // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints
149 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, true), 3, 10000);
150 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, true), 3, 10000);
151 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 10000);
152
153 // old_image new_image (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints
154 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH, 0.01f, 3, 5, false), 3, 10000);
155 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON, 0.01f, 3, 5, false), 3, 10000);
156 add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, false), 3, 10000);
157 }
158};
159// clang-format on
160// *INDENT-ON*
161
162} // namespace datasets
163} // namespace test
164} // namespace arm_compute
165#endif /* ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET */