blob: c3c37e4d243e2c7e313be9a35a5ed316f098ad36 [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_NEHARRISCORNERSKERNEL_H__
25#define __ARM_COMPUTE_NEHARRISCORNERSKERNEL_H__
26
27#include "arm_compute/core/CPP/kernels/CPPCornerCandidatesKernel.h"
28#include "arm_compute/core/CPP/kernels/CPPSortEuclideanDistanceKernel.h"
29#include "arm_compute/core/IArray.h"
30#include "arm_compute/core/NEON/INEKernel.h"
31
32#include <cstdint>
33#include <mutex>
34
35namespace arm_compute
36{
37class ITensor;
38using IImage = ITensor;
39
40/** Common interface for all Harris Score kernels */
41class INEHarrisScoreKernel : public INEKernel
42{
43public:
44 /** Default constructor */
45 INEHarrisScoreKernel();
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 INEHarrisScoreKernel(const INEHarrisScoreKernel &) = delete;
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 INEHarrisScoreKernel &operator=(const INEHarrisScoreKernel &) = delete;
50 /** Allow instances of this class to be moved */
51 INEHarrisScoreKernel(INEHarrisScoreKernel &&) = default;
52 /** Allow instances of this class to be moved */
53 INEHarrisScoreKernel &operator=(INEHarrisScoreKernel &&) = default;
54 /** Default destructor */
55 ~INEHarrisScoreKernel() = default;
56
57public:
58 /** Setup the kernel parameters
59 *
60 * @param[in] input1 Source image (gradient X). Data types supported: S16/S32
61 * @param[in] input2 Source image (gradient Y). Data types supported: same as @ input1
62 * @param[out] output Destination image (harris score). Data types supported: F32
63 * @param[in] norm_factor Normalization factor to use accordingly with the gradient size (Must be different from 0)
64 * @param[in] strength_thresh Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel).
65 * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation
66 * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant.
67 */
68 virtual void configure(const IImage *input1, const IImage *input2, IImage *output, float norm_factor, float strength_thresh, float sensitivity, bool border_undefined) = 0;
69
70protected:
71 const IImage *_input1; /**< Source image - Gx component */
72 const IImage *_input2; /**< Source image - Gy component */
73 IImage *_output; /**< Source image - Harris score */
74 float _sensitivity; /**< Sensitivity value */
75 float _strength_thresh; /**< Threshold value */
76 float _norm_factor; /**< Normalization factor */
77 BorderSize _border_size; /**< Border size */
78};
79
80/** Template NEON kernel to perform Harris Score.
81 * The implementation supports 3, 5, and 7 for the block_size
82 */
83template <int32_t block_size>
84class NEHarrisScoreKernel : public INEHarrisScoreKernel
85{
86public:
87 /** Default constructor */
88 NEHarrisScoreKernel();
89 // Inherited methods overridden:
90 void configure(const IImage *input1, const IImage *input2, IImage *output, float norm_factor, float strength_thresh, float sensitivity, bool border_undefined) override;
91 BorderSize border_size() const override;
Moritz Pflanzerc186b572017-09-07 09:48:04 +010092 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093
94private:
95 /** Common signature for all the specialised harris score functions */
96 using HarrisScoreFunction = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int32_t input_stride,
97 float norm_factor, float sensitivity, float strength_thresh);
98 /** Harris Score function to use for the particular image types passed to configure() */
99 HarrisScoreFunction *_func;
100};
101
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000102#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103/** Interface for the accumulate Weighted kernel using F16 */
104template <int32_t block_size>
105class NEHarrisScoreFP16Kernel : public INEHarrisScoreKernel
106{
107public:
108 /** Default constructor */
109 NEHarrisScoreFP16Kernel();
110 // Inherited methods overridden:
111 void configure(const IImage *input1, const IImage *input2, IImage *output, float norm_factor, float strength_thresh, float sensitivity, bool border_undefined) override;
112 BorderSize border_size() const override;
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100113 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100114
115private:
116 using HarrisScoreFunction = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int32_t input_stride,
117 float norm_factor, float sensitivity, float strength_thresh);
118 /** Harris Score function to use for the particular image types passed to configure() */
119 HarrisScoreFunction *_func;
120};
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000121#else /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122template <int32_t block_size>
123using NEHarrisScoreFP16Kernel = NEHarrisScoreKernel<block_size>;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000124#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100125} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100126#endif /* __ARM_COMPUTE_NEHARRISCORNERSKERNEL_H__ */