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_CLCANNYEDGE_H__ |
| 25 | #define __ARM_COMPUTE_CLCANNYEDGE_H__ |
| 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
| 29 | #include "arm_compute/core/CL/kernels/CLCannyEdgeKernel.h" |
| 30 | #include "arm_compute/core/CL/kernels/CLFillBorderKernel.h" |
Georgios Pinitas | 5701e2a | 2017-09-18 17:43:33 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/CL/CLMemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/CL/CLTensor.h" |
Georgios Pinitas | 5701e2a | 2017-09-18 17:43:33 +0100 | [diff] [blame] | 33 | #include "arm_compute/runtime/IMemoryManager.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 34 | |
| 35 | #include <memory> |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | class ICLTensor; |
| 40 | |
| 41 | /** Basic function to execute canny edge on OpenCL. This function calls the following OpenCL kernels and functions: |
| 42 | * |
| 43 | * -# @ref CLFillBorderKernel (if border_mode == REPLICATE or border_mode == CONSTANT) |
| 44 | * -# @ref CLSobel3x3 (if gradient_size == 3) or @ref CLSobel5x5 (if gradient_size == 5) or @ref CLSobel7x7 (if gradient_size == 7) |
| 45 | * -# @ref CLGradientKernel |
| 46 | * -# @ref CLEdgeNonMaxSuppressionKernel |
| 47 | * -# @ref CLEdgeTraceKernel |
| 48 | * |
| 49 | */ |
| 50 | class CLCannyEdge : public IFunction |
| 51 | { |
| 52 | public: |
| 53 | /** Constructor */ |
Georgios Pinitas | 5701e2a | 2017-09-18 17:43:33 +0100 | [diff] [blame] | 54 | CLCannyEdge(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 55 | /** Initialise the function's source, destination, thresholds, gradient size, normalization type and border mode. |
| 56 | * |
| 57 | * @param[in,out] input Source tensor. Data types supported: U8. (Written to only for border_mode != UNDEFINED) |
| 58 | * @param[out] output Destination tensor. Data types supported: U8. |
| 59 | * @param[in] upper_thr Upper threshold used for the hysteresis. |
| 60 | * @param[in] lower_thr Lower threshold used for the hysteresis. |
| 61 | * @param[in] gradient_size Gradient size (3, 5 or 7). |
| 62 | * @param[in] norm_type Normalization type. if 1, L1-Norm otherwise L2-Norm. |
| 63 | * @param[in] border_mode Border mode to use for the convolution. |
| 64 | * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT. |
| 65 | */ |
| 66 | void configure(ICLTensor *input, ICLTensor *output, int32_t upper_thr, int32_t lower_thr, int32_t gradient_size, int32_t norm_type, |
| 67 | BorderMode border_mode, uint8_t constant_border_value = 0); |
| 68 | |
| 69 | // Inherited methods overridden: |
| 70 | virtual void run() override; |
| 71 | |
| 72 | private: |
Georgios Pinitas | 5701e2a | 2017-09-18 17:43:33 +0100 | [diff] [blame] | 73 | CLMemoryGroup _memory_group; /**< Function's memory group */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | std::unique_ptr<IFunction> _sobel; /**< Pointer to Sobel kernel. */ |
| 75 | CLGradientKernel _gradient; /**< Gradient kernel. */ |
| 76 | CLFillBorderKernel _border_mag_gradient; /**< Fill border on magnitude tensor kernel */ |
| 77 | CLEdgeNonMaxSuppressionKernel _non_max_suppr; /**< Non-Maxima suppression kernel. */ |
| 78 | CLEdgeTraceKernel _edge_trace; /**< Edge tracing kernel. */ |
| 79 | CLImage _gx; /**< Source tensor - Gx component. */ |
| 80 | CLImage _gy; /**< Source tensor - Gy component. */ |
| 81 | CLImage _mag; /**< Source tensor - Magnitude. */ |
| 82 | CLImage _phase; /**< Source tensor - Phase. */ |
| 83 | CLImage _nonmax; /**< Source tensor - Non-Maxima suppressed. */ |
| 84 | CLImage _visited, _recorded, _l1_list_counter, _l1_stack; /**< Temporary tensors */ |
| 85 | }; |
| 86 | } |
| 87 | |
| 88 | #endif /* __ARM_COMPUTE_CLCANNYEDGE_H__ */ |