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
183a3de5
Commit
183a3de5
authored
Feb 08, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added set_aspect_ratio()
parent
bff364dc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
rectangle.h
dlib/geometry/rectangle.h
+35
-0
rectangle_abstract.h
dlib/geometry/rectangle_abstract.h
+18
-0
No files found.
dlib/geometry/rectangle.h
View file @
183a3de5
...
...
@@ -602,6 +602,41 @@ namespace dlib
return
rectangle
(
x
,
y
,
x
+
rect
.
width
()
-
1
,
y
+
rect
.
height
()
-
1
);
}
// ----------------------------------------------------------------------------------------
inline
rectangle
set_aspect_ratio
(
const
rectangle
&
rect
,
double
ratio
)
{
DLIB_ASSERT
(
ratio
>
0
,
"
\t
rectangle set_aspect_ratio()"
<<
"
\n\t
ratio: "
<<
ratio
<<
"
\n\t
this: "
<<
this
);
// aspect ratio is w/h
// we need to find the rectangle that is nearest to rect in area but
// with an aspect ratio of ratio.
// w/h == ratio
// w*h == rect.area()
if
(
ratio
>=
1
)
{
const
long
h
=
static_cast
<
long
>
(
std
::
sqrt
(
rect
.
area
()
/
ratio
)
+
0
.
5
);
const
long
w
=
static_cast
<
long
>
(
h
*
ratio
+
0
.
5
);
return
centered_rect
(
rect
,
w
,
h
);
}
else
{
const
long
w
=
static_cast
<
long
>
(
std
::
sqrt
(
rect
.
area
()
*
ratio
)
+
0
.
5
);
const
long
h
=
static_cast
<
long
>
(
w
/
ratio
+
0
.
5
);
return
centered_rect
(
rect
,
w
,
h
);
}
}
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/geometry/rectangle_abstract.h
View file @
183a3de5
...
...
@@ -477,6 +477,24 @@ namespace dlib
and height)
!*/
// ----------------------------------------------------------------------------------------
inline
rectangle
set_aspect_ratio
(
const
rectangle
&
rect
,
double
ratio
);
/*!
requires
- ratio > 0
ensures
- This function reshapes the given rectangle so that it has the given aspect
ratio. In particular, this means we return a rectangle R such that the
following equations are as true as possible:
- R.width()/R.height() == ratio
- R.area() == rect.area()
- center(rect) == center(R)
!*/
// ----------------------------------------------------------------------------------------
inline
rectangle
intersect
(
...
...
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