Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 09d3451 | 2018-08-30 16:02:11 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 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_HARRIS_CORNERS_FIXTURE |
| 25 | #define ARM_COMPUTE_TEST_HARRIS_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/framework/Asserts.h" |
| 32 | #include "tests/framework/Fixture.h" |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 33 | #include "tests/validation/Helpers.h" |
Georgios Pinitas | 5a7e776 | 2017-12-01 16:27:29 +0000 | [diff] [blame] | 34 | #include "tests/validation/reference/HarrisCornerDetector.h" |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 35 | |
| 36 | namespace arm_compute |
| 37 | { |
| 38 | class CLHarrisCorners; |
| 39 | class NEHarrisCorners; |
| 40 | |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | template <typename TensorType, typename AccessorType, typename ArrayType, typename FunctionType, typename T> |
| 46 | class HarrisCornersValidationFixture : public framework::Fixture |
| 47 | { |
| 48 | public: |
| 49 | template <typename...> |
Georgios Pinitas | 09d3451 | 2018-08-30 16:02:11 +0100 | [diff] [blame] | 50 | void setup(std::string image, int gradient_size, int block_size, BorderMode border_mode, Format format) |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 51 | { |
| 52 | HarrisCornersParameters params = harris_corners_parameters(); |
| 53 | |
Georgios Pinitas | 09d3451 | 2018-08-30 16:02:11 +0100 | [diff] [blame] | 54 | _target = compute_target(image, gradient_size, block_size, border_mode, format, params); |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 55 | _reference = compute_reference(image, gradient_size, block_size, border_mode, format, params); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | protected: |
| 59 | template <typename U> |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 60 | void fill(U &&tensor, RawTensor raw) |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 61 | { |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 62 | library->fill(tensor, raw); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Georgios Pinitas | 09d3451 | 2018-08-30 16:02:11 +0100 | [diff] [blame] | 65 | ArrayType compute_target(std::string image, int gradient_size, int block_size, BorderMode border_mode, Format format, const HarrisCornersParameters ¶ms) |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 66 | { |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 67 | // Load the image (cached by the library if loaded before) |
| 68 | const RawTensor &raw = library->get(image, format); |
| 69 | |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 70 | // Create tensors |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 71 | TensorType src = create_tensor<TensorType>(raw.shape(), format); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 72 | |
| 73 | // Create array of keypoints |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 74 | ArrayType corners(raw.shape().total_size()); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 75 | |
| 76 | // Create harris corners configure function |
| 77 | FunctionType harris_corners; |
Georgios Pinitas | 09d3451 | 2018-08-30 16:02:11 +0100 | [diff] [blame] | 78 | harris_corners.configure(&src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, &corners, border_mode, params.constant_border_value); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 79 | |
| 80 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 81 | |
| 82 | // Allocate tensors |
| 83 | src.allocator()->allocate(); |
| 84 | |
| 85 | ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 86 | |
| 87 | // Fill tensors |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 88 | fill(AccessorType(src), raw); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 89 | |
| 90 | // Compute function |
| 91 | harris_corners.run(); |
| 92 | |
| 93 | return corners; |
| 94 | } |
| 95 | |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 96 | std::vector<KeyPoint> compute_reference(std::string image, int gradient_size, int block_size, BorderMode border_mode, Format format, const HarrisCornersParameters ¶ms) |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 97 | { |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 98 | // Load the image (cached by the library if loaded before) |
| 99 | const RawTensor &raw = library->get(image, format); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 100 | // Create reference |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 101 | SimpleTensor<T> src{ raw.shape(), format }; |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 102 | |
| 103 | // Fill reference |
Alex Gilday | 345ab18 | 2018-01-09 11:40:19 +0000 | [diff] [blame] | 104 | fill(src, raw); |
Moritz Pflanzer | 6c6597c | 2017-09-24 12:09:41 +0100 | [diff] [blame] | 105 | |
| 106 | return reference::harris_corner_detector<T>(src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, border_mode, params.constant_border_value); |
| 107 | } |
| 108 | |
| 109 | ArrayType _target{}; |
| 110 | std::vector<KeyPoint> _reference{}; |
| 111 | }; |
| 112 | } // namespace validation |
| 113 | } // namespace test |
| 114 | } // namespace arm_compute |
| 115 | #endif /* ARM_COMPUTE_TEST_HARRIS_CORNERS_FIXTURE */ |