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_CLOPTICALFLOW_H 25 #define ARM_COMPUTE_CLOPTICALFLOW_H 26 27 #include "arm_compute/core/IArray.h" 28 #include "arm_compute/core/Types.h" 29 #include "arm_compute/runtime/CL/CLArray.h" 30 #include "arm_compute/runtime/CL/CLTensor.h" 31 #include "arm_compute/runtime/CL/functions/CLScharr3x3.h" 32 #include "arm_compute/runtime/IFunction.h" 33 #include "arm_compute/runtime/IMemoryManager.h" 34 #include "arm_compute/runtime/MemoryGroup.h" 35 36 #include <cstddef> 37 #include <cstdint> 38 #include <memory> 39 40 namespace arm_compute 41 { 42 class CLCompileContext; 43 class CLPyramid; 44 class CLLKTrackerInitKernel; 45 class CLLKTrackerStage0Kernel; 46 class CLLKTrackerStage1Kernel; 47 class CLLKTrackerFinalizeKernel; 48 49 /** OpenCL Array of Internal Keypoints */ 50 using CLLKInternalKeypointArray = CLArray<CLLKInternalKeypoint>; 51 /** OpenCL Array of Coefficient Tables */ 52 using CLCoefficientTableArray = CLArray<CLCoefficientTable>; 53 /** OpenCL Array of Old Values */ 54 using CLOldValueArray = CLArray<CLOldValue>; 55 56 /** Basic function to execute optical flow. This function calls the following OpenCL kernels and functions: 57 * 58 * -# @ref CLScharr3x3 59 * -# @ref CLLKTrackerInitKernel 60 * -# @ref CLLKTrackerStage0Kernel 61 * -# @ref CLLKTrackerStage1Kernel 62 * -# @ref CLLKTrackerFinalizeKernel 63 * 64 * @deprecated This function is deprecated and is intended to be removed in 21.05 release 65 * 66 */ 67 class CLOpticalFlow : public IFunction 68 { 69 public: 70 /** Default constructor */ 71 CLOpticalFlow(std::shared_ptr<IMemoryManager> memory_manager = nullptr); 72 /** Prevent instances of this class from being copied (As this class contains pointers) */ 73 CLOpticalFlow(const CLOpticalFlow &) = delete; 74 /** Prevent instances of this class from being copied (As this class contains pointers) */ 75 CLOpticalFlow &operator=(const CLOpticalFlow &) = delete; 76 /** Allow instances of this class to be moved */ 77 CLOpticalFlow(CLOpticalFlow &&) = default; 78 /** Allow instances of this class to be moved */ 79 CLOpticalFlow &operator=(CLOpticalFlow &&) = default; 80 /** Default destructor */ 81 ~CLOpticalFlow(); 82 /** Initialise the function input and output 83 * 84 * @param[in] old_pyramid Pointer to the pyramid for the old tensor. Data types supported U8 85 * @param[in] new_pyramid Pointer to the pyramid for the new tensor. Data types supported U8 86 * @param[in] old_points Pointer to the IKeyPointArray storing old key points 87 * @param[in] new_points_estimates Pointer to the IKeyPointArray storing new estimates key points 88 * @param[out] new_points Pointer to the IKeyPointArray storing new key points 89 * @param[in] termination The criteria to terminate the search of each keypoint. 90 * @param[in] epsilon The error for terminating the algorithm 91 * @param[in] num_iterations The maximum number of iterations before terminate the alogrithm 92 * @param[in] window_dimension The size of the window on which to perform the algorithm 93 * @param[in] use_initial_estimate The flag to indicate whether the initial estimated position should be used 94 * @param[in] border_mode The border mode applied at scharr kernel stage 95 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT 96 * 97 */ 98 void configure(const CLPyramid *old_pyramid, const CLPyramid *new_pyramid, 99 const ICLKeyPointArray *old_points, const ICLKeyPointArray *new_points_estimates, ICLKeyPointArray *new_points, 100 Termination termination, float epsilon, size_t num_iterations, size_t window_dimension, bool use_initial_estimate, 101 BorderMode border_mode, uint8_t constant_border_value = 0); 102 /** Initialise the function input and output 103 * 104 * @param[in] compile_context The compile context to be used. 105 * @param[in] old_pyramid Pointer to the pyramid for the old tensor. Data types supported U8 106 * @param[in] new_pyramid Pointer to the pyramid for the new tensor. Data types supported U8 107 * @param[in] old_points Pointer to the IKeyPointArray storing old key points 108 * @param[in] new_points_estimates Pointer to the IKeyPointArray storing new estimates key points 109 * @param[out] new_points Pointer to the IKeyPointArray storing new key points 110 * @param[in] termination The criteria to terminate the search of each keypoint. 111 * @param[in] epsilon The error for terminating the algorithm 112 * @param[in] num_iterations The maximum number of iterations before terminate the alogrithm 113 * @param[in] window_dimension The size of the window on which to perform the algorithm 114 * @param[in] use_initial_estimate The flag to indicate whether the initial estimated position should be used 115 * @param[in] border_mode The border mode applied at scharr kernel stage 116 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT 117 * 118 */ 119 void configure(const CLCompileContext &compile_context, const CLPyramid *old_pyramid, const CLPyramid *new_pyramid, 120 const ICLKeyPointArray *old_points, const ICLKeyPointArray *new_points_estimates, ICLKeyPointArray *new_points, 121 Termination termination, float epsilon, size_t num_iterations, size_t window_dimension, bool use_initial_estimate, 122 BorderMode border_mode, uint8_t constant_border_value = 0); 123 124 // Inherited methods overridden: 125 void run() override; 126 127 private: 128 MemoryGroup _memory_group; 129 std::vector<std::unique_ptr<CLLKTrackerInitKernel>> _tracker_init_kernel; 130 std::vector<std::unique_ptr<CLLKTrackerStage0Kernel>> _tracker_stage0_kernel; 131 std::vector<std::unique_ptr<CLLKTrackerStage1Kernel>> _tracker_stage1_kernel; 132 std::unique_ptr<CLLKTrackerFinalizeKernel> _tracker_finalize_kernel; 133 std::vector<CLScharr3x3> _func_scharr; 134 std::vector<CLTensor> _scharr_gx; 135 std::vector<CLTensor> _scharr_gy; 136 const ICLKeyPointArray *_old_points; 137 const ICLKeyPointArray *_new_points_estimates; 138 ICLKeyPointArray *_new_points; 139 std::unique_ptr<CLLKInternalKeypointArray> _old_points_internal; 140 std::unique_ptr<CLLKInternalKeypointArray> _new_points_internal; 141 std::unique_ptr<CLCoefficientTableArray> _coefficient_table; 142 std::unique_ptr<CLOldValueArray> _old_values; 143 size_t _num_levels; 144 }; 145 } 146 #endif /*ARM_COMPUTE_CLOPTICALFLOW_H */ 147