blob: ae66c375efa9f9db5b955ba0b89d03e42bc03ecb [file] [log] [blame]
Abe Mbise25a340f2017-12-19 13:00:58 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2018 Arm Limited.
Abe Mbise25a340f2017-12-19 13:00:58 +00003 *
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...>
Abe Mbise562fe0f2018-02-09 14:13:02 +000052 void setup(std::string image, Format format, bool suppress_nonmax, BorderMode border_mode)
Abe Mbise25a340f2017-12-19 13:00:58 +000053 {
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
Abe Mbise562fe0f2018-02-09 14:13:02 +000061 _target = compute_target(image, format, threshold, suppress_nonmax, border_mode, constant_border_value);
62 _reference = compute_reference(image, format, threshold, suppress_nonmax, border_mode, constant_border_value);
Abe Mbise25a340f2017-12-19 13:00:58 +000063 }
64
65protected:
66 template <typename U>
Abe Mbise562fe0f2018-02-09 14:13:02 +000067 void fill(U &&tensor, RawTensor raw)
Abe Mbise25a340f2017-12-19 13:00:58 +000068 {
Abe Mbise562fe0f2018-02-09 14:13:02 +000069 library->fill(tensor, raw);
Abe Mbise25a340f2017-12-19 13:00:58 +000070 }
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);
Abe Mbise25a340f2017-12-19 13:00:58 +000082 func.configure(&src, threshold, suppress_nonmax, &corners, border_mode, constant_border_value);
83 }
84
Abe Mbise562fe0f2018-02-09 14:13:02 +000085 ArrayType compute_target(const std::string &image, Format format, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value)
Abe Mbise25a340f2017-12-19 13:00:58 +000086 {
Abe Mbise562fe0f2018-02-09 14:13:02 +000087 // Load the image (cached by the library if loaded before)
88 const RawTensor &raw = library->get(image, format);
89
Abe Mbise25a340f2017-12-19 13:00:58 +000090 // Create tensors
Abe Mbise562fe0f2018-02-09 14:13:02 +000091 TensorType src = create_tensor<TensorType>(raw.shape(), format);
Abe Mbise25a340f2017-12-19 13:00:58 +000092
93 // Create array of keypoints
Abe Mbise562fe0f2018-02-09 14:13:02 +000094 ArrayType corners(raw.shape().total_size());
95 unsigned int num_corners = raw.shape().total_size();
Abe Mbise25a340f2017-12-19 13:00:58 +000096
97 // Create and configure function
98 FunctionType fast_corners;
99 configure_target<FunctionType>(fast_corners, src, corners, &num_corners, threshold, suppress_nonmax, border_mode, constant_border_value);
100
101 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
102
103 // Allocate tensors
104 src.allocator()->allocate();
105
106 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
107
108 // Fill tensors
Abe Mbise562fe0f2018-02-09 14:13:02 +0000109 fill(AccessorType(src), raw);
Abe Mbise25a340f2017-12-19 13:00:58 +0000110
111 // Compute function
112 fast_corners.run();
113
114 return corners;
115 }
116
Abe Mbise562fe0f2018-02-09 14:13:02 +0000117 std::vector<KeyPoint> compute_reference(const std::string &image, Format format, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value)
Abe Mbise25a340f2017-12-19 13:00:58 +0000118 {
Abe Mbise562fe0f2018-02-09 14:13:02 +0000119 // Load the image (cached by the library if loaded before)
120 const RawTensor &raw = library->get(image, format);
121
Abe Mbise25a340f2017-12-19 13:00:58 +0000122 // Create reference
Abe Mbise562fe0f2018-02-09 14:13:02 +0000123 SimpleTensor<T> src{ raw.shape(), format };
Abe Mbise25a340f2017-12-19 13:00:58 +0000124
125 // Fill reference
Abe Mbise562fe0f2018-02-09 14:13:02 +0000126 fill(src, raw);
Abe Mbise25a340f2017-12-19 13:00:58 +0000127
128 // Compute reference
129 return reference::fast_corners<T>(src, threshold, suppress_nonmax, border_mode, constant_border_value);
130 }
131
132 ArrayType _target{};
133 std::vector<KeyPoint> _reference{};
134};
135} // namespace validation
136} // namespace test
137} // namespace arm_compute
138#endif /* ARM_COMPUTE_TEST_FAST_CORNERS_FIXTURE */