blob: 90da6874359458d621060935f4f0a16644de31cf [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 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_CLHARRISCORNERS_H__
25#define __ARM_COMPUTE_CLHARRISCORNERS_H__
26
27#include "arm_compute/runtime/IFunction.h"
28
29#include "arm_compute/core/CL/ICLArray.h"
30#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h"
31#include "arm_compute/core/CL/kernels/CLHarrisCornersKernel.h"
32#include "arm_compute/core/CL/kernels/CLNonMaximaSuppression3x3Kernel.h"
33#include "arm_compute/core/NEON/kernels/NEHarrisCornersKernel.h"
34#include "arm_compute/core/Types.h"
35#include "arm_compute/runtime/CL/CLTensor.h"
36
37#include <cstdint>
38
39#include <memory>
40
41namespace arm_compute
42{
43class ICLTensor;
44using ICLImage = ICLTensor;
45
46/** Basic function to execute harris corners detection. This function calls the following CL and NEON kernels and functions:
47 *
48 * @note Requires CPU support for the kernels: CPPCornerCandidatesKernel and CPPSortEuclideanDistanceKernel.
49 *
50 * -# @ref CLSobel3x3 (if gradient_size == 3) or<br/>
51 * @ref CLSobel5x5 (if gradient_size == 5) or<br/>
52 * @ref CLSobel7x7 (if gradient_size == 7)
53 * -# @ref CLFillBorderKernel
54 * -# @ref CLHarrisScoreKernel
55 * -# @ref CLNonMaximaSuppression3x3
56 * -# @ref CPPCornerCandidatesKernel
57 * -# @ref CPPSortEuclideanDistanceKernel
58 */
59class CLHarrisCorners : public IFunction
60{
61public:
62 /** Constructor */
63 CLHarrisCorners();
64 /** Prevent instances of this class from being copied (As this class contains pointers) */
65 CLHarrisCorners(const CLHarrisCorners &) = delete;
66 /** Prevent instances of this class from being copied (As this class contains pointers) */
67 const CLHarrisCorners &operator=(const CLHarrisCorners &) = delete;
68 /** Initialize the function's source, destination, conv and border_mode.
69 *
70 * @param[in,out] input Source image. Data types supported: U8. (Written to only for @p border_mode != UNDEFINED)
71 * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel).
72 * @param[in] min_dist Radial Euclidean distance for the euclidean distance stage.
73 * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation
74 * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7
75 * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7.
76 * @param[out] corners Array of keypoints to store the results.
77 * @param[in] border_mode Border mode to use
78 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
79 */
80 void configure(ICLImage *input, float threshold, float min_dist, float sensitivity,
81 int32_t gradient_size, int32_t block_size, ICLKeyPointArray *corners,
82 BorderMode border_mode, uint8_t constant_border_value = 0);
83
84 // Inherited methods overridden:
85 void run() override;
86
87private:
88 std::unique_ptr<IFunction> _sobel; /**< Sobel function */
89 CLHarrisScoreKernel _harris_score; /**< Harris score kernel */
90 CLNonMaximaSuppression3x3Kernel _non_max_suppr; /**< Non-maxima suppression function */
91 CPPCornerCandidatesKernel _candidates; /**< Sort kernel */
92 CPPSortEuclideanDistanceKernel _sort_euclidean; /**< Euclidean distance kernel */
93 CLFillBorderKernel _border_gx; /**< Border handler before running harris score */
94 CLFillBorderKernel _border_gy; /**< Border handler before running harris score */
95 CLImage _gx; /**< Source image - Gx component */
96 CLImage _gy; /**< Source image - Gy component */
97 CLImage _score; /**< Source image - Harris score */
98 CLImage _nonmax; /**< Source image - Non-Maxima suppressed image */
99 std::unique_ptr<InternalKeypoint[]> _corners_list; /**< Array of InternalKeypoint. It stores the potential corner candidates */
100 int32_t _num_corner_candidates; /**< Number of potential corner candidates */
101 ICLKeyPointArray *_corners; /**< Output corners array */
102};
103}
104#endif /*__ARM_COMPUTE_CLHARRISCORNERS_H__ */