1 /* 2 * Copyright (c) 2017-2020 Arm Limited. 3 * 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 */ 24 #ifndef ARM_COMPUTE_CLHOGDETECTORKERNEL_H 25 #define ARM_COMPUTE_CLHOGDETECTORKERNEL_H 26 27 #include "arm_compute/core/CL/ICLArray.h" 28 #include "arm_compute/core/CL/ICLHOG.h" 29 #include "arm_compute/core/CL/OpenCL.h" 30 #include "src/core/CL/ICLKernel.h" 31 32 namespace cl 33 { 34 class Buffer; 35 } 36 37 namespace arm_compute 38 { 39 class ICLTensor; 40 41 /** OpenCL kernel to perform HOG detector kernel using linear SVM */ 42 class CLHOGDetectorKernel : public ICLKernel 43 { 44 public: 45 /** Default constructor */ 46 CLHOGDetectorKernel(); 47 /** Prevent instances of this class from being copied (As this class contains pointers) */ 48 CLHOGDetectorKernel(const CLHOGDetectorKernel &) = delete; 49 /** Prevent instances of this class from being copied (As this class contains pointers) */ 50 CLHOGDetectorKernel &operator=(const CLHOGDetectorKernel &) = delete; 51 /** Allow instances of this class to be moved */ 52 CLHOGDetectorKernel(CLHOGDetectorKernel &&) = default; 53 /** Allow instances of this class to be moved */ 54 CLHOGDetectorKernel &operator=(CLHOGDetectorKernel &&) = default; 55 /** Default destructor */ 56 ~CLHOGDetectorKernel() = default; 57 58 /** Initialise the kernel's input, HOG data-object, detection window, the stride of the detection window, the threshold and index of the object to detect 59 * 60 * @param[in] input Input tensor which stores the HOG descriptor obtained with @ref CLHOGOrientationBinningKernel. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per block 61 * @param[in] hog HOG data object used by @ref CLHOGOrientationBinningKernel and @ref CLHOGBlockNormalizationKernel 62 * @param[out] detection_windows Array of @ref DetectionWindow. This array stores all the detected objects 63 * @param[in] num_detection_windows Number of detected objects 64 * @param[in] detection_window_stride Distance in pixels between 2 consecutive detection windows in x and y directions. 65 * It must be multiple of the hog->info()->block_stride() 66 * @param[in] threshold (Optional) Threshold for the distance between features and SVM classifying plane 67 * @param[in] idx_class (Optional) Index of the class used for evaluating which class the detection window belongs to 68 */ 69 void configure(const ICLTensor *input, const ICLHOG *hog, ICLDetectionWindowArray *detection_windows, cl::Buffer *num_detection_windows, const Size2D &detection_window_stride, float threshold = 0.0f, 70 uint16_t idx_class = 0); 71 /** Initialise the kernel's input, HOG data-object, detection window, the stride of the detection window, the threshold and index of the object to detect 72 * 73 * @param[in] compile_context The compile context to be used. 74 * @param[in] input Input tensor which stores the HOG descriptor obtained with @ref CLHOGOrientationBinningKernel. Data type supported: F32. Number of channels supported: equal to the number of histogram bins per block 75 * @param[in] hog HOG data object used by @ref CLHOGOrientationBinningKernel and @ref CLHOGBlockNormalizationKernel 76 * @param[out] detection_windows Array of @ref DetectionWindow. This array stores all the detected objects 77 * @param[in] num_detection_windows Number of detected objects 78 * @param[in] detection_window_stride Distance in pixels between 2 consecutive detection windows in x and y directions. 79 * It must be multiple of the hog->info()->block_stride() 80 * @param[in] threshold (Optional) Threshold for the distance between features and SVM classifying plane 81 * @param[in] idx_class (Optional) Index of the class used for evaluating which class the detection window belongs to 82 */ 83 void configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLHOG *hog, ICLDetectionWindowArray *detection_windows, cl::Buffer *num_detection_windows, 84 const Size2D &detection_window_stride, float threshold = 0.0f, 85 uint16_t idx_class = 0); 86 87 // Inherited methods overridden: 88 void run(const Window &window, cl::CommandQueue &queue); 89 90 private: 91 const ICLTensor *_input; 92 ICLDetectionWindowArray *_detection_windows; 93 cl::Buffer *_num_detection_windows; 94 }; 95 } // namespace arm_compute 96 #endif /* ARM_COMPUTE_CLHOGDETECTORKERNEL_H */ 97