-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwarp.hh
executable file
·69 lines (53 loc) · 1.58 KB
/
warp.hh
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
// File: warp.hh
// Date: Tue Apr 30 23:49:42 2013 +0800
// Author: Yuxin Wu <[email protected]>
#pragma once
#include "lib/geometry.hh"
#include "lib/mat.h"
#include "feature/feature.hh"
#include "match_info.hh"
#include "common/common.hh"
namespace pano {
class CylinderProject {
public:
Vec center;
int r;
int sizefactor;
CylinderProject(int m_r, const Vec& m_center, int m_size):
center(m_center), r(m_r),
sizefactor(m_size){}
// project key points in an image, together with the image
Mat32f project(const Mat32f& img, std::vector<Vec2D>& pts) const;
// project key points in an image, given the image shape
// return the projected image offset
Vec2D project(Shape2D& shape, std::vector<Vec2D>& pts) const;
private:
// return (angle with x) and (angle vertical)
Vec2D proj(const Vec& p) const;
inline Vec2D proj(const Vec2D& p) const
{ return proj(Vec(p.x, p.y, 0)); }
Vec2D proj_r(const Vec2D& p) const;
};
class CylinderWarper {
public:
explicit CylinderWarper(real_t m_hfactor):
h_factor(m_hfactor) {}
// warp image together with key points
void warp(Mat32f& mat, std::vector<Vec2D>& kpts) const {
mat = get_projector(
mat.width(), mat.height()).project(mat, kpts);
}
// warp keypoints given image shape
void warp(Shape2D& shape, std::vector<Vec2D>& kpts) const {
get_projector(shape.w, shape.h).project(shape, kpts);
}
// warp image only
inline void warp(Mat32f& mat) const {
std::vector<Vec2D> a;
warp(mat, a);
}
protected:
CylinderProject get_projector(int w, int h) const;
const real_t h_factor;
};
}