Compute Library
 21.02
NELKTrackerKernel.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2021 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_LKTRACKERKERNEL_H
25 #define ARM_COMPUTE_LKTRACKERKERNEL_H
26 
28 #include "arm_compute/core/Types.h"
30 
31 #include <cstddef>
32 #include <cstdint>
33 #include <tuple>
34 #include <utility>
35 
36 namespace arm_compute
37 {
38 class ITensor;
39 
40 /** Interface for Neon Array of Internal Key Points. */
42 
43 /** Interface for the Lucas-Kanade tracker kernel */
45 {
46 public:
47  const char *name() const override
48  {
49  return "NELKTrackerKernel";
50  }
51  /** Default constructor */
53  /** Prevent instances of this class from being copied (As this class contains pointers) */
54  NELKTrackerKernel(const NELKTrackerKernel &) = delete;
55  /** Prevent instances of this class from being copied (As this class contains pointers) */
57  /** Allow instances of this class to be moved */
59  /** Allow instances of this class to be moved */
61  /** Default destructor */
62  ~NELKTrackerKernel() = default;
63 
64  /** Initialise the kernel input and output
65  *
66  * @param[in] input_old Pointer to the input old tensor. Data type supported: U8
67  * @param[in] input_new Pointer to the input new tensor. Data type supported. U8
68  * @param[in] old_scharr_gx Pointer to the input scharr X tensor. Data type supported: S16
69  * @param[in] old_scharr_gy Pointer to the input scharr Y tensor. Data type supported: S16
70  * @param[in] old_points Pointer to the IKeyPointArray storing old key points
71  * @param[in] new_points_estimates Pointer to the IKeyPointArray storing new estimates key points
72  * @param[out] new_points Pointer to the IKeyPointArray storing new key points
73  * @param[in, out] old_points_internal Pointer to the array of NELKInternalKeypoint for old points
74  * @param[out] new_points_internal Pointer to the array of NELKInternalKeypoint for new points
75  * @param[in] termination The criteria to terminate the search of each keypoint.
76  * @param[in] use_initial_estimate The flag to indicate whether the initial estimated position should be used
77  * @param[in] epsilon The error for terminating the algorithm
78  * @param[in] num_iterations The maximum number of iterations before terminate the algorithm
79  * @param[in] window_dimension The size of the window on which to perform the algorithm
80  * @param[in] level The pyramid level
81  * @param[in] num_levels The number of pyramid levels
82  * @param[in] pyramid_scale Scale factor used for generating the pyramid
83  */
84  void configure(const ITensor *input_old, const ITensor *input_new, const ITensor *old_scharr_gx, const ITensor *old_scharr_gy,
85  const IKeyPointArray *old_points, const IKeyPointArray *new_points_estimates, IKeyPointArray *new_points,
86  INELKInternalKeypointArray *old_points_internal, INELKInternalKeypointArray *new_points_internal,
87  Termination termination, bool use_initial_estimate, float epsilon, unsigned int num_iterations, size_t window_dimension,
88  size_t level, size_t num_levels, float pyramid_scale);
89 
90  // Inherited methods overridden:
91  void run(const Window &window, const ThreadInfo &info) override;
92  BorderSize border_size() const override;
93 
94 private:
95  /** Initialise the array of keypoints in the provide range
96  *
97  * @param[in] start Index of first element in the keypoints array to be initialised
98  * @param[in] end Index after last elelemnt in the keypoints array to be initialised
99  */
100  void init_keypoints(int start, int end);
101  /** Compute the structure tensor A^T * A based on the scharr gradients I_x and I_y
102  *
103  * @param[in] keypoint Keypoint for which gradients are computed
104  * @param[out] bilinear_ix Intermediate interpolated data for X gradient
105  * @param[out] bilinear_iy Intermediate interpolated data for Y gradient
106  *
107  * @return Values A11, A12, A22
108  */
109  std::tuple<int, int, int> compute_spatial_gradient_matrix(const NELKInternalKeypoint &keypoint, int32_t *bilinear_ix, int32_t *bilinear_iy);
110  /** Compute the vector A^T * b, i.e. -sum(I_d * I_t) for d in {x,y}
111  *
112  * @param[in] old_keypoint Old keypoint for which gradient is computed
113  * @param[in] new_keypoint New keypoint for which gradient is computed
114  * @param[in] bilinear_ix Intermediate interpolated data for X gradient
115  * @param[in] bilinear_iy Intermediate interpolated data for Y gradient
116  *
117  * @return Values b1, b2
118  */
119  std::pair<int, int> compute_image_mismatch_vector(const NELKInternalKeypoint &old_keypoint, const NELKInternalKeypoint &new_keypoint, const int32_t *bilinear_ix, const int32_t *bilinear_iy);
120 
121  const ITensor *_input_old;
122  const ITensor *_input_new;
123  const ITensor *_old_scharr_gx;
124  const ITensor *_old_scharr_gy;
125  IKeyPointArray *_new_points;
126  const IKeyPointArray *_new_points_estimates;
127  const IKeyPointArray *_old_points;
128  INELKInternalKeypointArray *_old_points_internal;
129  INELKInternalKeypointArray *_new_points_internal;
130  Termination _termination;
131  bool _use_initial_estimate;
132  float _pyramid_scale;
133  float _epsilon;
134  unsigned int _num_iterations;
135  int _window_dimension;
136  unsigned int _level;
137  unsigned int _num_levels;
138  ValidRegion _valid_region;
139 };
140 } // namespace arm_compute
141 #endif /*ARM_COMPUTE_NELKTRACKERKERNEL_H */
Internal keypoint class for Lucas-Kanade Optical Flow.
Definition: Types.h:2262
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
Container for 2D border size.
Definition: Types.h:273
const char * name() const override
Name of the kernel.
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
NELKTrackerKernel & operator=(const NELKTrackerKernel &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
Interface for Neon tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
~NELKTrackerKernel()=default
Default destructor.
BorderSize border_size() const override
The size of the border for that kernel.
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
Termination
Termination criteria.
Definition: Types.h:414
void configure(const ITensor *input_old, const ITensor *input_new, const ITensor *old_scharr_gx, const ITensor *old_scharr_gy, const IKeyPointArray *old_points, const IKeyPointArray *new_points_estimates, IKeyPointArray *new_points, INELKInternalKeypointArray *old_points_internal, INELKInternalKeypointArray *new_points_internal, Termination termination, bool use_initial_estimate, float epsilon, unsigned int num_iterations, size_t window_dimension, size_t level, size_t num_levels, float pyramid_scale)
Initialise the kernel input and output.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:235
Interface for the Lucas-Kanade tracker kernel.
Container for valid region of a window.
Definition: Types.h:188
NELKTrackerKernel()
Default constructor.
Describe a multidimensional execution window.
Definition: Window.h:39