Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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_CLCANNYEDGEKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_CLCANNYEDGEKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/CL/ICLKernel.h" |
| 28 | |
| 29 | #include <cstdint> |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | class ICLTensor; |
| 34 | |
| 35 | /** OpenCL kernel to perform Gradient computation. |
| 36 | */ |
| 37 | class CLGradientKernel : public ICLKernel |
| 38 | { |
| 39 | public: |
| 40 | /** Constructor */ |
| 41 | CLGradientKernel(); |
| 42 | /** Prevent instances of this class from being copied (As this class contains pointers). */ |
| 43 | CLGradientKernel(const CLGradientKernel &) = delete; |
| 44 | /** Prevent instances of this class from being copied (As this class contains pointers). */ |
| 45 | CLGradientKernel &operator=(const CLGradientKernel &) = delete; |
| 46 | /** Initialise the kernel's sources, destinations and border mode. |
| 47 | * |
| 48 | * @note gx, gy and mag must all be the same size (either 16 or 32). |
| 49 | * |
| 50 | * @param[in] gx Source tensor - Gx component. Data types supported: S16/S32. |
| 51 | * @param[in] gy Source tensor - Gy component. Data types supported: Same as gx. |
| 52 | * @param[out] magnitude Destination tensor - Magnitude. Data types supported: U16/U32. Must match the pixel size of gx, gy. |
| 53 | * @param[out] phase Destination tensor - Quantized phase. Data types supported: U8. |
| 54 | * @param[in] norm_type Normalization type. if 1, L1-Norm otherwise L2-Norm. |
| 55 | */ |
| 56 | void configure(const ICLTensor *gx, const ICLTensor *gy, ICLTensor *magnitude, ICLTensor *phase, int32_t norm_type); |
| 57 | |
| 58 | // Inherited methods overridden: |
| 59 | void run(const Window &window, cl::CommandQueue &queue) override; |
| 60 | |
| 61 | private: |
| 62 | const ICLTensor *_gx; /**< Source tensor - Gx component */ |
| 63 | const ICLTensor *_gy; /**< Source tensor - Gy component */ |
| 64 | ICLTensor *_magnitude; /**< Destination tensor - Magnitude */ |
| 65 | ICLTensor *_phase; /**< Destination tensor - Quantized phase */ |
| 66 | }; |
| 67 | |
| 68 | /** OpenCL kernel to perform Non-Maxima suppression for Canny Edge. |
| 69 | * |
| 70 | * @note This kernel is meant to be used alongside CannyEdge and performs a non-maxima suppression using magnitude and phase of input |
| 71 | * to characterize points as possible edges. The output buffer needs to be cleared before this kernel is executed. |
| 72 | * |
| 73 | * @note Hysteresis is computed in @ref CLEdgeTraceKernel |
| 74 | */ |
| 75 | class CLEdgeNonMaxSuppressionKernel : public ICLKernel |
| 76 | { |
| 77 | public: |
| 78 | /** Constructor */ |
| 79 | CLEdgeNonMaxSuppressionKernel(); |
| 80 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 81 | CLEdgeNonMaxSuppressionKernel(const CLEdgeNonMaxSuppressionKernel &) = delete; |
| 82 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 83 | CLEdgeNonMaxSuppressionKernel &operator=(const CLEdgeNonMaxSuppressionKernel &) = delete; |
| 84 | /** Initialise the kernel's sources, destination and border mode. |
| 85 | * |
| 86 | * @param[in] magnitude Source tensor - Magnitude. Data types supported: U16/U32. |
| 87 | * @param[in] phase Source tensor - Quantized phase. Data types supported: U8. |
| 88 | * @param[out] output Destination tensor. Data types supported: U16/U32. |
| 89 | * @param[in] lower_thr Lower threshold. |
| 90 | * @param[in] border_undefined True if the border mode is undefined. False if it's replicate or constant. |
| 91 | */ |
| 92 | void configure(const ICLTensor *magnitude, const ICLTensor *phase, ICLTensor *output, int32_t lower_thr, bool border_undefined); |
| 93 | |
| 94 | // Inherited methods overridden: |
| 95 | void run(const Window &window, cl::CommandQueue &queue) override; |
| 96 | BorderSize border_size() const override; |
| 97 | |
| 98 | private: |
| 99 | const ICLTensor *_magnitude; /**< Source tensor - Magnitude. */ |
| 100 | const ICLTensor *_phase; /**< Source tensor - Quantized phase. */ |
| 101 | ICLTensor *_output; /**< Destination tensor. */ |
| 102 | }; |
| 103 | |
| 104 | /** OpenCL kernel to perform Edge tracing. |
| 105 | */ |
| 106 | class CLEdgeTraceKernel : public ICLKernel |
| 107 | { |
| 108 | public: |
| 109 | /** Constructor */ |
| 110 | CLEdgeTraceKernel(); |
| 111 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 112 | CLEdgeTraceKernel(const CLEdgeTraceKernel &) = delete; |
| 113 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 114 | CLEdgeTraceKernel &operator=(const CLEdgeTraceKernel &) = delete; |
| 115 | /** Initialise the kernel's source, destination and border mode. |
| 116 | * |
| 117 | * @param[in] input Source tensor. Data types supported: U8. |
| 118 | * @param[out] output Destination tensor. Data types supported: U8. |
| 119 | * @param[in] upper_thr Upper threshold used for the hysteresis |
| 120 | * @param[in] lower_thr Lower threshold used for the hysteresis |
| 121 | * @param[in,out] visited Tensor for keeping the visited pixels. Data types supported: U32. |
| 122 | * Expected to be initialized to 0 before each run. |
| 123 | * @param[in,out] recorded Tensor for keeping the recorded pixels. Data types supported: U32 |
| 124 | * Expected to be initialized to 0 before each run. |
| 125 | * @param[in,out] l1_stack Tensor with the L1 stack for each pixel. Data types supported: S32. |
| 126 | * Expected to be initialized to 0 before each run. |
| 127 | * @param[in,out] l1_stack_counter Tensor for counting the elements in the L1 stack of each pixel. Data types supported: U8. |
| 128 | * Expected to be initialized to 0 before each run. |
| 129 | */ |
| 130 | void configure(const ICLTensor *input, ICLTensor *output, int32_t upper_thr, int32_t lower_thr, |
| 131 | ICLTensor *visited, ICLTensor *recorded, ICLTensor *l1_stack, ICLTensor *l1_stack_counter); |
| 132 | |
| 133 | // Inherited methods overridden: |
| 134 | void run(const Window &window, cl::CommandQueue &queue) override; |
| 135 | |
| 136 | private: |
| 137 | const ICLTensor *_input; /**< Source tensor. */ |
| 138 | ICLTensor *_output; /**< Destination tensor. */ |
| 139 | int32_t _lower_thr; /**< Lower threshold used for the hysteresis. */ |
| 140 | int32_t _upper_thr; /**< Upper threshold used for the hysteresis. */ |
| 141 | ICLTensor *_visited; /**< Marks visited elements */ |
| 142 | ICLTensor *_recorded; /**< Marks recorded elements */ |
| 143 | ICLTensor *_l1_stack; /**< L1 hysteris stack */ |
| 144 | ICLTensor *_l1_stack_counter; /**< L1 hysteris stack counter */ |
| 145 | }; |
| 146 | } |
| 147 | #endif /* __ARM_COMPUTE_CLCANNYEDGEKERNEL_H__ */ |