aboutsummaryrefslogtreecommitdiff
path: root/tests/datasets/OpticalFlowDataset.h
blob: 2ef75af7bb0bd0835fe24be20ef9b6d3fad98e1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * Copyright (c) 2018 Arm Limited.
 *
 * SPDX-License-Identifier: MIT
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#ifndef ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET
#define ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET

#include "tests/TypePrinter.h"
#include "tests/validation/Helpers.h"
#include "utils/TypePrinter.h"

namespace arm_compute
{
namespace test
{
namespace datasets
{
class OpticalFlowDataset
{
public:
    using type = std::tuple<std::string, std::string, OpticalFlowParameters, size_t, size_t>;

    struct iterator
    {
        iterator(std::vector<std::string>::const_iterator           old_image_it,
                 std::vector<std::string>::const_iterator           new_image_it,
                 std::vector<OpticalFlowParameters>::const_iterator params_it,
                 std::vector<size_t>::const_iterator                num_levels_it,
                 std::vector<size_t>::const_iterator                num_keypoints_it)
            : _old_image_it{ std::move(old_image_it) },
              _new_image_it{ std::move(new_image_it) },
              _params_it{ std::move(params_it) },
              _num_levels_it{ std::move(num_levels_it) },
              _num_keypoints_it{ std::move(num_keypoints_it) }
        {
        }

        std::string description() const
        {
            std::stringstream description;
            description << "NumLevels=" << *_num_levels_it << ":";
            description << "NumKeypoints=" << *_num_keypoints_it << ":";
            description << "Termination=" << _params_it->termination << ":";
            description << "Epsilon=" << _params_it->epsilon << ":";
            description << "NumIterations=" << _params_it->num_iterations << ":";
            description << "WindowDimension=" << _params_it->window_dimension << ":";
            description << "InitialEstimate=" << std::boolalpha << _params_it->use_initial_estimate;

            return description.str();
        }

        OpticalFlowDataset::type operator*() const
        {
            return std::make_tuple(*_old_image_it, *_new_image_it, *_params_it, *_num_levels_it, *_num_keypoints_it);
        }

        iterator &operator++()
        {
            ++_old_image_it;
            ++_new_image_it;
            ++_params_it;
            ++_num_levels_it;
            ++_num_keypoints_it;

            return *this;
        }

    private:
        std::vector<std::string>::const_iterator           _old_image_it;
        std::vector<std::string>::const_iterator           _new_image_it;
        std::vector<OpticalFlowParameters>::const_iterator _params_it;
        std::vector<size_t>::const_iterator                _num_levels_it;
        std::vector<size_t>::const_iterator                _num_keypoints_it;
    };

    iterator begin() const
    {
        return iterator(_old_image.begin(),
                        _new_image.begin(),
                        _params.begin(),
                        _num_levels.begin(),
                        _num_keypoints.begin());
    }

    int size() const
    {
        return std::min(_old_image.size(), std::min(_new_image.size(), std::min(_params.size(), std::min(_num_levels.size(), _num_keypoints.size()))));
    }

    void add_config(std::string old_image, std::string new_image, OpticalFlowParameters params, size_t num_levels, size_t num_keypoints)
    {
        _old_image.emplace_back(std::move(old_image));
        _new_image.emplace_back(std::move(new_image));
        _params.emplace_back(params);
        _num_levels.emplace_back(num_levels);
        _num_keypoints.emplace_back(num_keypoints);
    }

protected:
    OpticalFlowDataset()                      = default;
    OpticalFlowDataset(OpticalFlowDataset &&) = default;

private:
    std::vector<std::string>           _old_image{};
    std::vector<std::string>           _new_image{};
    std::vector<OpticalFlowParameters> _params{};
    std::vector<size_t>                _num_levels{};
    std::vector<size_t>                _num_keypoints{};
};

// *INDENT-OFF*
// clang-format off
class SmallOpticalFlowDataset final : public OpticalFlowDataset
{
public:
    SmallOpticalFlowDataset()
    {
        //         old_image              new_image              (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH,       0.01f, 3, 5, true), 3, 1000);
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON,    0.01f, 3, 5, true), 3, 1000);
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 1000);
    }
};

class LargeOpticalFlowDataset final : public OpticalFlowDataset
{
public:
    LargeOpticalFlowDataset()
    {
        //         old_image              new_image              (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH,       0.01f, 3, 5, true), 3, 10000);
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON,    0.01f, 3, 5, true), 3, 10000);
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, true), 3, 10000);

        //         old_image              new_image              (termination, epsilon, num_iterations, window_dimension, initial_estimate) levels keypoints
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_BOTH,       0.01f, 3, 5, false), 3, 10000);
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_EPSILON,    0.01f, 3, 5, false), 3, 10000);
        add_config("opticalflow_old.pgm", "opticalflow_new.pgm", OpticalFlowParameters(Termination::TERM_CRITERIA_ITERATIONS, 0.01f, 3, 5, false), 3, 10000);
    }
};
// clang-format on
// *INDENT-ON*

} // namespace datasets
} // namespace test
} // namespace arm_compute
#endif /* ARM_COMPUTE_TEST_OPTICAL_FLOW_DATASET */