-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPatchwork.h
More file actions
123 lines (99 loc) · 4.61 KB
/
Patchwork.h
File metadata and controls
123 lines (99 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//--------------------------------------------------------------------------------------------------
// Implementation of the papers "Exact Acceleration of Linear Object Detectors", 12th European
// Conference on Computer Vision, 2012 and "Deformable Part Models with Individual Part Scaling",
// 24th British Machine Vision Conference, 2013.
//
// Copyright (c) 2013 Idiap Research Institute, <http://www.idiap.ch/>
// Written by Charles Dubout <charles.dubout@idiap.ch>
//
// This file is part of FFLDv2 (the Fast Fourier Linear Detector version 2)
//
// FFLDv2 is free software: you can redistribute it and/or modify it under the terms of the GNU
// Affero General Public License version 3 as published by the Free Software Foundation.
//
// FFLDv2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
// General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License along with FFLDv2. If
// not, see <http://www.gnu.org/licenses/>.
//--------------------------------------------------------------------------------------------------
#ifndef FFLD_PATCHWORK_H
#define FFLD_PATCHWORK_H
#include "HOGPyramid.h"
#include "Rectangle.h"
#include <utility>
#include <fftw3.h>
namespace FFLD
{
/// The Patchwork class computes convolutions much faster than the HOGPyramid class.
class Patchwork
{
public:
/// Type of a scalar value.
typedef std::complex<HOGPyramid::Scalar> Scalar;
/// Type of a matrix.
typedef Eigen::Matrix<Scalar, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Matrix;
/// Type of a patchwork plane cell (fixed-size complex array of length NbFeatures).
typedef Eigen::Array<Scalar, HOGPyramid::NbFeatures, 1> Cell;
/// Type of a patchwork plane (matrix of cells).
typedef Eigen::Matrix<Cell, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> Plane;
/// Type of a patchwork filter (plane + original filter size).
typedef std::pair<Plane, std::pair<int, int> > Filter;
/// Constructs an empty patchwork. An empty patchwork has no plane.
Patchwork();
/// Constructs a patchwork from a pyramid.
/// @param[in] pyramid Pyramid.
/// @note If the pyramid is larger than the last maxRows and maxCols passed to the Init method
/// the Patchwork will be empty.
/// @note Assumes that the features of the pyramid levels are zero in the padded regions but for
/// the last feature, which is assumed to be one.
explicit Patchwork(const HOGPyramid & pyramid);
/// Returns whether the patchwork is empty. An empty patchwork has no plane.
bool empty() const;
/// Returns the amount of horizontal zero padding (in cells).
int padx() const;
/// Returns the amount of vertical zero padding (in cells).
int pady() const;
/// Returns the number of levels per octave in the pyramid.
int interval() const;
/// Returns the convolutions of the patchwork with filters (useful to compute the SVM margins).
/// @param[in] filters Filters.
/// @param[out] convolutions Convolution of each filter and each level.
void convolve(const std::vector<Filter> & filters,
std::vector<std::vector<HOGPyramid::Matrix> > & convolutions) const;
/// Initializes the FFTW library.
/// @param[in] maxRows Maximum number of rows of a pyramid level (including padding).
/// @param[in] maxCols Maximum number of columns of a pyramid level (including padding).
/// @returns Whether the initialization was successful.
/// @note Must be called before any other method (including constructors).
static bool InitFFTW(int maxRows, int maxCols, bool cacheWisdom = true);
/// Returns the current maximum number of rows of a pyramid level (including padding).
static int MaxRows();
/// Returns the current maximum number of columns of a pyramid level (including padding).
static int MaxCols();
/// Returns a transformed version of a filter to be used by the @c convolve method.
/// @param[in] filter Filter to transform.
/// @param[out] result Transformed filter.
/// @note If Init was not already called or if the filter is larger than the last maxRows and
/// maxCols passed to the Init method the result will be empty.
static void TransformFilter(const HOGPyramid::Level & filter, Filter & result);
private:
int padx_;
int pady_;
int interval_;
std::vector<std::pair<Rectangle, int> > rectangles_;
std::vector<Plane> planes_;
static int MaxRows_;
static int MaxCols_;
static int HalfCols_;
#ifndef FFLD_HOGPYRAMID_DOUBLE
static fftwf_plan Forwards_;
static fftwf_plan Inverse_;
#else
static fftw_plan Forwards_;
static fftw_plan Inverse_;
#endif
};
}
#endif