blob: 1f24894aca659538ab0bbc72eff46b78e562b9a3 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLLKTRACKERKERNEL_H
25#define ARM_COMPUTE_CLLKTRACKERKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CL/ICLArray.h"
28#include "arm_compute/core/CL/ICLKernel.h"
29#include "arm_compute/core/Types.h"
30
31#include <cstddef>
32#include <cstdint>
33
34namespace arm_compute
35{
36class ICLTensor;
37
38/** Internal keypoint structure for Lucas-Kanade Optical Flow */
39struct CLLKInternalKeypoint
40{
41 float x{ 0.f }; /**< x coordinate of the keypoint */
42 float y{ 0.f }; /**< y coordinate of the keypoint */
43 float tracking_status{ 0.f }; /**< the tracking status of the keypoint */
44 float dummy{ 0.f }; /**< Dummy field, to make sure the data structure 128-bit align, so that GPU can use vload4 */
45};
46
47/** Structure for storing Spatial Gradient Matrix and the minimum eigenvalue for each keypoint */
48struct CLCoefficientTable
49{
50 float A11; /**< iA11 * FLT_SCALE */
51 float A12; /**< iA11 * FLT_SCALE */
52 float A22; /**< iA11 * FLT_SCALE */
53 float min_eig; /**< Minimum eigenvalue */
54};
55
56/** Structure for storing ival, ixval and iyval for each point inside the window */
57struct CLOldValue
58{
59 int16_t ival; /**< ival extracts from old image */
60 int16_t ixval; /**< ixval extracts from scharr Gx image */
61 int16_t iyval; /**< iyval extracts from scharr Gy image */
62 int16_t dummy; /**< Dummy field, to make sure the data structure 128-bit align, so that GPU can use vload4 */
63};
64
Alex Gildayc357c472018-03-21 13:54:09 +000065/** Interface for OpenCL Array of Internal Key Points. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066using ICLLKInternalKeypointArray = ICLArray<CLLKInternalKeypoint>;
Alex Gildayc357c472018-03-21 13:54:09 +000067/** Interface for OpenCL Array of Coefficient Tables. */
68using ICLCoefficientTableArray = ICLArray<CLCoefficientTable>;
69/** Interface for OpenCL Array of Old Values. */
70using ICLOldValArray = ICLArray<CLOldValue>;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071
72/** Interface to run the initialization step of LKTracker */
73class CLLKTrackerInitKernel : public ICLKernel
74{
75public:
76 /** Initialise the kernel input and output
77 *
78 * @param[in] old_points Pointer to the @ref ICLKeyPointArray storing old key points
79 * @param[in] new_points_estimates Pointer to the @ref ICLKeyPointArray storing new estimates key points
80 * @param[out] old_points_internal Pointer to the array of internal @ref CLLKInternalKeypoint old points
81 * @param[out] new_points_internal Pointer to the array of internal @ref CLLKInternalKeypoint new points
82 * @param[in] use_initial_estimate The flag to indicate whether the initial estimated position should be used
83 * @param[in] level The pyramid level
84 * @param[in] num_levels The number of pyramid levels
85 * @param[in] pyramid_scale Scale factor used for generating the pyramid
86 */
87 void configure(const ICLKeyPointArray *old_points, const ICLKeyPointArray *new_points_estimates,
88 ICLLKInternalKeypointArray *old_points_internal, ICLLKInternalKeypointArray *new_points_internal,
89 bool use_initial_estimate, size_t level, size_t num_levels, float pyramid_scale);
90
91 // Inherited methods overridden:
92 void run(const Window &window, cl::CommandQueue &queue) override;
93};
94
95/** Interface to run the finalize step of LKTracker, where it truncates the coordinates stored in new_points array */
96class CLLKTrackerFinalizeKernel : public ICLKernel
97{
98public:
99 /** Initialise the kernel input and output
100 *
101 * @param[in] new_points_internal Pointer to the array of internal @ref CLLKInternalKeypoint new points
102 * @param[out] new_points Pointer to the @ref ICLKeyPointArray storing new key points
103 */
104 void configure(ICLLKInternalKeypointArray *new_points_internal, ICLKeyPointArray *new_points);
105
106 // Inherited methods overridden:
107 void run(const Window &window, cl::CommandQueue &queue) override;
108};
109
110/** Interface to run the first stage of LKTracker, where A11, A12, A22, min_eig, ival, ixval and iyval are computed */
111class CLLKTrackerStage0Kernel : public ICLKernel
112{
113public:
114 /** Default constructor */
115 CLLKTrackerStage0Kernel();
116 /** Prevent instances of this class from being copied (As this class contains pointers) */
117 CLLKTrackerStage0Kernel(const CLLKTrackerStage0Kernel &) = delete;
118 /** Prevent instances of this class from being copied (As this class contains pointers) */
119 CLLKTrackerStage0Kernel &operator=(const CLLKTrackerStage0Kernel &) = delete;
120 /** Allow instances of this class to be moved */
121 CLLKTrackerStage0Kernel(CLLKTrackerStage0Kernel &&) = default;
122 /** Allow instances of this class to be moved */
123 CLLKTrackerStage0Kernel &operator=(CLLKTrackerStage0Kernel &&) = default;
124 /** Initialise the kernel input and output
125 *
126 * @param[in] old_input Pointer to the input old tensor. Data types supported: U8
127 * @param[in] old_scharr_gx Pointer to the input scharr X tensor. Data types supported: S16
128 * @param[in] old_scharr_gy Pointer to the input scharr Y tensor. Data types supported: S16
129 * @param[in] old_points_internal Pointer to the array of CLLKInternalKeypoint old points
130 * @param[in, out] new_points_internal Pointer to the array of CLLKInternalKeypoint new points
131 * @param[out] coeff_table Pointer to the array holding the Spatial Gradient coefficients
132 * @param[out] old_ival Pointer to the array holding internal values
133 * @param[in] window_dimension The size of the window on which to perform the algorithm
134 * @param[in] level The pyramid level
135 */
136 void configure(const ICLTensor *old_input, const ICLTensor *old_scharr_gx, const ICLTensor *old_scharr_gy,
137 ICLLKInternalKeypointArray *old_points_internal, ICLLKInternalKeypointArray *new_points_internal,
138 ICLCoefficientTableArray *coeff_table, ICLOldValArray *old_ival,
139 size_t window_dimension, size_t level);
140
141 // Inherited methods overridden:
142 void run(const Window &window, cl::CommandQueue &queue) override;
143
144private:
145 const ICLTensor *_old_input;
146 const ICLTensor *_old_scharr_gx;
147 const ICLTensor *_old_scharr_gy;
148};
149
150/** Interface to run the second stage of LKTracker, where the motion vectors of the given points are computed */
151class CLLKTrackerStage1Kernel : public ICLKernel
152{
153public:
154 /** Default constructor */
155 CLLKTrackerStage1Kernel();
156 /** Prevent instances of this class from being copied (As this class contains pointers) */
157 CLLKTrackerStage1Kernel(const CLLKTrackerStage1Kernel &) = delete;
158 /** Prevent instances of this class from being copied (As this class contains pointers) */
159 CLLKTrackerStage1Kernel &operator=(const CLLKTrackerStage1Kernel &) = delete;
160 /** Allow instances of this class to be moved */
161 CLLKTrackerStage1Kernel(CLLKTrackerStage1Kernel &&) = default;
162 /** Allow instances of this class to be moved */
163 CLLKTrackerStage1Kernel &operator=(CLLKTrackerStage1Kernel &&) = default;
164 /** Initialise the kernel input and output
165 *
166 * @param[in] new_input Pointer to the input new tensor. Data types supported: U8
167 * @param[in, out] new_points_internal Pointer to the array of CLLKInternalKeypoint for new points
168 * @param[in] coeff_table Pointer to the array holding the Spatial Gradient coefficients
169 * @param[in] old_ival Pointer to the array holding internal values
170 * @param[in] termination The criteria to terminate the search of each keypoint.
171 * @param[in] epsilon The error for terminating the algorithm
172 * @param[in] num_iterations The maximum number of iterations before terminating the algorithm
173 * @param[in] window_dimension The size of the window on which to perform the algorithm
174 * @param[in] level The pyramid level
175 */
176 void configure(const ICLTensor *new_input, ICLLKInternalKeypointArray *new_points_internal, ICLCoefficientTableArray *coeff_table, ICLOldValArray *old_ival,
177 Termination termination, float epsilon, size_t num_iterations, size_t window_dimension, size_t level);
178
179 // Inherited methods overridden:
180 void run(const Window &window, cl::CommandQueue &queue) override;
181
182private:
183 const ICLTensor *_new_input;
184};
Gian Marco Iodicef670a0a2017-09-18 12:20:45 +0100185} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000186#endif /*ARM_COMPUTE_CLLKTRACKERKERNEL_H */