Compute Library
 19.08
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...
 
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 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

Definition at line 53 of file CLFastCorners.h.

Constructor & Destructor Documentation

◆ CLFastCorners() [1/2]

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

Constructor.

Definition at line 39 of file CLFastCorners.cpp.

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

◆ CLFastCorners() [2/2]

CLFastCorners ( const CLFastCorners )
delete

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

Member Function Documentation

◆ configure()

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 55 of file CLFastCorners.cpp.

57 {
60  ARM_COMPUTE_ERROR_ON(nullptr == corners);
61  ARM_COMPUTE_ERROR_ON(threshold < 1 && threshold > 255);
62 
63  TensorInfo tensor_info(input->info()->tensor_shape(), 1, DataType::U8);
64  _output.allocator()->init(tensor_info);
65 
66  _non_max = nonmax_suppression;
67  _num_corners = num_corners;
68  _corners = corners;
69  _num_buffer = cl::Buffer(CLScheduler::get().context(), CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE, sizeof(unsigned int));
70  _constant_border_value = constant_border_value;
71 
72  const bool update_number = (nullptr != _num_corners);
73 
74  _memory_group.manage(&_output);
75  _fast_corners_kernel.configure(input, &_output, threshold, nonmax_suppression, border_mode);
76 
77  if(!_non_max)
78  {
79  _copy_array_kernel.configure(&_output, update_number, _corners, &_num_buffer);
80  }
81  else
82  {
83  _suppr.allocator()->init(tensor_info);
84  _memory_group.manage(&_suppr);
85 
86  _suppr_func.configure(&_output, &_suppr, border_mode);
87  _copy_array_kernel.configure(&_suppr, update_number, _corners, &_num_buffer);
88 
89  _suppr.allocator()->allocate();
90  }
91 
92  // Allocate intermediate tensors
93  _output.allocator()->allocate();
94 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
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:337
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:55
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:855
void manage(TensorType *obj)
Sets a object to be managed by the given memory group.
void configure(ICLTensor *input, ICLTensor *output, BorderMode border_mode)
Initialise the function's source, destinations and border mode.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void configure(const ICLImage *input, bool update_number, ICLKeyPointArray *corners, cl::Buffer *num_buffers)
Initialise the kernel.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
void configure(const ICLImage *input, ICLImage *output, float threshold, bool non_max_suppression, BorderMode border_mode)
Initialise the kernel.
Borders are left undefined.
Store the tensor'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

References CLTensorAllocator::allocate(), CLTensor::allocator(), ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, arm_compute::test::validation::border_mode, CLNonMaximaSuppression3x3::configure(), CLFastCornersKernel::configure(), CLCopyToArrayKernel::configure(), CLScheduler::get(), ITensor::info(), ITensorAllocator::init(), MemoryGroupBase< TensorType >::manage(), ITensorInfo::tensor_shape(), arm_compute::test::validation::reference::threshold(), arm_compute::U8, and arm_compute::UNDEFINED.

◆ 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 96 of file CLFastCorners.cpp.

97 {
98  cl::CommandQueue q = CLScheduler::get().queue();
99 
100  MemoryGroupResourceScope scope_mg(_memory_group);
101 
102  if(_non_max)
103  {
104  ARM_COMPUTE_ERROR_ON_MSG(_output.cl_buffer().get() == nullptr, "Unconfigured function");
105  const auto out_buffer = static_cast<unsigned char *>(q.enqueueMapBuffer(_output.cl_buffer(), CL_TRUE, CL_MAP_WRITE, 0, _output.info()->total_size()));
106  memset(out_buffer, 0, _output.info()->total_size());
107  q.enqueueUnmapMemObject(_output.cl_buffer(), out_buffer);
108  }
109 
110  CLScheduler::get().enqueue(_fast_corners_kernel, false);
111 
112  if(_non_max)
113  {
114  _suppr_func.run();
115  }
116 
117  CLScheduler::get().enqueue(_copy_array_kernel, false);
118 
119  unsigned int get_num_corners = 0;
120  q.enqueueReadBuffer(_num_buffer, CL_TRUE, 0, sizeof(unsigned int), &get_num_corners);
121 
122  size_t corner_size = std::min(static_cast<size_t>(get_num_corners), _corners->max_num_values());
123 
124  _corners->resize(corner_size);
125 
126  if(_num_corners != nullptr)
127  {
128  *_num_corners = get_num_corners;
129  }
130 
131  q.flush();
132 }
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLTensor.cpp:35
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
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:45
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.
size_t total_size() const override
Returns the total size of the tensor in bytes.
Definition: TensorInfo.h:264
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: CLScheduler.cpp:95
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.h:102
Memory group resources scope handling class.
Definition: IMemoryGroup.h:46
size_t max_num_values() const
Maximum number of values which can be stored in this array.
Definition: IArray.h:58
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328

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().


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