Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEHARRISCORNERS_H |
| 25 | #define ARM_COMPUTE_NEHARRISCORNERS_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/CPP/kernels/CPPCornerCandidatesKernel.h" |
| 28 | #include "arm_compute/core/CPP/kernels/CPPSortEuclideanDistanceKernel.h" |
| 29 | #include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h" |
| 30 | #include "arm_compute/core/NEON/kernels/NEHarrisCornersKernel.h" |
| 31 | #include "arm_compute/core/Types.h" |
| 32 | #include "arm_compute/runtime/Array.h" |
| 33 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | d910ffa | 2017-09-18 16:04:42 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/IMemoryManager.h" |
| 35 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | #include "arm_compute/runtime/NEON/functions/NENonMaximaSuppression3x3.h" |
| 37 | #include "arm_compute/runtime/Tensor.h" |
| 38 | |
| 39 | #include <cstdint> |
| 40 | #include <memory> |
| 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | class ITensor; |
| 45 | using IImage = ITensor; |
| 46 | |
| 47 | /** Basic function to execute harris corners detection. This function calls the following NEON kernels and functions: |
| 48 | * |
| 49 | * -# @ref NESobel3x3 (if gradient_size == 3) or<br/> |
| 50 | * @ref NESobel5x5 (if gradient_size == 5) or<br/> |
| 51 | * @ref NESobel7x7 (if gradient_size == 7) |
| 52 | * -# @ref NEFillBorderKernel |
| 53 | * -# NEHarrisScoreKernel<3> (if block_size == 3) or<br/> |
| 54 | * NEHarrisScoreKernel<5> (if block_size == 5) or<br/> |
| 55 | * NEHarrisScoreKernel<7> (if block_size == 7) |
| 56 | * -# @ref NENonMaximaSuppression3x3 |
| 57 | * -# @ref CPPCornerCandidatesKernel |
| 58 | * -# @ref CPPSortEuclideanDistanceKernel |
| 59 | * |
| 60 | */ |
| 61 | class NEHarrisCorners : public IFunction |
| 62 | { |
| 63 | public: |
| 64 | /** Constructor |
| 65 | * |
| 66 | * Initialize _sobel, _harris_score and _corner_list to nullptr. |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 67 | * |
| 68 | * @param[in] memory_manager (Optional) Memory manager. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 69 | */ |
Georgios Pinitas | d910ffa | 2017-09-18 16:04:42 +0100 | [diff] [blame] | 70 | NEHarrisCorners(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 71 | /** Initialize the function's source, destination, conv and border_mode. |
| 72 | * |
| 73 | * @param[in, out] input Source image. Data type supported: U8. (Written to only for @p border_mode != UNDEFINED) |
| 74 | * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel). |
| 75 | * @param[in] min_dist Radial Euclidean distance for the euclidean diatance stage |
| 76 | * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation |
| 77 | * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7 |
| 78 | * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7. |
| 79 | * @param[out] corners Array of keypoints to store the results. |
| 80 | * @param[in] border_mode Border mode to use |
| 81 | * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | */ |
| 83 | void configure(IImage *input, float threshold, float min_dist, float sensitivity, |
| 84 | int32_t gradient_size, int32_t block_size, KeyPointArray *corners, |
Georgios Pinitas | 09d3451 | 2018-08-30 16:02:11 +0100 | [diff] [blame] | 85 | BorderMode border_mode, uint8_t constant_border_value = 0); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | |
| 87 | // Inherited methods overridden: |
| 88 | void run() override; |
| 89 | |
| 90 | private: |
Georgios Pinitas | d910ffa | 2017-09-18 16:04:42 +0100 | [diff] [blame] | 91 | MemoryGroup _memory_group; /**< Function's memory group */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | std::unique_ptr<IFunction> _sobel; /**< Sobel function */ |
| 93 | std::unique_ptr<INEHarrisScoreKernel> _harris_score; /**< Harris score kernel */ |
| 94 | NENonMaximaSuppression3x3 _non_max_suppr; /**< Non-maxima suppression function */ |
| 95 | CPPCornerCandidatesKernel _candidates; /**< Sort kernel */ |
| 96 | CPPSortEuclideanDistanceKernel _sort_euclidean; /**< Euclidean distance kernel */ |
| 97 | NEFillBorderKernel _border_gx; /**< Border handler before running harris score */ |
| 98 | NEFillBorderKernel _border_gy; /**< Border handler before running harris score */ |
| 99 | Image _gx; /**< Source image - Gx component */ |
| 100 | Image _gy; /**< Source image - Gy component */ |
| 101 | Image _score; /**< Source image - Harris score */ |
| 102 | Image _nonmax; /**< Source image - Non-Maxima suppressed image */ |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 103 | std::vector<InternalKeypoint> _corners_list; /**< Array of InternalKeypoint. It stores the potential corner candidates */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 104 | int32_t _num_corner_candidates; /**< Number of potential corner candidates */ |
| 105 | }; |
| 106 | } |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 107 | #endif /*ARM_COMPUTE_NEHARRISCORNERS_H */ |