• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017-2020 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_CLLKTRACKERKERNEL_H
25 #define ARM_COMPUTE_CLLKTRACKERKERNEL_H
26 
27 #include "arm_compute/core/CL/ICLArray.h"
28 #include "arm_compute/core/Types.h"
29 #include "src/core/CL/ICLKernel.h"
30 
31 #include <cstddef>
32 #include <cstdint>
33 
34 namespace arm_compute
35 {
36 class ICLTensor;
37 
38 /** Interface to run the initialization step of LKTracker */
39 class CLLKTrackerInitKernel : public ICLKernel
40 {
41 public:
42     /** Initialise the kernel input and output
43      *
44      * @param[in]  old_points           Pointer to the @ref ICLKeyPointArray storing old key points
45      * @param[in]  new_points_estimates Pointer to the @ref ICLKeyPointArray storing new estimates key points
46      * @param[out] old_points_internal  Pointer to the array of internal @ref CLLKInternalKeypoint old points
47      * @param[out] new_points_internal  Pointer to the array of internal @ref CLLKInternalKeypoint new points
48      * @param[in]  use_initial_estimate The flag to indicate whether the initial estimated position should be used
49      * @param[in]  level                The pyramid level
50      * @param[in]  num_levels           The number of pyramid levels
51      * @param[in]  pyramid_scale        Scale factor used for generating the pyramid
52      */
53     void configure(const ICLKeyPointArray *old_points, const ICLKeyPointArray *new_points_estimates,
54                    ICLLKInternalKeypointArray *old_points_internal, ICLLKInternalKeypointArray *new_points_internal,
55                    bool use_initial_estimate, size_t level, size_t num_levels, float pyramid_scale);
56     /** Initialise the kernel input and output
57      *
58      * @param[in]  compile_context      The compile context to be used.
59      * @param[in]  old_points           Pointer to the @ref ICLKeyPointArray storing old key points
60      * @param[in]  new_points_estimates Pointer to the @ref ICLKeyPointArray storing new estimates key points
61      * @param[out] old_points_internal  Pointer to the array of internal @ref CLLKInternalKeypoint old points
62      * @param[out] new_points_internal  Pointer to the array of internal @ref CLLKInternalKeypoint new points
63      * @param[in]  use_initial_estimate The flag to indicate whether the initial estimated position should be used
64      * @param[in]  level                The pyramid level
65      * @param[in]  num_levels           The number of pyramid levels
66      * @param[in]  pyramid_scale        Scale factor used for generating the pyramid
67      */
68     void configure(const CLCompileContext &compile_context, const ICLKeyPointArray *old_points, const ICLKeyPointArray *new_points_estimates,
69                    ICLLKInternalKeypointArray *old_points_internal, ICLLKInternalKeypointArray *new_points_internal,
70                    bool use_initial_estimate, size_t level, size_t num_levels, float pyramid_scale);
71 
72     // Inherited methods overridden:
73     void run(const Window &window, cl::CommandQueue &queue) override;
74 };
75 
76 /** Interface to run the finalize step of LKTracker, where it truncates the coordinates stored in new_points array */
77 class CLLKTrackerFinalizeKernel : public ICLKernel
78 {
79 public:
80     /** Initialise the kernel input and output
81      *
82      * @param[in]  new_points_internal Pointer to the array of internal @ref CLLKInternalKeypoint new points
83      * @param[out] new_points          Pointer to the @ref ICLKeyPointArray storing new key points
84      */
85     void configure(ICLLKInternalKeypointArray *new_points_internal, ICLKeyPointArray *new_points);
86     /** Initialise the kernel input and output
87      *
88      * @param[in]  compile_context     The compile context to be used.
89      * @param[in]  new_points_internal Pointer to the array of internal @ref CLLKInternalKeypoint new points
90      * @param[out] new_points          Pointer to the @ref ICLKeyPointArray storing new key points
91      */
92     void configure(const CLCompileContext &compile_context, ICLLKInternalKeypointArray *new_points_internal, ICLKeyPointArray *new_points);
93 
94     // Inherited methods overridden:
95     void run(const Window &window, cl::CommandQueue &queue) override;
96 };
97 
98 /** Interface to run the first stage of LKTracker, where A11, A12, A22, min_eig, ival, ixval and iyval are computed */
99 class CLLKTrackerStage0Kernel : public ICLKernel
100 {
101 public:
102     /** Default constructor */
103     CLLKTrackerStage0Kernel();
104     /** Prevent instances of this class from being copied (As this class contains pointers) */
105     CLLKTrackerStage0Kernel(const CLLKTrackerStage0Kernel &) = delete;
106     /** Prevent instances of this class from being copied (As this class contains pointers) */
107     CLLKTrackerStage0Kernel &operator=(const CLLKTrackerStage0Kernel &) = delete;
108     /** Allow instances of this class to be moved */
109     CLLKTrackerStage0Kernel(CLLKTrackerStage0Kernel &&) = default;
110     /** Allow instances of this class to be moved */
111     CLLKTrackerStage0Kernel &operator=(CLLKTrackerStage0Kernel &&) = default;
112     /** Initialise the kernel input and output
113      *
114      * @param[in]      old_input           Pointer to the input old tensor. Data types supported: U8
115      * @param[in]      old_scharr_gx       Pointer to the input scharr X tensor. Data types supported: S16
116      * @param[in]      old_scharr_gy       Pointer to the input scharr Y tensor. Data types supported: S16
117      * @param[in]      old_points_internal Pointer to the array of CLLKInternalKeypoint old points
118      * @param[in, out] new_points_internal Pointer to the array of CLLKInternalKeypoint new points
119      * @param[out]     coeff_table         Pointer to the array holding the Spatial Gradient coefficients
120      * @param[out]     old_ival            Pointer to the array holding internal values
121      * @param[in]      window_dimension    The size of the window on which to perform the algorithm
122      * @param[in]      level               The pyramid level
123      */
124     void configure(const ICLTensor *old_input, const ICLTensor *old_scharr_gx, const ICLTensor *old_scharr_gy,
125                    ICLLKInternalKeypointArray *old_points_internal, ICLLKInternalKeypointArray *new_points_internal,
126                    ICLCoefficientTableArray *coeff_table, ICLOldValArray *old_ival,
127                    size_t window_dimension, size_t level);
128     /** Initialise the kernel input and output
129      *
130      * @param[in]      compile_context     The compile context to be used.
131      * @param[in]      old_input           Pointer to the input old tensor. Data types supported: U8
132      * @param[in]      old_scharr_gx       Pointer to the input scharr X tensor. Data types supported: S16
133      * @param[in]      old_scharr_gy       Pointer to the input scharr Y tensor. Data types supported: S16
134      * @param[in]      old_points_internal Pointer to the array of CLLKInternalKeypoint old points
135      * @param[in, out] new_points_internal Pointer to the array of CLLKInternalKeypoint new points
136      * @param[out]     coeff_table         Pointer to the array holding the Spatial Gradient coefficients
137      * @param[out]     old_ival            Pointer to the array holding internal values
138      * @param[in]      window_dimension    The size of the window on which to perform the algorithm
139      * @param[in]      level               The pyramid level
140      */
141     void configure(const CLCompileContext &compile_context, const ICLTensor *old_input, const ICLTensor *old_scharr_gx, const ICLTensor *old_scharr_gy,
142                    ICLLKInternalKeypointArray *old_points_internal, ICLLKInternalKeypointArray *new_points_internal,
143                    ICLCoefficientTableArray *coeff_table, ICLOldValArray *old_ival,
144                    size_t window_dimension, size_t level);
145 
146     // Inherited methods overridden:
147     void run(const Window &window, cl::CommandQueue &queue) override;
148 
149 private:
150     const ICLTensor *_old_input;
151     const ICLTensor *_old_scharr_gx;
152     const ICLTensor *_old_scharr_gy;
153 };
154 
155 /** Interface to run the second stage of LKTracker, where the motion vectors of the given points are computed */
156 class CLLKTrackerStage1Kernel : public ICLKernel
157 {
158 public:
159     /** Default constructor */
160     CLLKTrackerStage1Kernel();
161     /** Prevent instances of this class from being copied (As this class contains pointers) */
162     CLLKTrackerStage1Kernel(const CLLKTrackerStage1Kernel &) = delete;
163     /** Prevent instances of this class from being copied (As this class contains pointers) */
164     CLLKTrackerStage1Kernel &operator=(const CLLKTrackerStage1Kernel &) = delete;
165     /** Allow instances of this class to be moved */
166     CLLKTrackerStage1Kernel(CLLKTrackerStage1Kernel &&) = default;
167     /** Allow instances of this class to be moved */
168     CLLKTrackerStage1Kernel &operator=(CLLKTrackerStage1Kernel &&) = default;
169     /** Initialise the kernel input and output
170      *
171      * @param[in]      new_input           Pointer to the input new tensor. Data types supported: U8
172      * @param[in, out] new_points_internal Pointer to the array of CLLKInternalKeypoint for new points
173      * @param[in]      coeff_table         Pointer to the array holding the Spatial Gradient coefficients
174      * @param[in]      old_ival            Pointer to the array holding internal values
175      * @param[in]      termination         The criteria to terminate the search of each keypoint.
176      * @param[in]      epsilon             The error for terminating the algorithm
177      * @param[in]      num_iterations      The maximum number of iterations before terminating the algorithm
178      * @param[in]      window_dimension    The size of the window on which to perform the algorithm
179      * @param[in]      level               The pyramid level
180      */
181     void configure(const ICLTensor *new_input, ICLLKInternalKeypointArray *new_points_internal, ICLCoefficientTableArray *coeff_table, ICLOldValArray *old_ival,
182                    Termination termination, float epsilon, size_t num_iterations, size_t window_dimension, size_t level);
183     /** Initialise the kernel input and output
184      *
185      * @param[in]      compile_context     The compile context to be used.
186      * @param[in]      new_input           Pointer to the input new tensor. Data types supported: U8
187      * @param[in, out] new_points_internal Pointer to the array of CLLKInternalKeypoint for new points
188      * @param[in]      coeff_table         Pointer to the array holding the Spatial Gradient coefficients
189      * @param[in]      old_ival            Pointer to the array holding internal values
190      * @param[in]      termination         The criteria to terminate the search of each keypoint.
191      * @param[in]      epsilon             The error for terminating the algorithm
192      * @param[in]      num_iterations      The maximum number of iterations before terminating the algorithm
193      * @param[in]      window_dimension    The size of the window on which to perform the algorithm
194      * @param[in]      level               The pyramid level
195      */
196     void configure(const CLCompileContext &compile_context, const ICLTensor *new_input, ICLLKInternalKeypointArray *new_points_internal, ICLCoefficientTableArray *coeff_table, ICLOldValArray *old_ival,
197                    Termination termination, float epsilon, size_t num_iterations, size_t window_dimension, size_t level);
198 
199     // Inherited methods overridden:
200     void run(const Window &window, cl::CommandQueue &queue) override;
201 
202 private:
203     const ICLTensor *_new_input;
204 };
205 } // namespace arm_compute
206 #endif /*ARM_COMPUTE_CLLKTRACKERKERNEL_H */
207