Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
786c93cd
Commit
786c93cd
authored
Jul 03, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added rectangle_transform
parent
4de8678b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
142 additions
and
0 deletions
+142
-0
point_transforms.h
dlib/geometry/point_transforms.h
+69
-0
point_transforms_abstract.h
dlib/geometry/point_transforms_abstract.h
+73
-0
No files found.
dlib/geometry/point_transforms.h
View file @
786c93cd
...
...
@@ -9,6 +9,7 @@
#include "../matrix.h"
#include "../matrix/matrix_la.h"
#include "../optimization/optimization.h"
#include "rectangle.h"
#include <vector>
namespace
dlib
...
...
@@ -190,6 +191,74 @@ namespace dlib
dlib
::
vector
<
double
,
2
>
b
;
};
// ----------------------------------------------------------------------------------------
class
rectangle_transform
{
public
:
rectangle_transform
(
)
{
}
rectangle_transform
(
const
point_transform_affine
&
tform_
)
:
tform
(
tform_
)
{
}
drectangle
operator
()
(
const
drectangle
&
r
)
const
{
dpoint
tl
=
r
.
tl_corner
();
dpoint
tr
=
r
.
tr_corner
();
dpoint
bl
=
r
.
bl_corner
();
dpoint
br
=
r
.
br_corner
();
// The new rectangle wouold ideally have this area if we could actually rotrate
// the box.
double
new_area
=
length
(
tform
(
tl
)
-
tform
(
tr
))
*
length
(
tform
(
tl
)
-
tform
(
bl
));
// But if we rotate the coners of the rectangle and then find the rectangle
// that contains them we get this, which might have a much larger area than we
// want.
drectangle
temp
;
temp
+=
tform
(
tl
);
temp
+=
tform
(
tr
);
temp
+=
tform
(
bl
);
temp
+=
tform
(
br
);
// so we adjust the area to match the target area and have the same center as
// the above box.
double
scale
=
std
::
sqrt
(
new_area
/
temp
.
area
());
return
centered_rect
(
center
(
temp
),
std
::
round
(
temp
.
width
()
*
scale
),
std
::
round
(
temp
.
height
()
*
scale
));
}
rectangle
operator
()
(
const
rectangle
&
r
)
const
{
return
(
*
this
)(
drectangle
(
r
));
}
const
point_transform_affine
&
get_tform
(
)
const
{
return
tform
;
}
inline
friend
void
serialize
(
const
rectangle_transform
&
item
,
std
::
ostream
&
out
)
{
serialize
(
item
.
tform
,
out
);
}
inline
friend
void
deserialize
(
rectangle_transform
&
item
,
std
::
istream
&
in
)
{
deserialize
(
item
.
tform
,
in
);
}
private
:
point_transform_affine
tform
;
};
// ----------------------------------------------------------------------------------------
inline
point_transform_affine
operator
*
(
...
...
dlib/geometry/point_transforms_abstract.h
View file @
786c93cd
...
...
@@ -5,6 +5,8 @@
#include "../matrix/matrix_abstract.h"
#include "vector_abstract.h"
#include "rectangle_abstract.h"
#include "drectangle_abstract.h"
#include <vector>
namespace
dlib
...
...
@@ -146,6 +148,77 @@ namespace dlib
example, an equilateral triangle to turn into an isosceles triangle.
!*/
// ----------------------------------------------------------------------------------------
class
rectangle_transform
{
/*!
WHAT THIS OBJECT REPRESENTS
This object is just a point_transform_affine wrapped up so that it can
transform rectangle objects. It will take a rectangle and transform it
according to an affine transformation.
THREAD SAFETY
It is safe for multiple threads to make concurrent accesses to this object
without synchronization.
!*/
public
:
rectangle_transform
(
);
/*!
ensures
- This object will perform the identity transform. That is, given a rectangle
as input it will return the same rectangle as output.
!*/
rectangle_transform
(
const
point_transform_affine
&
tform
);
/*!
ensures
- #get_tform() == tform
!*/
drectangle
operator
()
(
const
drectangle
&
r
)
const
;
/*!
ensures
- Applies the transformation get_tform() to r and returns the resulting
rectangle. If the transformation doesn't have any rotation then the
transformation simply maps the corners of the rectangle according to
get_tform() and returns the exact result. However, since
dlib::drectangle can't represent rotated rectangles, if there is any
rotation in the affine transform we will attempt to produce the most
faithful possible outputs by ensuring the output rectangle has the
correct center point and that its area and aspect ratio match the correct
rotated rectangle's as much as possible.
!*/
rectangle
operator
()
(
const
rectangle
&
r
)
const
;
/*!
ensures
- returns (*this)(drectangle(r))
!*/
const
point_transform_affine
&
get_tform
(
)
const
;
/*!
ensures
- returns the affine transformation this object uses to transform rectangles.
!*/
};
void
serialize
(
const
rectangle_transform
&
item
,
std
::
ostream
&
out
);
void
deserialize
(
rectangle_transform
&
item
,
std
::
istream
&
in
);
/*!
provides serialization support
!*/
// ----------------------------------------------------------------------------------------
class
point_transform_projective
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment