blob: d52b17e5508f0cde04c3cfa83e95746cea8d912f [file] [log] [blame]
Abe Mbise1b993382017-12-19 13:51:59 +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_CANNY_EDGE_FIXTURE
25#define ARM_COMPUTE_TEST_CANNY_EDGE_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"
33#include "tests/validation/Helpers.h"
34#include "tests/validation/reference/CannyEdgeDetector.h"
35
36namespace arm_compute
37{
38class CLCannyEdge;
39class NECannyEdge;
40
41namespace test
42{
43namespace validation
44{
45template <typename TensorType, typename AccessorType, typename ArrayType, typename FunctionType, typename T>
46class CannyEdgeValidationFixture : public framework::Fixture
47{
48public:
49 template <typename...>
Georgios Pinitas09d34512018-08-30 16:02:11 +010050 void setup(std::string image, int gradient_size, MagnitudeType norm_type, BorderMode border_mode, Format format)
Abe Mbise1b993382017-12-19 13:51:59 +000051 {
52 CannyEdgeParameters params = canny_edge_parameters();
53
Georgios Pinitas09d34512018-08-30 16:02:11 +010054 _target = compute_target(image, gradient_size, norm_type, border_mode, format, params);
Abe Mbise1b993382017-12-19 13:51:59 +000055 _reference = compute_reference(image, gradient_size, norm_type, border_mode, format, params);
56 }
57
58protected:
59 template <typename U>
60 void fill(U &&tensor, RawTensor raw)
61 {
62 library->fill(tensor, raw);
63 }
64
Georgios Pinitas09d34512018-08-30 16:02:11 +010065 TensorType compute_target(const std::string &image, int gradient_size, MagnitudeType norm_type, BorderMode border_mode, Format format, const CannyEdgeParameters &params)
Abe Mbise1b993382017-12-19 13:51:59 +000066 {
67 // Load the image (cached by the library if loaded before)
68 const RawTensor &raw = library->get(image, format);
69
70 // Create tensors
71 TensorType src = create_tensor<TensorType>(raw.shape(), format);
72 TensorType dst = create_tensor<TensorType>(raw.shape(), format);
73 src.info()->set_format(format);
74 dst.info()->set_format(format);
75
76 // Create Canny edge configure function
77 FunctionType canny_edge;
Georgios Pinitas09d34512018-08-30 16:02:11 +010078 canny_edge.configure(&src, &dst, params.upper_thresh, params.lower_thresh, gradient_size, static_cast<int>(norm_type) + 1, border_mode, params.constant_border_value);
Abe Mbise1b993382017-12-19 13:51:59 +000079
80 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
81 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
82
83 // Allocate tensors
84 src.allocator()->allocate();
85 dst.allocator()->allocate();
86
87 ARM_COMPUTE_EXPECT(!src.info()->is_resizable(), framework::LogLevel::ERRORS);
88 ARM_COMPUTE_EXPECT(!dst.info()->is_resizable(), framework::LogLevel::ERRORS);
89
90 // Fill tensors
91 fill(AccessorType(src), raw);
92
93 // Compute function
94 canny_edge.run();
95
96 return dst;
97 }
98
99 SimpleTensor<T> compute_reference(const std::string &image, int gradient_size, MagnitudeType norm_type, BorderMode border_mode, Format format, const CannyEdgeParameters &params)
100 {
101 ARM_COMPUTE_ERROR_ON(format != Format::U8);
102
103 // Load the image (cached by the library if loaded before)
104 const RawTensor &raw = library->get(image, format);
105
106 // Create reference
107 SimpleTensor<T> src{ raw.shape(), format };
108
109 // Fill reference
110 fill(src, raw);
111
112 return reference::canny_edge_detector<T>(src, params.upper_thresh, params.lower_thresh, gradient_size, norm_type, border_mode, params.constant_border_value);
113 }
114
115 TensorType _target{};
116 SimpleTensor<T> _reference{};
117};
118} // namespace validation
119} // namespace test
120} // namespace arm_compute
121#endif /* ARM_COMPUTE_TEST_CANNY_EDGE_FIXTURE */