Compute Library
 21.02
NEOpticalFlow Class Reference

Basic function to execute optical flow. More...

#include <NEOpticalFlow.h>

Collaboration diagram for NEOpticalFlow:
[legend]

Public Member Functions

 NEOpticalFlow (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Constructor. More...
 
 NEOpticalFlow (const NEOpticalFlow &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEOpticalFlowoperator= (const NEOpticalFlow &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ~NEOpticalFlow ()
 Default destructor. More...
 
void configure (const Pyramid *old_pyramid, const Pyramid *new_pyramid, const IKeyPointArray *old_points, const IKeyPointArray *new_points_estimates, IKeyPointArray *new_points, Termination termination, float epsilon, unsigned int num_iterations, size_t window_dimension, bool use_initial_estimate, BorderMode border_mode, uint8_t constant_border_value=0)
 Initialise the function input and output. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Detailed Description

Basic function to execute optical flow.

This function calls the following Neon kernels and functions:

  1. NEScharr3x3
  2. NELKTrackerKernel
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 57 of file NEOpticalFlow.h.

Constructor & Destructor Documentation

◆ NEOpticalFlow() [1/2]

NEOpticalFlow ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Constructor.

Parameters
[in]memory_manager(Optional) Memory manager.

Definition at line 42 of file NEOpticalFlow.cpp.

43  : _memory_group(std::move(memory_manager)),
44  _func_scharr(),
45  _kernel_tracker(),
46  _scharr_gx(),
47  _scharr_gy(),
48  _new_points(nullptr),
49  _new_points_estimates(nullptr),
50  _old_points(nullptr),
51  _new_points_internal(),
52  _old_points_internal(),
53  _num_levels(0)
54 {
55 }

◆ NEOpticalFlow() [2/2]

NEOpticalFlow ( const NEOpticalFlow )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ ~NEOpticalFlow()

~NEOpticalFlow ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const Pyramid old_pyramid,
const Pyramid new_pyramid,
const IKeyPointArray old_points,
const IKeyPointArray new_points_estimates,
IKeyPointArray new_points,
Termination  termination,
float  epsilon,
unsigned int  num_iterations,
size_t  window_dimension,
bool  use_initial_estimate,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 
)

Initialise the function input and output.

Parameters
[in]old_pyramidPointer to the pyramid for the old tensor. Data type supported U8
[in]new_pyramidPointer to the pyramid for the new tensor. Data type supported U8
[in]old_pointsPointer to the IKeyPointArray storing old key points
[in]new_points_estimatesPointer to the IKeyPointArray storing new estimates key points
[out]new_pointsPointer to the IKeyPointArray storing new key points
[in]terminationThe criteria to terminate the search of each keypoint.
[in]epsilonThe error for terminating the algorithm
[in]num_iterationsThe maximum number of iterations before terminate the alogrithm
[in]window_dimensionThe size of the window on which to perform the algorithm
[in]use_initial_estimateThe flag to indicate whether the initial estimated position should be used
[in]border_modeThe border mode applied at scharr kernel stage
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT

Definition at line 57 of file NEOpticalFlow.cpp.

References ARM_COMPUTE_ERROR_ON, ITensorInfo::dimension(), Pyramid::get_pyramid_level(), PyramidInfo::height(), ITensor::info(), Pyramid::info(), MemoryGroup::manage(), PyramidInfo::num_levels(), IArray< T >::num_values(), IArray< T >::resize(), arm_compute::S16, PyramidInfo::scale(), and PyramidInfo::width().

60 {
61  ARM_COMPUTE_ERROR_ON(nullptr == old_pyramid);
62  ARM_COMPUTE_ERROR_ON(nullptr == new_pyramid);
63  ARM_COMPUTE_ERROR_ON(nullptr == old_points);
64  ARM_COMPUTE_ERROR_ON(nullptr == new_points_estimates);
65  ARM_COMPUTE_ERROR_ON(nullptr == new_points);
66  ARM_COMPUTE_ERROR_ON(old_pyramid->info()->num_levels() != new_pyramid->info()->num_levels());
67  ARM_COMPUTE_ERROR_ON(0 == old_pyramid->info()->num_levels());
68  ARM_COMPUTE_ERROR_ON(old_pyramid->info()->width() != new_pyramid->info()->width());
69  ARM_COMPUTE_ERROR_ON(old_pyramid->info()->height() != new_pyramid->info()->height());
70  ARM_COMPUTE_ERROR_ON(use_initial_estimate && old_points->num_values() != new_points_estimates->num_values());
71 
72  _num_levels = old_pyramid->info()->num_levels();
73  _old_points = old_points;
74  _new_points = new_points;
75  _new_points_estimates = new_points_estimates;
76 
77  const float pyr_scale = old_pyramid->info()->scale();
78 
79  _func_scharr.clear();
80  _kernel_tracker.clear();
81  _scharr_gx.clear();
82  _scharr_gy.clear();
83 
84  _func_scharr.resize(_num_levels);
85  _kernel_tracker.resize(_num_levels);
86  _scharr_gx.resize(_num_levels);
87  _scharr_gy.resize(_num_levels);
88 
89  _old_points_internal = LKInternalKeypointArray(old_points->num_values());
90  _new_points_internal = LKInternalKeypointArray(old_points->num_values());
91  _new_points->resize(old_points->num_values());
92 
93  for(unsigned int i = 0; i < _num_levels; ++i)
94  {
95  // Get images from the ith level of old and right pyramid
96  IImage *old_ith_input = old_pyramid->get_pyramid_level(i);
97  IImage *new_ith_input = new_pyramid->get_pyramid_level(i);
98 
99  // Get width and height of images
100  const unsigned int width_ith = old_ith_input->info()->dimension(0);
101  const unsigned int height_ith = new_ith_input->info()->dimension(1);
102 
103  TensorInfo tensor_info(TensorShape(width_ith, height_ith), Format::S16);
104 
105  _scharr_gx[i].allocator()->init(tensor_info);
106  _scharr_gy[i].allocator()->init(tensor_info);
107 
108  // Manage intermediate buffers
109  _memory_group.manage(&_scharr_gx[i]);
110  _memory_group.manage(&_scharr_gy[i]);
111 
112  // Init Scharr kernel
113  _func_scharr[i].configure(old_ith_input, &_scharr_gx[i], &_scharr_gy[i], border_mode, constant_border_value);
114 
115  // Init Lucas-Kanade kernel
116  _kernel_tracker[i] = std::make_unique<NELKTrackerKernel>();
117  _kernel_tracker[i]->configure(old_ith_input, new_ith_input, &_scharr_gx[i], &_scharr_gy[i],
118  old_points, new_points_estimates, new_points,
119  &_old_points_internal, &_new_points_internal,
120  termination, use_initial_estimate, epsilon, num_iterations, window_dimension,
121  i, _num_levels, pyr_scale);
122 
123  _scharr_gx[i].allocator()->allocate();
124  _scharr_gy[i].allocator()->allocate();
125  }
126 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
void resize(size_t num)
Resizes the array to contain "num" elements.
Definition: IArray.h:128
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
1 channel, 1 S16 per channel
ITensor IImage
Interface for CPP Images.
Array< NELKInternalKeypoint > LKInternalKeypointArray
Array of LK Internel Keypoints.
Definition: NEOpticalFlow.h:47

◆ operator=()

NEOpticalFlow& operator= ( const NEOpticalFlow )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For Neon kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 128 of file NEOpticalFlow.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, Window::DimX, Scheduler::get(), GemmTuner::level, and IScheduler::schedule().

129 {
130  ARM_COMPUTE_ERROR_ON_MSG(_num_levels == 0, "Unconfigured function");
131 
132  MemoryGroupResourceScope scope_mg(_memory_group);
133 
134  for(unsigned int level = _num_levels; level > 0; --level)
135  {
136  // Run Scharr kernel
137  _func_scharr[level - 1].run();
138 
139  // Run Lucas-Kanade kernel
140  NEScheduler::get().schedule(_kernel_tracker[level - 1].get(), Window::DimX);
141  }
142 }
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

The documentation for this class was generated from the following files: