-
Notifications
You must be signed in to change notification settings - Fork 0
/
Line.h
149 lines (114 loc) · 3.75 KB
/
Line.h
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*
* This file is part of ALVAR, A Library for Virtual and Augmented Reality.
*
* Copyright 2007-2012 VTT Technical Research Centre of Finland
*
* Contact: VTT Augmented Reality Team <[email protected]>
* <http://www.vtt.fi/multimedia/alvar.html>
*
* ALVAR is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library 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 Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ALVAR; if not, see
* <http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html>.
*/
#ifndef _LINE_H
#define _LINE_H
/**
* \file Line.h
*
* \brief This file implements a parametrized line.
*/
/*****************************************************************************
****************************** I N C L U D E ******************************
****************************************************************************/
#include "Alvar.h"
#include "Util.h"
namespace alvar {
/*****************************************************************************
*
*** class Line
*
* Struct representing a line. The line is parametrized by its center and
* direction vector. The advantage of this form is that vertical lines can
* be represented as compared to the common slope/intercept form.
*
*****************************************************************************/
class ALVAR_EXPORT Line
{
public:
/**
* \brief Constructor.
* \param params params[0] and params[1] are the x and y components of the direction vector, params[2] and params[3]
* \are the x and y coordinates of the line center.
*/
Line() = default;
explicit Line(const cv::Vec4f& params)
{
c.x = params[2];
c.y = params[3];
s.x = params[0];
s.y = params[1];
return;
}
Line(const Line& src) : c(src.c), s(src.s)
{
return;
}
Line& operator=(const Line& rhs)
{
if (this != &rhs)
{
c = rhs.c;
s = rhs.s;
} // end if
return (*this);
}
const PointDouble& GetCenter() const
{
return(c);
}
const PointDouble& GetDirection() const
{
return(s);
}
/**
* \brief Calculates an intersection point of two lines.
* \param l1 First line.
* \param l2 Second line.
* \return Intersection point.
*/
static PointDouble Intersection(const Line& l1, const Line& l2);
PointDouble Intersection(const Line& other) const
{
return(Intersection(*this, other));
}
/**
* \brief Fit lines to vector of points.
* \param lines Resulting set of lines.
* \param corners Index list of line breaks.
* \param edge Vector of points (pixels) where the line is fitted.
* \param grey In the future, we may want to fit lines directly to grayscale image instead of thresholded edge.
*/
static int FitLines(std::vector<Line> &lines, const std::vector<int>& corners,
const std::vector<PointInt>& edge, cv::Mat& grey);
protected:
/**
* \brief Line center.
*/
PointDouble c; // center
/**
* \brief Direction vector.
*/
PointDouble s; // direction vector
}; // end of class Line
} // namespace alvar
#endif