Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2021 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_CLHARRISCORNERS_H |
| 25 | #define ARM_COMPUTE_CLHARRISCORNERS_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/CL/ICLArray.h" |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 28 | #include "arm_compute/core/CPP/kernels/CPPCornerCandidatesKernel.h" |
| 29 | #include "arm_compute/core/CPP/kernels/CPPSortEuclideanDistanceKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/Types.h" |
| 31 | #include "arm_compute/runtime/CL/CLTensor.h" |
Giorgio Arena | fc2817d | 2017-06-27 17:26:37 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/CL/functions/CLNonMaximaSuppression3x3.h" |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 33 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | 5701e2a | 2017-09-18 17:43:33 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/IMemoryManager.h" |
Georgios Pinitas | 26014cf | 2019-09-09 19:00:57 +0100 | [diff] [blame] | 35 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 36 | #include <cstdint> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | #include <memory> |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 41 | class CLCompileContext; |
| 42 | class CLHarrisScoreKernel; |
| 43 | class CLFillBorderKernel; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 44 | class ICLTensor; |
| 45 | using ICLImage = ICLTensor; |
| 46 | |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 47 | /** Basic function to execute harris corners detection. This function calls the following CL and Neon kernels and functions: |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 48 | * |
| 49 | * @note Requires CPU support for the kernels: CPPCornerCandidatesKernel and CPPSortEuclideanDistanceKernel. |
| 50 | * |
| 51 | * -# @ref CLSobel3x3 (if gradient_size == 3) or<br/> |
| 52 | * @ref CLSobel5x5 (if gradient_size == 5) or<br/> |
| 53 | * @ref CLSobel7x7 (if gradient_size == 7) |
| 54 | * -# @ref CLFillBorderKernel |
| 55 | * -# @ref CLHarrisScoreKernel |
| 56 | * -# @ref CLNonMaximaSuppression3x3 |
| 57 | * -# @ref CPPCornerCandidatesKernel |
| 58 | * -# @ref CPPSortEuclideanDistanceKernel |
morgolock | 00c7601 | 2020-11-06 10:40:12 +0000 | [diff] [blame] | 59 | * |
| 60 | * @deprecated This function is deprecated and is intended to be removed in 21.05 release |
| 61 | * |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | */ |
| 63 | class CLHarrisCorners : public IFunction |
| 64 | { |
| 65 | public: |
| 66 | /** Constructor */ |
Georgios Pinitas | 5701e2a | 2017-09-18 17:43:33 +0100 | [diff] [blame] | 67 | CLHarrisCorners(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 69 | CLHarrisCorners(const CLHarrisCorners &) = delete; |
| 70 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 71 | const CLHarrisCorners &operator=(const CLHarrisCorners &) = delete; |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 72 | /** Default destructor */ |
| 73 | ~CLHarrisCorners(); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | /** Initialize the function's source, destination, conv and border_mode. |
| 75 | * |
| 76 | * @param[in,out] input Source image. Data types supported: U8. (Written to only for @p border_mode != UNDEFINED) |
| 77 | * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel). |
| 78 | * @param[in] min_dist Radial Euclidean distance for the euclidean distance stage. |
| 79 | * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation |
| 80 | * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7 |
| 81 | * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7. |
| 82 | * @param[out] corners Array of keypoints to store the results. |
| 83 | * @param[in] border_mode Border mode to use |
| 84 | * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. |
Alex Gilday | 6485691 | 2018-01-05 10:10:28 +0000 | [diff] [blame] | 85 | * @param[in] use_fp16 (Optional) If true the FP16 kernels will be used. If false F32 kernels are used. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | */ |
| 87 | void configure(ICLImage *input, float threshold, float min_dist, float sensitivity, |
| 88 | int32_t gradient_size, int32_t block_size, ICLKeyPointArray *corners, |
Alex Gilday | 6485691 | 2018-01-05 10:10:28 +0000 | [diff] [blame] | 89 | BorderMode border_mode, uint8_t constant_border_value = 0, bool use_fp16 = false); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 90 | /** Initialize the function's source, destination, conv and border_mode. |
| 91 | * |
| 92 | * @param[in] compile_context The compile context to be used. |
| 93 | * @param[in,out] input Source image. Data types supported: U8. (Written to only for @p border_mode != UNDEFINED) |
| 94 | * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel). |
| 95 | * @param[in] min_dist Radial Euclidean distance for the euclidean distance stage. |
| 96 | * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation |
| 97 | * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7 |
| 98 | * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7. |
| 99 | * @param[out] corners Array of keypoints to store the results. |
| 100 | * @param[in] border_mode Border mode to use |
| 101 | * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. |
| 102 | * @param[in] use_fp16 (Optional) If true the FP16 kernels will be used. If false F32 kernels are used. |
| 103 | */ |
| 104 | void configure(const CLCompileContext &compile_context, ICLImage *input, float threshold, float min_dist, float sensitivity, |
| 105 | int32_t gradient_size, int32_t block_size, ICLKeyPointArray *corners, |
| 106 | BorderMode border_mode, uint8_t constant_border_value = 0, bool use_fp16 = false); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 107 | |
| 108 | // Inherited methods overridden: |
| 109 | void run() override; |
| 110 | |
| 111 | private: |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 112 | MemoryGroup _memory_group; /**< Function's memory group */ |
| 113 | std::unique_ptr<IFunction> _sobel; /**< Sobel function */ |
| 114 | std::unique_ptr<CLHarrisScoreKernel> _harris_score; /**< Harris score kernel */ |
| 115 | CLNonMaximaSuppression3x3 _non_max_suppr; /**< Non-maxima suppression function */ |
| 116 | CPPCornerCandidatesKernel _candidates; /**< Sort kernel */ |
| 117 | CPPSortEuclideanDistanceKernel _sort_euclidean; /**< Euclidean distance kernel */ |
| 118 | std::unique_ptr<CLFillBorderKernel> _border_gx; /**< Border handler before running harris score */ |
| 119 | std::unique_ptr<CLFillBorderKernel> _border_gy; /**< Border handler before running harris score */ |
| 120 | CLImage _gx; /**< Source image - Gx component */ |
| 121 | CLImage _gy; /**< Source image - Gy component */ |
| 122 | CLImage _score; /**< Source image - Harris score */ |
| 123 | CLImage _nonmax; /**< Source image - Non-Maxima suppressed image */ |
| 124 | std::vector<InternalKeypoint> _corners_list; /**< Array of InternalKeypoint. It stores the potential corner candidates */ |
| 125 | int32_t _num_corner_candidates; /**< Number of potential corner candidates */ |
| 126 | ICLKeyPointArray *_corners; /**< Output corners array */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 127 | }; |
| 128 | } |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 129 | #endif /*ARM_COMPUTE_CLHARRISCORNERS_H */ |