Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +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 | #include "arm_compute/runtime/NEON/functions/NEFastCorners.h" |
| 25 | |
| 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/ITensor.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/PixelValue.h" |
| 29 | #include "arm_compute/core/TensorInfo.h" |
| 30 | #include "arm_compute/core/Validate.h" |
| 31 | #include "arm_compute/runtime/Array.h" |
| 32 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
| 33 | #include "arm_compute/runtime/TensorAllocator.h" |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 34 | #include "src/core/NEON/kernels/NEFastCornersKernel.h" |
| 35 | #include "src/core/NEON/kernels/NEFillArrayKernel.h" |
| 36 | #include "src/core/NEON/kernels/NEFillBorderKernel.h" |
| 37 | #include "src/core/NEON/kernels/NENonMaximaSuppression3x3Kernel.h" |
| 38 | #include "support/MemorySupport.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 40 | namespace arm_compute |
| 41 | { |
| 42 | NEFastCorners::~NEFastCorners() = default; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 43 | |
Georgios Pinitas | d910ffa | 2017-09-18 16:04:42 +0100 | [diff] [blame] | 44 | NEFastCorners::NEFastCorners(std::shared_ptr<IMemoryManager> memory_manager) |
| 45 | : _memory_group(std::move(memory_manager)), |
| 46 | _fast_corners_kernel(), |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | _border_handler(), |
| 48 | _nonmax_kernel(), |
| 49 | _fill_kernel(), |
| 50 | _output(), |
| 51 | _suppressed(), |
| 52 | _non_max(false) |
| 53 | { |
| 54 | } |
| 55 | |
| 56 | void NEFastCorners::configure(IImage *input, float threshold, bool nonmax_suppression, KeyPointArray *corners, |
| 57 | BorderMode border_mode, uint8_t constant_border_value) |
| 58 | { |
| 59 | ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(input); |
| 60 | ARM_COMPUTE_ERROR_ON(BorderMode::UNDEFINED != border_mode); |
| 61 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8); |
| 62 | ARM_COMPUTE_ERROR_ON(nullptr == corners); |
| 63 | ARM_COMPUTE_ERROR_ON(threshold < 1 && threshold > 255); |
| 64 | |
| 65 | _non_max = nonmax_suppression; |
| 66 | |
| 67 | TensorInfo tensor_info(input->info()->tensor_shape(), Format::U8); |
| 68 | _output.allocator()->init(tensor_info); |
Georgios Pinitas | d910ffa | 2017-09-18 16:04:42 +0100 | [diff] [blame] | 69 | _memory_group.manage(&_output); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 70 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 71 | _fast_corners_kernel = arm_compute::support::cpp14::make_unique<NEFastCornersKernel>(); |
| 72 | _border_handler = arm_compute::support::cpp14::make_unique<NEFillBorderKernel>(); |
| 73 | _fill_kernel = arm_compute::support::cpp14::make_unique<NEFillArrayKernel>(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | // If border is UNDEFINED _fast_corners_kernel will operate in xwindow (3, |
| 75 | // width - 3) and ywindow (3, height -3) so the output image will leave the |
| 76 | // pixels on the borders unchanged. This is reflected in the valid region |
| 77 | // of the output. The non maxima suppression is only run on the valid |
| 78 | // pixels. |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 79 | _fast_corners_kernel->configure(input, &_output, threshold, nonmax_suppression, BorderMode::UNDEFINED == border_mode); |
| 80 | _border_handler->configure(input, _fast_corners_kernel->border_size(), border_mode, constant_border_value); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 81 | |
| 82 | if(!_non_max) |
| 83 | { |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 84 | _fill_kernel->configure(&_output, 1 /* we keep all texels >0 */, corners); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 85 | } |
| 86 | else |
| 87 | { |
| 88 | _suppressed.allocator()->init(tensor_info); |
Georgios Pinitas | d910ffa | 2017-09-18 16:04:42 +0100 | [diff] [blame] | 89 | _memory_group.manage(&_suppressed); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 90 | _nonmax_kernel = arm_compute::support::cpp14::make_unique<NENonMaximaSuppression3x3Kernel>(); |
| 91 | _nonmax_kernel->configure(&_output, &_suppressed, BorderMode::UNDEFINED == border_mode); |
| 92 | _fill_kernel->configure(&_suppressed, 1 /* we keep all texels >0 */, corners); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 93 | |
| 94 | // Allocate intermediate tensors |
| 95 | _suppressed.allocator()->allocate(); |
| 96 | } |
| 97 | |
| 98 | // Allocate intermediate tensors |
| 99 | _output.allocator()->allocate(); |
| 100 | } |
| 101 | |
| 102 | void NEFastCorners::run() |
| 103 | { |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 104 | NEScheduler::get().schedule(_border_handler.get(), Window::DimZ); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 105 | |
Georgios Pinitas | da953f2 | 2019-04-02 17:27:03 +0100 | [diff] [blame] | 106 | MemoryGroupResourceScope scope_mg(_memory_group); |
Georgios Pinitas | d910ffa | 2017-09-18 16:04:42 +0100 | [diff] [blame] | 107 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 108 | NEScheduler::get().schedule(_fast_corners_kernel.get(), Window::DimY); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 109 | |
| 110 | if(_non_max) |
| 111 | { |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 112 | NEScheduler::get().schedule(_nonmax_kernel.get(), Window::DimY); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 113 | } |
| 114 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 115 | NEScheduler::get().schedule(_fill_kernel.get(), Window::DimY); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | } |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 117 | } // namespace arm_compute |