Compute Library
 20.08
NEFastCorners.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2019 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  */
25 
26 #include "arm_compute/core/Error.h"
35 
36 using namespace arm_compute;
37 
38 NEFastCorners::NEFastCorners(std::shared_ptr<IMemoryManager> memory_manager)
39  : _memory_group(std::move(memory_manager)),
40  _fast_corners_kernel(),
41  _border_handler(),
42  _nonmax_kernel(),
43  _fill_kernel(),
44  _output(),
45  _suppressed(),
46  _non_max(false)
47 {
48 }
49 
50 void NEFastCorners::configure(IImage *input, float threshold, bool nonmax_suppression, KeyPointArray *corners,
51  BorderMode border_mode, uint8_t constant_border_value)
52 {
56  ARM_COMPUTE_ERROR_ON(nullptr == corners);
57  ARM_COMPUTE_ERROR_ON(threshold < 1 && threshold > 255);
58 
59  _non_max = nonmax_suppression;
60 
61  TensorInfo tensor_info(input->info()->tensor_shape(), Format::U8);
62  _output.allocator()->init(tensor_info);
63  _memory_group.manage(&_output);
64 
65  // If border is UNDEFINED _fast_corners_kernel will operate in xwindow (3,
66  // width - 3) and ywindow (3, height -3) so the output image will leave the
67  // pixels on the borders unchanged. This is reflected in the valid region
68  // of the output. The non maxima suppression is only run on the valid
69  // pixels.
70  _fast_corners_kernel.configure(input, &_output, threshold, nonmax_suppression, BorderMode::UNDEFINED == border_mode);
71  _border_handler.configure(input, _fast_corners_kernel.border_size(), border_mode, constant_border_value);
72 
73  if(!_non_max)
74  {
75  _fill_kernel.configure(&_output, 1 /* we keep all texels >0 */, corners);
76  }
77  else
78  {
79  _suppressed.allocator()->init(tensor_info);
80  _memory_group.manage(&_suppressed);
81  _nonmax_kernel.configure(&_output, &_suppressed, BorderMode::UNDEFINED == border_mode);
82  _fill_kernel.configure(&_suppressed, 1 /* we keep all texels >0 */, corners);
83 
84  // Allocate intermediate tensors
85  _suppressed.allocator()->allocate();
86  }
87 
88  // Allocate intermediate tensors
89  _output.allocator()->allocate();
90 }
91 
93 {
94  NEScheduler::get().schedule(&_border_handler, Window::DimZ);
95 
96  MemoryGroupResourceScope scope_mg(_memory_group);
97 
98  NEScheduler::get().schedule(&_fast_corners_kernel, Window::DimY);
99 
100  if(_non_max)
101  {
102  NEScheduler::get().schedule(&_nonmax_kernel, Window::DimY);
103  }
104 
105  NEScheduler::get().schedule(&_fill_kernel, Window::DimY);
106 }
BorderMode
Methods available to handle borders.
Definition: Types.h:264
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
1 channel, 1 U8 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void configure(ITensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
Initialise the function.
Interface for NEON tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2020 Arm Limited.
TensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: Tensor.cpp:48
Basic implementation of the IArray interface which allocates a static number of T values.
Definition: Array.h:37
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void configure(const ITensor *input, ITensor *output, bool border_undefined)
Initialise the kernel's sources, destinations and border mode.
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:856
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
void run() override
Run the kernels contained in the function.
void configure(const IImage *input, uint8_t threshold, IKeyPointArray *output)
Initialise the kernel.
NEFastCorners(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
BorderSize border_size() const override
The size of the border for that kernel.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Borders are left undefined.
void configure(IImage *input, float threshold, bool nonmax_suppression, KeyPointArray *corners, BorderMode border_mode, uint8_t constant_border_value=0)
Initialize the function's source, destination, conv and border_mode.
Store the tensor's metadata.
Definition: TensorInfo.h:45
void configure(const IImage *input, IImage *output, uint8_t threshold, bool non_max_suppression, bool border_undefined)
Initialise the kernel.
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:95