Compute Library
 21.02
NEHarrisCorners Class Reference

Basic function to execute harris corners detection. More...

#include <NEHarrisCorners.h>

Collaboration diagram for NEHarrisCorners:
[legend]

Public Member Functions

 NEHarrisCorners (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Constructor. More...
 
 NEHarrisCorners (const NEHarrisCorners &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEHarrisCornersoperator= (const NEHarrisCorners &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEHarrisCorners (NEHarrisCorners &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
NEHarrisCornersoperator= (NEHarrisCorners &&)=delete
 Prevent instances of this class from being moved (As this class contains non movable objects) More...
 
 ~NEHarrisCorners ()
 Default destructor. More...
 
void configure (IImage *input, float threshold, float min_dist, float sensitivity, int32_t gradient_size, int32_t block_size, KeyPointArray *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 harris corners detection.

This function calls the following Neon kernels and functions:

  1. NESobel3x3 (if gradient_size == 3) or
    NESobel5x5 (if gradient_size == 5) or
    NESobel7x7 (if gradient_size == 7)
  2. NEFillBorderKernel
  3. NEHarrisScoreKernel<3> (if block_size == 3) or
    NEHarrisScoreKernel<5> (if block_size == 5) or
    NEHarrisScoreKernel<7> (if block_size == 7)
  4. NENonMaximaSuppression3x3
  5. CPPCornerCandidatesKernel
  6. CPPSortEuclideanDistanceKernel
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 63 of file NEHarrisCorners.h.

Constructor & Destructor Documentation

◆ NEHarrisCorners() [1/3]

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

Constructor.

Initialize _sobel, _harris_score and _corner_list to nullptr.

Parameters
[in]memory_manager(Optional) Memory manager.

Definition at line 48 of file NEHarrisCorners.cpp.

49  : _memory_group(std::move(memory_manager)),
50  _sobel(),
51  _harris_score(),
52  _non_max_suppr(),
53  _candidates(),
54  _sort_euclidean(),
55  _border_gx(),
56  _border_gy(),
57  _gx(),
58  _gy(),
59  _score(),
60  _nonmax(),
61  _corners_list(),
62  _num_corner_candidates(0)
63 {
64 }

◆ NEHarrisCorners() [2/3]

NEHarrisCorners ( const NEHarrisCorners )
delete

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

◆ NEHarrisCorners() [3/3]

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ ~NEHarrisCorners()

~NEHarrisCorners ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( IImage input,
float  threshold,
float  min_dist,
float  sensitivity,
int32_t  gradient_size,
int32_t  block_size,
KeyPointArray corners,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 
)

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

Parameters
[in,out]inputSource image. Data type supported: U8. (Written to only for border_mode != UNDEFINED)
[in]thresholdMinimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel).
[in]min_distRadial Euclidean distance for the euclidean diatance stage
[in]sensitivitySensitivity threshold k from the Harris-Stephens equation
[in]gradient_sizeThe gradient window size to use on the input. The implementation supports 3, 5, and 7
[in]block_sizeThe block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7.
[out]cornersArray of keypoints to store the results.
[in]border_modeBorder mode to use
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 66 of file NEHarrisCorners.cpp.

References TensorAllocator::allocate(), Tensor::allocator(), ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D, NENonMaximaSuppression3x3::configure(), CPPSortEuclideanDistanceKernel::configure(), CPPCornerCandidatesKernel::configure(), arm_compute::F32, ITensor::info(), TensorAllocator::init(), TensorInfo::init(), MemoryGroup::manage(), arm_compute::S16, arm_compute::S32, arm_compute::test::validation::shape, ITensorInfo::tensor_shape(), arm_compute::U8, arm_compute::UNDEFINED, Dimensions< T >::x(), and Dimensions< T >::y().

69 {
72  ARM_COMPUTE_ERROR_ON(!(block_size == 3 || block_size == 5 || block_size == 7));
73 
74  const TensorShape shape = input->info()->tensor_shape();
75  TensorInfo tensor_info_gxgy;
76 
77  if(gradient_size < 7)
78  {
79  tensor_info_gxgy.init(shape, Format::S16);
80  }
81  else
82  {
83  tensor_info_gxgy.init(shape, Format::S32);
84  }
85 
86  _gx.allocator()->init(tensor_info_gxgy);
87  _gy.allocator()->init(tensor_info_gxgy);
88 
89  // Manage intermediate buffers
90  _memory_group.manage(&_gx);
91  _memory_group.manage(&_gy);
92 
93  TensorInfo tensor_info_score(shape, Format::F32);
94  _score.allocator()->init(tensor_info_score);
95  _nonmax.allocator()->init(tensor_info_score);
96 
97  _corners_list.resize(shape.x() * shape.y());
98 
99  // Set/init Sobel kernel accordingly with gradient_size
100  switch(gradient_size)
101  {
102  case 3:
103  {
104  auto k = std::make_unique<NESobel3x3>();
105  k->configure(input, &_gx, &_gy, border_mode, constant_border_value);
106  _sobel = std::move(k);
107  break;
108  }
109  case 5:
110  {
111  auto k = std::make_unique<NESobel5x5>();
112  k->configure(input, &_gx, &_gy, border_mode, constant_border_value);
113  _sobel = std::move(k);
114  break;
115  }
116  case 7:
117  {
118  auto k = std::make_unique<NESobel7x7>();
119  k->configure(input, &_gx, &_gy, border_mode, constant_border_value);
120  _sobel = std::move(k);
121  break;
122  }
123  default:
124  ARM_COMPUTE_ERROR("Gradient size not implemented");
125  }
126 
127  // Normalization factor
128  const float norm_factor = 1.0f / (255.0f * pow(4.0f, gradient_size / 2) * block_size);
129 
130  // Manage intermediate buffers
131  _memory_group.manage(&_score);
132 
133  // Set/init Harris Score kernel accordingly with block_size
134  switch(block_size)
135  {
136  case 3:
137  {
138  auto k = std::make_unique<NEHarrisScoreKernel<3>>();
139  k->configure(&_gx, &_gy, &_score, norm_factor, threshold, sensitivity, border_mode == BorderMode::UNDEFINED);
140  _harris_score = std::move(k);
141  }
142  break;
143  case 5:
144  {
145  auto k = std::make_unique<NEHarrisScoreKernel<5>>();
146  k->configure(&_gx, &_gy, &_score, norm_factor, threshold, sensitivity, border_mode == BorderMode::UNDEFINED);
147  _harris_score = std::move(k);
148  }
149  break;
150  case 7:
151  {
152  auto k = std::make_unique<NEHarrisScoreKernel<7>>();
153  k->configure(&_gx, &_gy, &_score, norm_factor, threshold, sensitivity, border_mode == BorderMode::UNDEFINED);
154  _harris_score = std::move(k);
155  }
156  default:
157  break;
158  }
159 
160  // Configure border filling before harris score
161  _border_gx = std::make_unique<NEFillBorderKernel>();
162  _border_gy = std::make_unique<NEFillBorderKernel>();
163  _border_gx->configure(&_gx, _harris_score->border_size(), border_mode, constant_border_value);
164  _border_gy->configure(&_gy, _harris_score->border_size(), border_mode, constant_border_value);
165 
166  // Allocate once all the configure methods have been called
167  _gx.allocator()->allocate();
168  _gy.allocator()->allocate();
169 
170  // Manage intermediate buffers
171  _memory_group.manage(&_nonmax);
172 
173  // Init non-maxima suppression function
174  _non_max_suppr.configure(&_score, &_nonmax, border_mode);
175 
176  // Allocate once all the configure methods have been called
177  _score.allocator()->allocate();
178 
179  // Init corner candidates kernel
180  _candidates.configure(&_nonmax, _corners_list.data(), &_num_corner_candidates);
181 
182  // Allocate once all the configure methods have been called
183  _nonmax.allocator()->allocate();
184 
185  // Init euclidean distance
186  _sort_euclidean.configure(_corners_list.data(), corners, &_num_corner_candidates, min_dist);
187 }
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
#define ARM_COMPUTE_ERROR_ON_TENSOR_NOT_2D(t)
Definition: Validate.h:856
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 U8 per channel
1 channel, 1 F32 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
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
1 channel, 1 S32 per channel
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void configure(InternalKeypoint *in_out, IKeyPointArray *output, const int32_t *num_corner_candidates, float min_distance)
Initialise the kernel&#39;s source, destination and border mode.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
1 channel, 1 S16 per channel
void configure(ITensor *input, ITensor *output, BorderMode border_mode)
Initialise the function&#39;s source, destinations and border mode.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
Borders are left undefined.
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Definition: Threshold.cpp:35
void configure(const IImage *input, InternalKeypoint *output, int32_t *num_corner_candidates)
Setup the kernel parameters.

◆ operator=() [1/2]

NEHarrisCorners& operator= ( const NEHarrisCorners )
delete

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

◆ operator=() [2/2]

NEHarrisCorners& operator= ( NEHarrisCorners &&  )
delete

Prevent instances of this class from being moved (As this class contains non movable objects)

◆ 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 189 of file NEHarrisCorners.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, Window::DimY, Window::DimZ, Scheduler::get(), INESimpleFunction::run(), and IScheduler::schedule().

190 {
191  ARM_COMPUTE_ERROR_ON_MSG(_sobel == nullptr, "Unconfigured function");
192 
193  MemoryGroupResourceScope scope_mg(_memory_group);
194 
195  // Init to 0 number of corner candidates
196  _num_corner_candidates = 0;
197 
198  // Run Sobel kernel
199  _sobel->run();
200 
201  // Fill border before harris score kernel
202  NEScheduler::get().schedule(_border_gx.get(), Window::DimZ);
203  NEScheduler::get().schedule(_border_gy.get(), Window::DimZ);
204 
205  // Run harris score kernel
206  NEScheduler::get().schedule(_harris_score.get(), Window::DimY);
207 
208  // Run non-maxima suppression
209  _non_max_suppr.run();
210 
211  // Run corner candidate kernel
212  NEScheduler::get().schedule(&_candidates, Window::DimY);
213 
214  // Run sort & euclidean distance
215  NEScheduler::get().schedule(&_sort_euclidean, Window::DimY);
216 }
void run() override final
Run the kernels contained in the function.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:94

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