• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016-2019 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 
HOGInfo()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 
HOGInfo(const Size2D & cell_size,const Size2D & block_size,const Size2D & detection_window_size,const Size2D & block_stride,size_t num_bins,HOGNormType normalization_type,float l2_hyst_threshold,PhaseType phase_type)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 
init(const Size2D & cell_size,const Size2D & block_size,const Size2D & detection_window_size,const Size2D & block_stride,size_t num_bins,HOGNormType normalization_type,float l2_hyst_threshold,PhaseType phase_type)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_block_positions_per_image(_detection_window_size).area() * _num_bins + 1;
65 }
66 
num_cells_per_block() const67 Size2D HOGInfo::num_cells_per_block() const
68 {
69     ARM_COMPUTE_ERROR_ON(_cell_size.width == 0 || _cell_size.height == 0);
70 
71     return Size2D{ _block_size.width / _cell_size.width,
72                    _block_size.height / _cell_size.height };
73 }
74 
num_cells_per_block_stride() const75 Size2D HOGInfo::num_cells_per_block_stride() const
76 {
77     ARM_COMPUTE_ERROR_ON(_cell_size.width == 0 || _cell_size.height == 0);
78 
79     return Size2D{ _block_stride.width / _cell_size.width,
80                    _block_stride.height / _cell_size.height };
81 }
82 
num_block_positions_per_image(const Size2D & image_size) const83 Size2D HOGInfo::num_block_positions_per_image(const Size2D &image_size) const
84 {
85     ARM_COMPUTE_ERROR_ON(_block_stride.width == 0 || _block_stride.height == 0);
86 
87     return Size2D{ ((image_size.width - _block_size.width) / _block_stride.width) + 1,
88                    ((image_size.height - _block_size.height) / _block_stride.height) + 1 };
89 }
90 
cell_size() const91 const Size2D &HOGInfo::cell_size() const
92 {
93     return _cell_size;
94 }
95 
block_size() const96 const Size2D &HOGInfo::block_size() const
97 {
98     return _block_size;
99 }
100 
detection_window_size() const101 const Size2D &HOGInfo::detection_window_size() const
102 {
103     return _detection_window_size;
104 }
105 
block_stride() const106 const Size2D &HOGInfo::block_stride() const
107 {
108     return _block_stride;
109 }
110 
num_bins() const111 size_t HOGInfo::num_bins() const
112 {
113     return _num_bins;
114 }
115 
normalization_type() const116 HOGNormType HOGInfo::normalization_type() const
117 {
118     return _normalization_type;
119 }
120 
l2_hyst_threshold() const121 float HOGInfo::l2_hyst_threshold() const
122 {
123     return _l2_hyst_threshold;
124 }
125 
phase_type() const126 PhaseType HOGInfo::phase_type() const
127 {
128     return _phase_type;
129 }
130 
descriptor_size() const131 size_t HOGInfo::descriptor_size() const
132 {
133     return _descriptor_size;
134 }
135