Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLOPTICALFLOW_H |
| 25 | #define ARM_COMPUTE_CLOPTICALFLOW_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/CL/kernels/CLLKTrackerKernel.h" |
| 28 | |
| 29 | #include "arm_compute/core/IArray.h" |
| 30 | #include "arm_compute/core/Types.h" |
| 31 | #include "arm_compute/runtime/CL/CLArray.h" |
| 32 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 33 | #include "arm_compute/runtime/CL/functions/CLScharr3x3.h" |
| 34 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | 8a94e7c | 2017-09-15 19:06:47 +0100 | [diff] [blame] | 35 | #include "arm_compute/runtime/IMemoryManager.h" |
Georgios Pinitas | 26014cf | 2019-09-09 19:00:57 +0100 | [diff] [blame] | 36 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | |
| 38 | #include <cstddef> |
| 39 | #include <cstdint> |
| 40 | #include <memory> |
| 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | class CLPyramid; |
| 45 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 46 | /** OpenCL Array of Internal Keypoints */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | using CLLKInternalKeypointArray = CLArray<CLLKInternalKeypoint>; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 48 | /** OpenCL Array of Coefficient Tables */ |
| 49 | using CLCoefficientTableArray = CLArray<CLCoefficientTable>; |
| 50 | /** OpenCL Array of Old Values */ |
| 51 | using CLOldValueArray = CLArray<CLOldValue>; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 52 | |
| 53 | /** Basic function to execute optical flow. This function calls the following OpenCL kernels and functions: |
| 54 | * |
| 55 | * -# @ref CLScharr3x3 |
| 56 | * -# @ref CLLKTrackerInitKernel |
| 57 | * -# @ref CLLKTrackerStage0Kernel |
| 58 | * -# @ref CLLKTrackerStage1Kernel |
| 59 | * -# @ref CLLKTrackerFinalizeKernel |
| 60 | */ |
| 61 | class CLOpticalFlow : public IFunction |
| 62 | { |
| 63 | public: |
| 64 | /** Default constructor */ |
Georgios Pinitas | 8a94e7c | 2017-09-15 19:06:47 +0100 | [diff] [blame] | 65 | CLOpticalFlow(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 66 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 67 | CLOpticalFlow(const CLOpticalFlow &) = delete; |
| 68 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 69 | CLOpticalFlow &operator=(const CLOpticalFlow &) = delete; |
| 70 | /** Allow instances of this class to be moved */ |
| 71 | CLOpticalFlow(CLOpticalFlow &&) = default; |
| 72 | /** Allow instances of this class to be moved */ |
| 73 | CLOpticalFlow &operator=(CLOpticalFlow &&) = default; |
| 74 | /** Initialise the function input and output |
| 75 | * |
| 76 | * @param[in] old_pyramid Pointer to the pyramid for the old tensor. Data types supported U8 |
| 77 | * @param[in] new_pyramid Pointer to the pyramid for the new tensor. Data types supported U8 |
| 78 | * @param[in] old_points Pointer to the IKeyPointArray storing old key points |
| 79 | * @param[in] new_points_estimates Pointer to the IKeyPointArray storing new estimates key points |
| 80 | * @param[out] new_points Pointer to the IKeyPointArray storing new key points |
| 81 | * @param[in] termination The criteria to terminate the search of each keypoint. |
| 82 | * @param[in] epsilon The error for terminating the algorithm |
| 83 | * @param[in] num_iterations The maximum number of iterations before terminate the alogrithm |
| 84 | * @param[in] window_dimension The size of the window on which to perform the algorithm |
| 85 | * @param[in] use_initial_estimate The flag to indicate whether the initial estimated position should be used |
| 86 | * @param[in] border_mode The border mode applied at scharr kernel stage |
| 87 | * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT |
| 88 | * |
| 89 | */ |
| 90 | void configure(const CLPyramid *old_pyramid, const CLPyramid *new_pyramid, |
| 91 | const ICLKeyPointArray *old_points, const ICLKeyPointArray *new_points_estimates, ICLKeyPointArray *new_points, |
| 92 | Termination termination, float epsilon, size_t num_iterations, size_t window_dimension, bool use_initial_estimate, |
| 93 | BorderMode border_mode, uint8_t constant_border_value = 0); |
| 94 | |
| 95 | // Inherited methods overridden: |
| 96 | void run() override; |
| 97 | |
| 98 | private: |
Georgios Pinitas | 26014cf | 2019-09-09 19:00:57 +0100 | [diff] [blame] | 99 | MemoryGroup _memory_group; |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 100 | std::vector<CLLKTrackerInitKernel> _tracker_init_kernel; |
| 101 | std::vector<CLLKTrackerStage0Kernel> _tracker_stage0_kernel; |
| 102 | std::vector<CLLKTrackerStage1Kernel> _tracker_stage1_kernel; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 103 | CLLKTrackerFinalizeKernel _tracker_finalize_kernel; |
Michalis Spyrou | bcfd09a | 2019-05-01 13:03:59 +0100 | [diff] [blame] | 104 | std::vector<CLScharr3x3> _func_scharr; |
| 105 | std::vector<CLTensor> _scharr_gx; |
| 106 | std::vector<CLTensor> _scharr_gy; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 107 | const ICLKeyPointArray *_old_points; |
| 108 | const ICLKeyPointArray *_new_points_estimates; |
| 109 | ICLKeyPointArray *_new_points; |
| 110 | std::unique_ptr<CLLKInternalKeypointArray> _old_points_internal; |
| 111 | std::unique_ptr<CLLKInternalKeypointArray> _new_points_internal; |
| 112 | std::unique_ptr<CLCoefficientTableArray> _coefficient_table; |
| 113 | std::unique_ptr<CLOldValueArray> _old_values; |
| 114 | size_t _num_levels; |
| 115 | }; |
| 116 | } |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 117 | #endif /*ARM_COMPUTE_CLOPTICALFLOW_H */ |