Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, 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 | #include "arm_compute/core/HOGInfo.h" |
| 25 | |
| 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/Validate.h" |
| 28 | |
| 29 | using namespace arm_compute; |
| 30 | |
| 31 | HOGInfo::HOGInfo() |
| 32 | : _cell_size(), _block_size(), _detection_window_size(), _block_stride(), _num_bins(0), _normalization_type(HOGNormType::L2HYS_NORM), _l2_hyst_threshold(0.0f), _phase_type(PhaseType::UNSIGNED), |
| 33 | _descriptor_size(0) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | HOGInfo::HOGInfo(const Size2D &cell_size, const Size2D &block_size, const Size2D &detection_window_size, const Size2D &block_stride, size_t num_bins, |
| 38 | HOGNormType normalization_type, float l2_hyst_threshold, PhaseType phase_type) |
| 39 | : HOGInfo() |
| 40 | { |
| 41 | init(cell_size, block_size, detection_window_size, block_stride, num_bins, normalization_type, l2_hyst_threshold, phase_type); |
| 42 | } |
| 43 | |
| 44 | void HOGInfo::init(const Size2D &cell_size, const Size2D &block_size, const Size2D &detection_window_size, const Size2D &block_stride, size_t num_bins, |
| 45 | HOGNormType normalization_type, float l2_hyst_threshold, PhaseType phase_type) |
| 46 | { |
| 47 | ARM_COMPUTE_ERROR_ON_MSG((block_size.width % cell_size.width), "The block width must be multiple of cell width"); |
| 48 | ARM_COMPUTE_ERROR_ON_MSG((block_size.height % cell_size.height), "Block height must be multiple of cell height"); |
| 49 | ARM_COMPUTE_ERROR_ON_MSG((block_stride.width % cell_size.width), "Block stride width must be multiple of cell width"); |
| 50 | ARM_COMPUTE_ERROR_ON_MSG((block_stride.height % cell_size.height), "Block stride height must be multiple of cell height"); |
| 51 | ARM_COMPUTE_ERROR_ON_MSG(((detection_window_size.width - block_size.width) % block_stride.width), "Window width must be multiple of block width and block stride width"); |
| 52 | ARM_COMPUTE_ERROR_ON_MSG(((detection_window_size.height - block_size.height) % block_stride.height), "Window height must be multiple of block height and block stride height"); |
| 53 | |
| 54 | _cell_size = cell_size; |
| 55 | _block_size = block_size; |
| 56 | _detection_window_size = detection_window_size; |
| 57 | _block_stride = block_stride; |
| 58 | _num_bins = num_bins; |
| 59 | _normalization_type = normalization_type; |
| 60 | _l2_hyst_threshold = l2_hyst_threshold; |
| 61 | _phase_type = phase_type; |
| 62 | |
| 63 | // Compute descriptor size. +1 takes into account of the bias |
| 64 | _descriptor_size = num_cells_per_block().area() * num_blocks_per_image(_detection_window_size).area() * _num_bins + 1; |
| 65 | } |
| 66 | |
| 67 | Size2D HOGInfo::num_cells_per_block() const |
| 68 | { |
| 69 | return Size2D(_block_size.width / _cell_size.width, |
| 70 | _block_size.height / _cell_size.height); |
| 71 | } |
| 72 | |
| 73 | Size2D HOGInfo::num_blocks_per_image(const Size2D &image_size) const |
| 74 | { |
| 75 | return Size2D(((image_size.width - _block_size.width) / _block_stride.width) + 1, |
| 76 | ((image_size.height - _block_size.height) / _block_stride.height) + 1); |
| 77 | } |
| 78 | |
| 79 | const Size2D &HOGInfo::cell_size() const |
| 80 | { |
| 81 | return _cell_size; |
| 82 | } |
| 83 | |
| 84 | const Size2D &HOGInfo::block_size() const |
| 85 | { |
| 86 | return _block_size; |
| 87 | } |
| 88 | |
| 89 | const Size2D &HOGInfo::detection_window_size() const |
| 90 | { |
| 91 | return _detection_window_size; |
| 92 | } |
| 93 | |
| 94 | const Size2D &HOGInfo::block_stride() const |
| 95 | { |
| 96 | return _block_stride; |
| 97 | } |
| 98 | |
| 99 | size_t HOGInfo::num_bins() const |
| 100 | { |
| 101 | return _num_bins; |
| 102 | } |
| 103 | |
| 104 | HOGNormType HOGInfo::normalization_type() const |
| 105 | { |
| 106 | return _normalization_type; |
| 107 | } |
| 108 | |
| 109 | float HOGInfo::l2_hyst_threshold() const |
| 110 | { |
| 111 | return _l2_hyst_threshold; |
| 112 | } |
| 113 | |
| 114 | PhaseType HOGInfo::phase_type() const |
| 115 | { |
| 116 | return _phase_type; |
| 117 | } |
| 118 | |
| 119 | size_t HOGInfo::descriptor_size() const |
| 120 | { |
| 121 | return _descriptor_size; |
| 122 | } |