-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatch_info.hh
executable file
·80 lines (66 loc) · 1.84 KB
/
match_info.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
70
71
72
73
74
75
76
77
78
79
80
//File: match_info.hh
//Author: Yuxin Wu <[email protected]>
#pragma once
#include <utility>
#include <vector>
#include <iostream>
#include "lib/geometry.hh"
#include "homography.hh"
#include "common/common.hh"
namespace pano {
struct MatchInfo {
// coordinate is half-shifted
typedef std::pair<Vec2D, Vec2D> PCC; // to, from
std::vector<PCC> match;
float confidence = 0; // negative value indicates number of inlier, for debug
Homography homo;
void reverse() {
for (auto& c : match)
std::swap(c.first, c.second);
}
void serialize(std::ostream& os) const {
os << confidence << " ";
homo.serialize(os);
os << " " << match.size();
for (auto& p : match) {
os << " " << p.first.x << " "
<< p.first.y << " " << p.second.x << " "
<< p.second.y;
}
}
static MatchInfo deserialize(std::istream& is) {
MatchInfo ret;
is >> ret.confidence;
ret.homo = Homography::deserialize(is);
int match_size;
is >> match_size;
ret.match.resize(match_size);
REP(i, match_size) {
PCC& p = ret.match[i];
is >> p.first.x >> p.first.y >> p.second.x >> p.second.y;
}
return ret;
}
};
struct Shape2D {
int w, h;
Shape2D(int w, int h): w(w), h(h) {}
inline double halfw() const { return w * 0.5; }
inline double halfh() const { return h * 0.5; }
inline Vec2D center() const { return Vec2D{halfw(), halfh()}; }
// 1 2
// 3 4 return corner in [-w/2,w/2] coordinate
inline std::vector<Vec2D> shifted_corner() const {
return {Vec2D{-w*0.5, -h*0.5}, Vec2D{w*0.5,-h*0.5},
Vec2D{-w*0.5, h*0.5}, Vec2D{w*0.5, h*0.5}};
}
// whether a point in shifted coor is inside the shape
inline bool shifted_in(Vec2D p) const {
return (p.x >= -w*0.5 && p.x < w*0.5 && p.y >= -h*0.5 && p.y < h*0.5);
}
friend std::ostream& operator << (std::ostream& os, const Shape2D& s) {
os << "w=" << s.w << ",h=" << s.h;
return os;
}
};
}