blob: 0b827f74b5f46aebe2f418e950bba08356228527 [file] [log] [blame]
Abe Mbise25a340f2017-12-19 13:00:58 +00001/*
2 * Copyright (c) 2017-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_FAST_CORNERS_FIXTURE
25#define ARM_COMPUTE_TEST_FAST_CORNERS_FIXTURE
26
27#include "arm_compute/core/TensorShape.h"
28#include "arm_compute/core/Types.h"
29#include "tests/AssetsLibrary.h"
30#include "tests/Globals.h"
31#include "tests/IAccessor.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Fixture.h"
34#include "tests/validation/reference/FastCorners.h"
35
36#include <random>
37
38namespace arm_compute
39{
40class CLFastCorners;
41class NEFastCorners;
42
43namespace test
44{
45namespace validation
46{
47template <typename TensorType, typename AccessorType, typename ArrayType, typename FunctionType, typename T>
48class FastCornersValidationFixture : public framework::Fixture
49{
50public:
51 template <typename...>
52 void setup(TensorShape shape, Format format, bool suppress_nonmax, BorderMode border_mode)
53 {
54 std::mt19937 gen(library->seed());
55 std::uniform_int_distribution<uint8_t> int_dist(0, 255);
56 std::uniform_real_distribution<float> real_dist(0, 255);
57
58 const uint8_t constant_border_value = int_dist(gen);
59 const float threshold = real_dist(gen);
60
61 _target = compute_target(shape, format, threshold, suppress_nonmax, border_mode, constant_border_value);
62 _reference = compute_reference(shape, format, threshold, suppress_nonmax, border_mode, constant_border_value);
63 }
64
65protected:
66 template <typename U>
67 void fill(U &&tensor)
68 {
69 library->fill_tensor_uniform(tensor, 0);
70 }
71
72 template <typename F, typename std::enable_if<std::is_same<F, CLFastCorners>::value, int>::type = 0>
73 void configure_target(F &func, TensorType &src, ArrayType &corners, unsigned int *num_corners, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value)
74 {
75 func.configure(&src, threshold, suppress_nonmax, &corners, num_corners, border_mode, constant_border_value);
76 }
77
78 template <typename F, typename std::enable_if<std::is_same<F, NEFastCorners>::value, int>::type = 0>
79 void configure_target(F &func, TensorType &src, ArrayType &corners, unsigned int *num_corners, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value)
80 {
81 ARM_COMPUTE_UNUSED(num_corners);
82 // ARM_COMPUTE_ERROR_ON(num_corners);
83 func.configure(&src, threshold, suppress_nonmax, &corners, border_mode, constant_border_value);
84 }
85
86 ArrayType compute_target(const TensorShape &shape, Format format, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value)
87 {
88 // Create tensors
89 TensorType src = create_tensor<TensorType>(shape, data_type_from_format(format));
90 src.info()->set_format(format);
91
92 // Create array of keypoints
93 ArrayType corners(shape.total_size());
94 unsigned int num_corners = shape.total_size();
95
96 // Create and configure function
97 FunctionType fast_corners;
98 configure_target<FunctionType>(fast_corners, src, corners, &num_corners, threshold, suppress_nonmax, border_mode, constant_border_value);
99
100 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
101
102 // Allocate tensors
103 src.allocator()->allocate();
104
105 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
106
107 // Fill tensors
108 fill(AccessorType(src));
109
110 // Compute function
111 fast_corners.run();
112
113 return corners;
114 }
115
116 std::vector<KeyPoint> compute_reference(const TensorShape &shape, Format format, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value)
117 {
118 // Create reference
119 SimpleTensor<T> src{ shape, format };
120
121 // Fill reference
122 fill(src);
123
124 // Compute reference
125 return reference::fast_corners<T>(src, threshold, suppress_nonmax, border_mode, constant_border_value);
126 }
127
128 ArrayType _target{};
129 std::vector<KeyPoint> _reference{};
130};
131} // namespace validation
132} // namespace test
133} // namespace arm_compute
134#endif /* ARM_COMPUTE_TEST_FAST_CORNERS_FIXTURE */