Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 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 | */ |
| 24 | #ifndef __ARM_COMPUTE_NEOPTICALFLOW_H__ |
| 25 | #define __ARM_COMPUTE_NEOPTICALFLOW_H__ |
| 26 | |
| 27 | #include "arm_compute/core/IArray.h" |
| 28 | #include "arm_compute/core/NEON/kernels/NELKTrackerKernel.h" |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | #include "arm_compute/runtime/Array.h" |
| 31 | #include "arm_compute/runtime/IFunction.h" |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/IMemoryManager.h" |
| 33 | #include "arm_compute/runtime/MemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/NEON/functions/NEScharr3x3.h" |
| 35 | #include "arm_compute/runtime/Tensor.h" |
| 36 | |
| 37 | #include <cstddef> |
| 38 | #include <cstdint> |
| 39 | #include <memory> |
| 40 | |
| 41 | namespace arm_compute |
| 42 | { |
| 43 | class Pyramid; |
| 44 | |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 45 | /** Array of LK Internel Keypoints */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 46 | using LKInternalKeypointArray = Array<NELKInternalKeypoint>; |
| 47 | /** Basic function to execute optical flow. This function calls the following NEON kernels and functions: |
| 48 | * |
| 49 | * -# @ref NEScharr3x3 |
| 50 | * -# @ref NELKTrackerKernel |
| 51 | * |
| 52 | */ |
| 53 | class NEOpticalFlow : public IFunction |
| 54 | { |
| 55 | public: |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 56 | /** Constructor |
| 57 | * |
| 58 | * @param[in] memory_manager (Optional) Memory manager. |
| 59 | */ |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 60 | NEOpticalFlow(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 62 | NEOpticalFlow(const NEOpticalFlow &) = delete; |
| 63 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 64 | NEOpticalFlow &operator=(const NEOpticalFlow &) = delete; |
| 65 | /** Initialise the function input and output |
| 66 | * |
| 67 | * @param[in] old_pyramid Pointer to the pyramid for the old tensor. Data type supported U8 |
| 68 | * @param[in] new_pyramid Pointer to the pyramid for the new tensor. Data type supported U8 |
| 69 | * @param[in] old_points Pointer to the IKeyPointArray storing old key points |
| 70 | * @param[in] new_points_estimates Pointer to the IKeyPointArray storing new estimates key points |
| 71 | * @param[out] new_points Pointer to the IKeyPointArray storing new key points |
| 72 | * @param[in] termination The criteria to terminate the search of each keypoint. |
| 73 | * @param[in] epsilon The error for terminating the algorithm |
| 74 | * @param[in] num_iterations The maximum number of iterations before terminate the alogrithm |
| 75 | * @param[in] window_dimension The size of the window on which to perform the algorithm |
| 76 | * @param[in] use_initial_estimate The flag to indicate whether the initial estimated position should be used |
| 77 | * @param[in] border_mode The border mode applied at scharr kernel stage |
| 78 | * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT |
| 79 | * |
| 80 | */ |
| 81 | void configure(const Pyramid *old_pyramid, const Pyramid *new_pyramid, const IKeyPointArray *old_points, const IKeyPointArray *new_points_estimates, |
| 82 | IKeyPointArray *new_points, Termination termination, float epsilon, unsigned int num_iterations, size_t window_dimension, |
| 83 | bool use_initial_estimate, BorderMode border_mode, uint8_t constant_border_value = 0); |
| 84 | |
| 85 | // Inherited methods overridden: |
| 86 | void run() override; |
| 87 | |
| 88 | private: |
Georgios Pinitas | 658039b | 2017-09-15 16:30:50 +0100 | [diff] [blame] | 89 | MemoryGroup _memory_group; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 90 | std::unique_ptr<NEScharr3x3[]> _func_scharr; |
| 91 | std::unique_ptr<NELKTrackerKernel[]> _kernel_tracker; |
| 92 | std::unique_ptr<Tensor[]> _scharr_gx; |
| 93 | std::unique_ptr<Tensor[]> _scharr_gy; |
| 94 | IKeyPointArray *_new_points; |
| 95 | const IKeyPointArray *_new_points_estimates; |
| 96 | const IKeyPointArray *_old_points; |
| 97 | LKInternalKeypointArray _new_points_internal; |
| 98 | LKInternalKeypointArray _old_points_internal; |
| 99 | unsigned int _num_levels; |
| 100 | }; |
| 101 | } |
| 102 | #endif /*__ARM_COMPUTE_NEOPTICALFLOW_H__ */ |