forked from luigifreda/pyslam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
76 lines (65 loc) · 2.56 KB
/
Copy pathutils.cpp
File metadata and controls
76 lines (65 loc) · 2.56 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
/*
* This file is part of PYSLAM
*
* Copyright (C) 2016-present Luigi Freda <luigi dot freda at gmail dot com>
*
* PYSLAM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PYSLAM 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PYSLAM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "utils.h"
namespace utils
{
void extract_patch( const cv::Mat& image, const cv::KeyPoint& kp,
const int& patch_size, cv::Mat& patch,
const bool use_orientation,
const float scale_factor,
const int warp_flags)
{
cv::Mat M;
if ( use_orientation )
{
const float s = scale_factor * (float) kp.size / (float) patch_size;
const float cosine = (kp.angle>=0) ? cos(kp.angle*(float)CV_PI/180.0f) : 1.f;
const float sine = (kp.angle>=0) ? sin(kp.angle*(float)CV_PI/180.0f) : 0.f;
float M_[] = {
s*cosine, -s*sine, (-s*cosine + s*sine ) * patch_size/2.0f + kp.pt.x,
s*sine, s*cosine, (-s*sine - s*cosine) * patch_size/2.0f + kp.pt.y
};
M = cv::Mat( 2, 3, CV_32FC1, M_ ).clone();
}
else
{
const float s = scale_factor * (float)kp.size / (float)patch_size;
float M_[] = {
s, 0.f, -s * patch_size/2.0f + kp.pt.x,
0.f, s, -s * patch_size/2.0f + kp.pt.y
};
M = cv::Mat( 2, 3, CV_32FC1, M_ ).clone();
}
cv::warpAffine( image, patch, M, cv::Size( patch_size, patch_size ), warp_flags);
}
void extract_patches( const cv::Mat& image, const std::vector<cv::KeyPoint>& kps,
const int& patch_size, std::vector<cv::Mat>& patches,
const bool use_orientation,
const float scale_factor,
const int warp_flags)
{
patches.resize(kps.size());
for(size_t ii=0,iiEnd=kps.size();ii<iiEnd;ii++)
{
cv::Mat& patchii = patches[ii];
const cv::KeyPoint& kpii = kps[ii];
extract_patch(image, kpii, patch_size, patchii, use_orientation, scale_factor, warp_flags);
}
}
} // namespace utils