Compute Library
 19.08
HOGInfo.cpp
Go to the documentation of this file.
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  */
25 
26 #include "arm_compute/core/Error.h"
28 
29 using namespace arm_compute;
30 
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 {
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_block_positions_per_image(_detection_window_size).area() * _num_bins + 1;
65 }
66 
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 
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 
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 
91 const Size2D &HOGInfo::cell_size() const
92 {
93  return _cell_size;
94 }
95 
97 {
98  return _block_size;
99 }
100 
102 {
103  return _detection_window_size;
104 }
105 
107 {
108  return _block_stride;
109 }
110 
111 size_t HOGInfo::num_bins() const
112 {
113  return _num_bins;
114 }
115 
117 {
118  return _normalization_type;
119 }
120 
122 {
123  return _l2_hyst_threshold;
124 }
125 
127 {
128  return _phase_type;
129 }
130 
132 {
133  return _descriptor_size;
134 }
L2-norm followed by clipping.
size_t num_bins() const
The number of histogram bins for each cell.
Definition: HOGInfo.cpp:111
const Size2D & detection_window_size() const
The detection window size in pixels.
Definition: HOGInfo.cpp:101
Angle range: [0, 180].
const Size2D & cell_size() const
The cell size in pixels.
Definition: HOGInfo.cpp:91
PhaseType
Phase calculation type.
Definition: Types.h:396
Size2D num_cells_per_block_stride() const
Calculates the number of cells per block stride.
Definition: HOGInfo.cpp:75
Store the HOG's metadata.
Definition: HOGInfo.h:35
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:337
PhaseType phase_type() const
The type of PhaseType.
Definition: HOGInfo.cpp:126
const Size2D & block_stride() const
The block stride in pixels.
Definition: HOGInfo.cpp:106
HOGNormType normalization_type() const
The normalization type.
Definition: HOGInfo.cpp:116
Copyright (c) 2017-2018 ARM Limited.
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
HOGInfo()
Default constructor.
Definition: HOGInfo.cpp:31
Size2D num_cells_per_block() const
Calculates the number of cells for each block.
Definition: HOGInfo.cpp:67
const Size2D & block_size() const
The block size in pixels.
Definition: HOGInfo.cpp:96
float l2_hyst_threshold() const
Threshold used for L2HYS_NORM normalization type.
Definition: HOGInfo.cpp:121
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
HOGNormType
Normalization type for Histogram of Oriented Gradients (HOG)
Definition: Types.h:531
Size2D num_block_positions_per_image(const Size2D &image_size) const
Calculates the number of block positions for the given image size.
Definition: HOGInfo.cpp:83
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
size_t descriptor_size() const
The size of HOG descriptor.
Definition: HOGInfo.cpp:131
void 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=HOGNormType::L2HYS_NORM, float l2_hyst_threshold=0.2f, PhaseType phase_type=PhaseType::UNSIGNED)
Initialize the metadata structure with the given parameters.
Definition: HOGInfo.cpp:44
size_t area() const
The area of the image or rectangle calculated as (width * height)
Definition: Size2D.h:53
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328