blob: f370dd29ab89ac08e5fa2e84b4c46c003a7d4028 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouebcebf12020-10-21 00:04:14 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEHOGMULTIDETECTION_H
25#define ARM_COMPUTE_NEHOGMULTIDETECTION_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CPP/kernels/CPPDetectionWindowNonMaximaSuppressionKernel.h"
28#include "arm_compute/core/IArray.h"
29#include "arm_compute/core/IMultiHOG.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010031#include "arm_compute/runtime/IMemoryManager.h"
32#include "arm_compute/runtime/MemoryGroup.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033#include "arm_compute/runtime/NEON/functions/NEHOGDetector.h"
34#include "arm_compute/runtime/NEON/functions/NEHOGGradient.h"
35#include "arm_compute/runtime/Tensor.h"
36
Georgios Pinitas658039b2017-09-15 16:30:50 +010037#include <memory>
38
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039namespace arm_compute
40{
Michalis Spyrouebcebf12020-10-21 00:04:14 +010041class NEHOGOrientationBinningKernel;
42class NEHOGBlockNormalizationKernel;
43
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044/** Basic function to detect multiple objects (or the same object at different scales) on the same input image using HOG. This function calls the following NEON kernels:
45 *
46 * -# @ref NEHOGGradient
47 * -# @ref NEHOGOrientationBinningKernel
48 * -# @ref NEHOGBlockNormalizationKernel
49 * -# @ref NEHOGDetector
50 * -# @ref CPPDetectionWindowNonMaximaSuppressionKernel (executed if non_maxima_suppression == true)
51 *
52 * @note This implementation works if all the HOG data-objects within the IMultiHOG container have the same:
53 * -# Phase type
54 -# Normalization type
55 -# L2 hysteresis threshold if the normalization type is L2HYS_NORM
56 *
morgolock0c862652020-11-06 08:59:45 +000057 * @deprecated This function is deprecated and is intended to be removed in 21.05 release
58 *
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 */
60class NEHOGMultiDetection : public IFunction
61{
62public:
63 /** Default constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010064 NEHOGMultiDetection(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065 /** Prevent instances of this class from being copied (As this class contains pointers) */
66 NEHOGMultiDetection(const NEHOGMultiDetection &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +000067 /** Prevent instances of this class from being moved (As this class contains pointers) */
68 NEHOGMultiDetection(NEHOGMultiDetection &&) = delete;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010069 /** Prevent instances of this class from being copied (As this class contains pointers) */
70 NEHOGMultiDetection &operator=(const NEHOGMultiDetection &) = delete;
Michalis Spyrou770dfeb2020-11-04 18:55:34 +000071 /** Prevent instances of this class from being moved (As this class contains pointers) */
72 NEHOGMultiDetection &operator=(NEHOGMultiDetection &&) = delete;
Michalis Spyrouebcebf12020-10-21 00:04:14 +010073 /** Default destructor */
74 ~NEHOGMultiDetection();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 /** Initialise the function's source, destination, detection window strides, border mode, threshold and non-maxima suppression
76 *
77 * @param[in, out] input Input tensor. Data type supported: U8
78 * (Written to only for @p border_mode != UNDEFINED)
79 * @param[in] multi_hog Container of multiple HOG data object. Each HOG data object describes one HOG model to detect.
80 * This container should store the HOG data-objects in descending or ascending cell_size width order.
81 * This will help to understand if the HOG descriptor computation can be skipped for some HOG data-objects
82 * @param[out] detection_windows Array of @ref DetectionWindow used for locating the detected objects
83 * @param[in] detection_window_strides Array of @ref Size2D used to specify the distance in pixels between 2 consecutive detection windows in x and y directions for each HOG data-object
84 * The dimension of this array must be the same of multi_hog->num_models()
85 * The i-th detection_window_stride of this array must be multiple of the block_stride stored in the i-th multi_hog array
86 * @param[in] border_mode Border mode to use.
87 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
88 * @param[in] threshold (Optional) Threshold for the distance between features and SVM classifying plane
89 * @param[in] non_maxima_suppression (Optional) Flag to specify whether the non-maxima suppression is required or not.
90 * True if the non-maxima suppression stage has to be computed
91 * @param[in] min_distance (Optional) Radial Euclidean distance to use for the non-maxima suppression stage
92 *
93 */
94 void configure(ITensor *input, const IMultiHOG *multi_hog, IDetectionWindowArray *detection_windows, const ISize2DArray *detection_window_strides, BorderMode border_mode,
95 uint8_t constant_border_value = 0,
96 float threshold = 0.0f, bool non_maxima_suppression = false, float min_distance = 1.0f);
97
98 // Inherited method overridden:
99 void run() override;
100
101private:
Georgios Pinitas725b1732019-05-20 19:40:47 +0100102 MemoryGroup _memory_group;
103 NEHOGGradient _gradient_kernel;
104 std::vector<NEHOGOrientationBinningKernel> _orient_bin_kernel;
105 std::vector<NEHOGBlockNormalizationKernel> _block_norm_kernel;
106 std::vector<NEHOGDetector> _hog_detect_kernel;
107 CPPDetectionWindowNonMaximaSuppressionKernel _non_maxima_kernel;
108 std::vector<Tensor> _hog_space;
109 std::vector<Tensor> _hog_norm_space;
110 IDetectionWindowArray *_detection_windows;
111 Tensor _mag;
112 Tensor _phase;
113 bool _non_maxima_suppression;
114 size_t _num_orient_bin_kernel;
115 size_t _num_block_norm_kernel;
116 size_t _num_hog_detect_kernel;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100117};
Georgios Pinitas725b1732019-05-20 19:40:47 +0100118} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000119#endif /* ARM_COMPUTE_NEHOGMULTIDETECTION_H */