blob: 1c30157344b9d08d8c3dd9b49a8a9da46e519e3a [file] [log] [blame]
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +01001/*
Alex Gilday345ab182018-01-09 11:40:19 +00002 * Copyright (c) 2017, 2018 ARM Limited.
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +01003 *
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 Pflanzer6c6597c2017-09-24 12:09:41 +010033#include "tests/validation/Helpers.h"
Georgios Pinitas5a7e7762017-12-01 16:27:29 +000034#include "tests/validation/reference/HarrisCornerDetector.h"
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010035
36namespace arm_compute
37{
38class CLHarrisCorners;
39class NEHarrisCorners;
40
41namespace test
42{
43namespace validation
44{
45template <typename TensorType, typename AccessorType, typename ArrayType, typename FunctionType, typename T>
46class HarrisCornersValidationFixture : public framework::Fixture
47{
48public:
49 template <typename...>
Alex Gilday345ab182018-01-09 11:40:19 +000050 void setup(std::string image, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, Format format)
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010051 {
52 HarrisCornersParameters params = harris_corners_parameters();
53
Alex Gilday345ab182018-01-09 11:40:19 +000054 _target = compute_target(image, gradient_size, block_size, border_mode, use_fp16, format, params);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010055 //TODO(COMPMID-543): Add use_fp16 to reference
Alex Gilday345ab182018-01-09 11:40:19 +000056 _reference = compute_reference(image, gradient_size, block_size, border_mode, format, params);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010057 }
58
59protected:
60 template <typename U>
Alex Gilday345ab182018-01-09 11:40:19 +000061 void fill(U &&tensor, RawTensor raw)
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010062 {
Alex Gilday345ab182018-01-09 11:40:19 +000063 library->fill(tensor, raw);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010064 }
65
66 template <typename F, typename std::enable_if<std::is_same<F, NEHarrisCorners>::value, int>::type = 0>
67 void configure_target(F &func, TensorType &src, ArrayType &corners, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, const HarrisCornersParameters &params)
68 {
69 func.configure(&src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, &corners, border_mode, params.constant_border_value, use_fp16);
70 }
71
72 template <typename F, typename std::enable_if<std::is_same<F, CLHarrisCorners>::value, int>::type = 0>
73 void configure_target(F &func, TensorType &src, ArrayType &corners, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, const HarrisCornersParameters &params)
74 {
75 ARM_COMPUTE_UNUSED(use_fp16);
76 ARM_COMPUTE_ERROR_ON(use_fp16);
77 func.configure(&src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, &corners, border_mode, params.constant_border_value);
78 }
79
Alex Gilday345ab182018-01-09 11:40:19 +000080 ArrayType compute_target(std::string image, int gradient_size, int block_size, BorderMode border_mode, bool use_fp16, Format format, const HarrisCornersParameters &params)
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010081 {
Alex Gilday345ab182018-01-09 11:40:19 +000082 // Load the image (cached by the library if loaded before)
83 const RawTensor &raw = library->get(image, format);
84
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010085 // Create tensors
Alex Gilday345ab182018-01-09 11:40:19 +000086 TensorType src = create_tensor<TensorType>(raw.shape(), format);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010087
88 // Create array of keypoints
Alex Gilday345ab182018-01-09 11:40:19 +000089 ArrayType corners(raw.shape().total_size());
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +010090
91 // Create harris corners configure function
92 FunctionType harris_corners;
93 configure_target<FunctionType>(harris_corners, src, corners, gradient_size, block_size, border_mode, use_fp16, params);
94
95 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
96
97 // Allocate tensors
98 src.allocator()->allocate();
99
100 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
101
102 // Fill tensors
Alex Gilday345ab182018-01-09 11:40:19 +0000103 fill(AccessorType(src), raw);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100104
105 // Compute function
106 harris_corners.run();
107
108 return corners;
109 }
110
Alex Gilday345ab182018-01-09 11:40:19 +0000111 std::vector<KeyPoint> compute_reference(std::string image, int gradient_size, int block_size, BorderMode border_mode, Format format, const HarrisCornersParameters &params)
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100112 {
Alex Gilday345ab182018-01-09 11:40:19 +0000113 // Load the image (cached by the library if loaded before)
114 const RawTensor &raw = library->get(image, format);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100115 // Create reference
Alex Gilday345ab182018-01-09 11:40:19 +0000116 SimpleTensor<T> src{ raw.shape(), format };
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100117
118 // Fill reference
Alex Gilday345ab182018-01-09 11:40:19 +0000119 fill(src, raw);
Moritz Pflanzer6c6597c2017-09-24 12:09:41 +0100120
121 return reference::harris_corner_detector<T>(src, params.threshold, params.min_dist, params.sensitivity, gradient_size, block_size, border_mode, params.constant_border_value);
122 }
123
124 ArrayType _target{};
125 std::vector<KeyPoint> _reference{};
126};
127} // namespace validation
128} // namespace test
129} // namespace arm_compute
130#endif /* ARM_COMPUTE_TEST_HARRIS_CORNERS_FIXTURE */