Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | class CLFastCorners; |
| 41 | class NEFastCorners; |
| 42 | |
| 43 | namespace test |
| 44 | { |
| 45 | namespace validation |
| 46 | { |
| 47 | template <typename TensorType, typename AccessorType, typename ArrayType, typename FunctionType, typename T> |
| 48 | class FastCornersValidationFixture : public framework::Fixture |
| 49 | { |
| 50 | public: |
| 51 | template <typename...> |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 52 | void setup(std::string image, Format format, bool suppress_nonmax, BorderMode border_mode) |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 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 | |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 61 | _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 Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | protected: |
| 66 | template <typename U> |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 67 | void fill(U &&tensor, RawTensor raw) |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 68 | { |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 69 | library->fill(tensor, raw); |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 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); |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 82 | func.configure(&src, threshold, suppress_nonmax, &corners, border_mode, constant_border_value); |
| 83 | } |
| 84 | |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 85 | ArrayType compute_target(const std::string &image, Format format, float threshold, bool suppress_nonmax, BorderMode border_mode, uint8_t constant_border_value) |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 86 | { |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 87 | // Load the image (cached by the library if loaded before) |
| 88 | const RawTensor &raw = library->get(image, format); |
| 89 | |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 90 | // Create tensors |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 91 | TensorType src = create_tensor<TensorType>(raw.shape(), format); |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 92 | |
| 93 | // Create array of keypoints |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 94 | ArrayType corners(raw.shape().total_size()); |
| 95 | unsigned int num_corners = raw.shape().total_size(); |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 96 | |
| 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 Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 109 | fill(AccessorType(src), raw); |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 110 | |
| 111 | // Compute function |
| 112 | fast_corners.run(); |
| 113 | |
| 114 | return corners; |
| 115 | } |
| 116 | |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 117 | 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 Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 118 | { |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 119 | // Load the image (cached by the library if loaded before) |
| 120 | const RawTensor &raw = library->get(image, format); |
| 121 | |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 122 | // Create reference |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 123 | SimpleTensor<T> src{ raw.shape(), format }; |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 124 | |
| 125 | // Fill reference |
Abe Mbise | 562fe0f | 2018-02-09 14:13:02 +0000 | [diff] [blame] | 126 | fill(src, raw); |
Abe Mbise | 25a340f | 2017-12-19 13:00:58 +0000 | [diff] [blame] | 127 | |
| 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 */ |