blob: b9a51653f28289af8d269f9097b5e4f20bdbdeff [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-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_CLHOGMULTIDETECTION_H
25#define ARM_COMPUTE_CLHOGMULTIDETECTION_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CL/ICLArray.h"
28#include "arm_compute/core/CL/ICLMultiHOG.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/CPP/kernels/CPPDetectionWindowNonMaximaSuppressionKernel.h"
30#include "arm_compute/runtime/CL/CLTensor.h"
31#include "arm_compute/runtime/CL/functions/CLHOGDetector.h"
32#include "arm_compute/runtime/CL/functions/CLHOGGradient.h"
33#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +010034#include "arm_compute/runtime/IMemoryManager.h"
Georgios Pinitas26014cf2019-09-09 19:00:57 +010035#include "arm_compute/runtime/MemoryGroup.h"
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +010036
37#include <memory>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038
39namespace arm_compute
40{
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010041class CLCompileContext;
42class CLHOGOrientationBinningKernel;
43class CLHOGBlockNormalizationKernel;
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 kernels:
45 *
46 * -# @ref CLHOGGradient
47 * -# @ref CLHOGOrientationBinningKernel
48 * -# @ref CLHOGBlockNormalizationKernel
49 * -# @ref CLHOGDetector
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 *
morgolock00c76012020-11-06 10:40:12 +000057 *
58 * @deprecated This function is deprecated and is intended to be removed in 21.05 release
59 *
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 */
61class CLHOGMultiDetection : public IFunction
62{
63public:
64 /** Default constructor */
Georgios Pinitas8a94e7c2017-09-15 19:06:47 +010065 CLHOGMultiDetection(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 /** Prevent instances of this class from being copied (As this class contains pointers) */
67 CLHOGMultiDetection(const CLHOGMultiDetection &) = delete;
68 /** Prevent instances of this class from being copied (As this class contains pointers) */
69 CLHOGMultiDetection &operator=(const CLHOGMultiDetection &) = delete;
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010070 /** Default destructor */
71 ~CLHOGMultiDetection();
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072 /** Initialise the function's source, destination, detection window strides, border mode, threshold and non-maxima suppression
73 *
74 * @param[in, out] input Input tensor. Data type supported: U8
75 * (Written to only for @p border_mode != UNDEFINED)
76 * @param[in] multi_hog Container of multiple HOG data object. Each HOG data object describes one HOG model to detect.
77 * This container should store the HOG data-objects in descending or ascending cell_size width order.
78 * This will help to understand if the HOG descriptor computation can be skipped for some HOG data-objects
79 * @param[out] detection_windows Array of @ref DetectionWindow used for locating the detected objects
80 * @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
81 * The dimension of this array must be the same of multi_hog->num_models()
82 * The i-th detection_window_stride of this array must be multiple of the block_stride stored in the i-th multi_hog array
83 * @param[in] border_mode Border mode to use.
84 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
85 * @param[in] threshold (Optional) Threshold for the distance between features and SVM classifying plane
86 * @param[in] non_maxima_suppression (Optional) Flag to specify whether the non-maxima suppression is required or not.
87 * True if the non-maxima suppression stage has to be computed
88 * @param[in] min_distance (Optional) Radial Euclidean distance to use for the non-maxima suppression stage
89 *
90 */
91 void configure(ICLTensor *input, const ICLMultiHOG *multi_hog, ICLDetectionWindowArray *detection_windows, ICLSize2DArray *detection_window_strides, BorderMode border_mode,
Manuel Bottini2b84be52020-04-08 10:15:51 +010092 uint8_t constant_border_value = 0, float threshold = 0.0f, bool non_maxima_suppression = false, float min_distance = 1.0f);
93 /** Initialise the function's source, destination, detection window strides, border mode, threshold and non-maxima suppression
94 *
95 * @param[in] compile_context The compile context to be used.
96 * @param[in, out] input Input tensor. Data type supported: U8
97 * (Written to only for @p border_mode != UNDEFINED)
98 * @param[in] multi_hog Container of multiple HOG data object. Each HOG data object describes one HOG model to detect.
99 * This container should store the HOG data-objects in descending or ascending cell_size width order.
100 * This will help to understand if the HOG descriptor computation can be skipped for some HOG data-objects
101 * @param[out] detection_windows Array of @ref DetectionWindow used for locating the detected objects
102 * @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
103 * The dimension of this array must be the same of multi_hog->num_models()
104 * The i-th detection_window_stride of this array must be multiple of the block_stride stored in the i-th multi_hog array
105 * @param[in] border_mode Border mode to use.
106 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
107 * @param[in] threshold (Optional) Threshold for the distance between features and SVM classifying plane
108 * @param[in] non_maxima_suppression (Optional) Flag to specify whether the non-maxima suppression is required or not.
109 * True if the non-maxima suppression stage has to be computed
110 * @param[in] min_distance (Optional) Radial Euclidean distance to use for the non-maxima suppression stage
111 *
112 */
113 void configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLMultiHOG *multi_hog, ICLDetectionWindowArray *detection_windows, ICLSize2DArray *detection_window_strides,
114 BorderMode border_mode, uint8_t constant_border_value = 0, float threshold = 0.0f, bool non_maxima_suppression = false, float min_distance = 1.0f);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100115
116 // Inherited method overridden:
117 void run() override;
118
119private:
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +0100120 MemoryGroup _memory_group;
121 CLHOGGradient _gradient_kernel;
122 std::vector<std::unique_ptr<CLHOGOrientationBinningKernel>> _orient_bin_kernel;
123 std::vector<std::unique_ptr<CLHOGBlockNormalizationKernel>> _block_norm_kernel;
124 std::vector<CLHOGDetector> _hog_detect_kernel;
125 CPPDetectionWindowNonMaximaSuppressionKernel _non_maxima_kernel;
126 std::vector<CLTensor> _hog_space;
127 std::vector<CLTensor> _hog_norm_space;
128 ICLDetectionWindowArray *_detection_windows;
129 CLTensor _mag;
130 CLTensor _phase;
131 bool _non_maxima_suppression;
132 size_t _num_orient_bin_kernel;
133 size_t _num_block_norm_kernel;
134 size_t _num_hog_detect_kernel;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100135};
136}
137
morgolock00c76012020-11-06 10:40:12 +0000138#endif /* ARM_COMPUTE_CLHOGMULTIDETECTION_H */