Compute Library
 21.02
CLFastCorners Class Reference

Basic function to execute fast corners. More...

#include <CLFastCorners.h>

Collaboration diagram for CLFastCorners:
[legend]

Public Member Functions

 CLFastCorners (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Constructor. More...
 
 CLFastCorners (const CLFastCorners &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
const CLFastCornersoperator= (const CLFastCorners &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ~CLFastCorners ()
 Default destructor. More...
 
void configure (const ICLImage *input, float threshold, bool nonmax_suppression, ICLKeyPointArray *corners, unsigned int *num_corners, BorderMode border_mode, uint8_t constant_border_value=0)
 Initialize the function's source, destination, conv and border_mode. More...
 
void configure (const CLCompileContext &compile_context, const ICLImage *input, float threshold, bool nonmax_suppression, ICLKeyPointArray *corners, unsigned int *num_corners, BorderMode border_mode, uint8_t constant_border_value=0)
 Initialize the function's source, destination, conv and border_mode. 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 fast corners.

This function calls the following CL kernels:

  1. CLFastCornersKernel
  2. CLNonMaximaSuppression3x3Kernel (executed if nonmax_suppression == true)
  3. CLCopyToArrayKernel
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 56 of file CLFastCorners.h.

Constructor & Destructor Documentation

◆ CLFastCorners() [1/2]

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

Constructor.

Definition at line 40 of file CLFastCorners.cpp.

41  : _memory_group(std::move(memory_manager)),
42  _fast_corners_kernel(std::make_unique<CLFastCornersKernel>()),
43  _suppr_func(),
44  _copy_array_kernel(std::make_unique<CLCopyToArrayKernel>()),
45  _output(),
46  _suppr(),
47  _win(),
48  _non_max(false),
49  _num_corners(nullptr),
50  _num_buffer(),
51  _corners(nullptr),
52  _constant_border_value(0)
53 {
54 }

◆ CLFastCorners() [2/2]

CLFastCorners ( const CLFastCorners )
delete

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

◆ ~CLFastCorners()

~CLFastCorners ( )
default

Default destructor.

Member Function Documentation

◆ configure() [1/2]

void configure ( const ICLImage input,
float  threshold,
bool  nonmax_suppression,
ICLKeyPointArray corners,
unsigned int *  num_corners,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 
)

Initialize the function's source, destination, conv and border_mode.

Parameters
[in]inputSource image. Data types supported: U8.
[in]thresholdThreshold on difference between intensity of the central pixel and pixels on Bresenham's circle of radius 3.
[in]nonmax_suppressionIf true, non-maximum suppression is applied to detected corners before being placed in the array.
[out]cornersArray of keypoints to store the results.
[in,out]num_cornersRecord number of corners in the array
[in]border_modeStrategy to use for borders.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 58 of file CLFastCorners.cpp.

References CLKernelLibrary::get().

60 {
61  configure(CLKernelLibrary::get().get_compile_context(), input, threshold, nonmax_suppression, corners, num_corners, border_mode, constant_border_value);
62 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(const ICLImage *input, float threshold, bool nonmax_suppression, ICLKeyPointArray *corners, unsigned int *num_corners, BorderMode border_mode, uint8_t constant_border_value=0)
Initialize the function&#39;s source, destination, conv and border_mode.
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
const ICLImage input,
float  threshold,
bool  nonmax_suppression,
ICLKeyPointArray corners,
unsigned int *  num_corners,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 
)

Initialize the function's source, destination, conv and border_mode.

Parameters
[in]compile_contextThe compile context to be used.
[in]inputSource image. Data types supported: U8.
[in]thresholdThreshold on difference between intensity of the central pixel and pixels on Bresenham's circle of radius 3.
[in]nonmax_suppressionIf true, non-maximum suppression is applied to detected corners before being placed in the array.
[out]cornersArray of keypoints to store the results.
[in,out]num_cornersRecord number of corners in the array
[in]border_modeStrategy to use for borders.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 64 of file CLFastCorners.cpp.

References CLTensorAllocator::allocate(), CLTensor::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, CLNonMaximaSuppression3x3::configure(), CLScheduler::get(), ITensor::info(), ITensorAllocator::init(), MemoryGroup::manage(), ITensorInfo::tensor_shape(), arm_compute::U8, and arm_compute::UNDEFINED.

66 {
69  ARM_COMPUTE_ERROR_ON(nullptr == corners);
70  ARM_COMPUTE_ERROR_ON(threshold < 1 && threshold > 255);
71 
72  TensorInfo tensor_info(input->info()->tensor_shape(), 1, DataType::U8);
73  _output.allocator()->init(tensor_info);
74 
75  _non_max = nonmax_suppression;
76  _num_corners = num_corners;
77  _corners = corners;
78  _num_buffer = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, sizeof(unsigned int));
79  _constant_border_value = constant_border_value;
80 
81  const bool update_number = (nullptr != _num_corners);
82 
83  _memory_group.manage(&_output);
84  _fast_corners_kernel->configure(compile_context, input, &_output, threshold, nonmax_suppression, border_mode);
85 
86  if(!_non_max)
87  {
88  _copy_array_kernel->configure(compile_context, &_output, update_number, _corners, &_num_buffer);
89  }
90  else
91  {
92  _suppr.allocator()->init(tensor_info);
93  _memory_group.manage(&_suppr);
94 
95  _suppr_func.configure(compile_context, &_output, &_suppr, border_mode);
96  _copy_array_kernel->configure(compile_context, &_suppr, update_number, _corners, &_num_buffer);
97 
98  _suppr.allocator()->allocate();
99  }
100 
101  // Allocate intermediate tensors
102  _output.allocator()->allocate();
103 }
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:856
static CLScheduler & get()
Access the scheduler singleton.
1 channel, 1 U8 per channel
#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
CLTensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: CLTensor.cpp:61
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void configure(ICLTensor *input, ICLTensor *output, BorderMode border_mode)
Initialise the function&#39;s source, destinations and border mode.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
Borders are left undefined.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35

◆ operator=()

const CLFastCorners& operator= ( const CLFastCorners )
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 105 of file CLFastCorners.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, CLTensor::cl_buffer(), CLScheduler::enqueue(), CLScheduler::get(), CLTensor::info(), IArray< T >::max_num_values(), CLScheduler::queue(), IArray< T >::resize(), ICLSimpleFunction::run(), and TensorInfo::total_size().

106 {
107  cl::CommandQueue q = CLScheduler::get().queue();
108 
109  MemoryGroupResourceScope scope_mg(_memory_group);
110 
111  if(_non_max)
112  {
113  ARM_COMPUTE_ERROR_ON_MSG(_output.cl_buffer().get() == nullptr, "Unconfigured function");
114  const auto out_buffer = static_cast<unsigned char *>(q.enqueueMapBuffer(_output.cl_buffer(), CL_TRUE, CL_MAP_WRITE, 0, _output.info()->total_size()));
115  memset(out_buffer, 0, _output.info()->total_size());
116  q.enqueueUnmapMemObject(_output.cl_buffer(), out_buffer);
117  }
118 
119  CLScheduler::get().enqueue(*_fast_corners_kernel, false);
120 
121  if(_non_max)
122  {
123  _suppr_func.run();
124  }
125 
126  CLScheduler::get().enqueue(*_copy_array_kernel, false);
127 
128  unsigned int get_num_corners = 0;
129  q.enqueueReadBuffer(_num_buffer, CL_TRUE, 0, sizeof(unsigned int), &get_num_corners);
130 
131  size_t corner_size = std::min(static_cast<size_t>(get_num_corners), _corners->max_num_values());
132 
133  _corners->resize(corner_size);
134 
135  if(_num_corners != nullptr)
136  {
137  *_num_corners = get_num_corners;
138  }
139 
140  q.flush();
141 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
static CLScheduler & get()
Access the scheduler singleton.
const cl::Buffer & cl_buffer() const override
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
Definition: CLTensor.cpp:51
void resize(size_t num)
Resizes the array to contain "num" elements.
Definition: IArray.h:128
void run() override final
Run the kernels contained in the function.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
size_t total_size() const override
Returns the total size of the tensor in bytes.
Definition: TensorInfo.h:278
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:41
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:58

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