blob: 1c27585a1e7911e8b6a121591064354fa7336cf1 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2019 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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
29using namespace arm_compute;
30
31HOGInfo::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
37HOGInfo::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
44void 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
John Richardson684cb0f2018-01-09 11:17:00 +000064 _descriptor_size = num_cells_per_block().area() * num_block_positions_per_image(_detection_window_size).area() * _num_bins + 1;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065}
66
67Size2D HOGInfo::num_cells_per_block() const
68{
John Richardson25f23682017-11-27 14:35:09 +000069 ARM_COMPUTE_ERROR_ON(_cell_size.width == 0 || _cell_size.height == 0);
70
Michalis Spyroua4f378d2019-04-26 14:54:54 +010071 return Size2D{ _block_size.width / _cell_size.width,
72 _block_size.height / _cell_size.height };
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073}
74
John Richardson25f23682017-11-27 14:35:09 +000075Size2D HOGInfo::num_cells_per_block_stride() const
76{
77 ARM_COMPUTE_ERROR_ON(_cell_size.width == 0 || _cell_size.height == 0);
78
Michalis Spyroua4f378d2019-04-26 14:54:54 +010079 return Size2D{ _block_stride.width / _cell_size.width,
80 _block_stride.height / _cell_size.height };
John Richardson25f23682017-11-27 14:35:09 +000081}
82
John Richardson684cb0f2018-01-09 11:17:00 +000083Size2D HOGInfo::num_block_positions_per_image(const Size2D &image_size) const
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084{
John Richardson684cb0f2018-01-09 11:17:00 +000085 ARM_COMPUTE_ERROR_ON(_block_stride.width == 0 || _block_stride.height == 0);
86
Michalis Spyroua4f378d2019-04-26 14:54:54 +010087 return Size2D{ ((image_size.width - _block_size.width) / _block_stride.width) + 1,
88 ((image_size.height - _block_size.height) / _block_stride.height) + 1 };
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089}
90
91const Size2D &HOGInfo::cell_size() const
92{
93 return _cell_size;
94}
95
96const Size2D &HOGInfo::block_size() const
97{
98 return _block_size;
99}
100
101const Size2D &HOGInfo::detection_window_size() const
102{
103 return _detection_window_size;
104}
105
106const Size2D &HOGInfo::block_stride() const
107{
108 return _block_stride;
109}
110
111size_t HOGInfo::num_bins() const
112{
113 return _num_bins;
114}
115
116HOGNormType HOGInfo::normalization_type() const
117{
118 return _normalization_type;
119}
120
121float HOGInfo::l2_hyst_threshold() const
122{
123 return _l2_hyst_threshold;
124}
125
126PhaseType HOGInfo::phase_type() const
127{
128 return _phase_type;
129}
130
131size_t HOGInfo::descriptor_size() const
132{
133 return _descriptor_size;
134}