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
e2c79e8e
Commit
e2c79e8e
authored
Feb 28, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed extract_image_chips() so that it doesn't build image pyramids larger
than necessary when pulling out chips.
parent
e3c38ba0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
4 deletions
+21
-4
interpolation.h
dlib/image_transforms/interpolation.h
+21
-4
No files found.
dlib/image_transforms/interpolation.h
View file @
e2c79e8e
...
...
@@ -1556,7 +1556,8 @@ namespace dlib
{
chip_details
()
:
angle
(
0
),
rows
(
0
),
cols
(
0
)
{}
chip_details
(
const
rectangle
&
rect_
)
:
rect
(
rect_
),
angle
(
0
),
rows
(
rect_
.
height
()),
cols
(
rect_
.
width
())
{}
chip_details
(
const
drectangle
&
rect_
)
:
rect
(
rect_
),
angle
(
0
),
rows
(
rect_
.
height
()),
cols
(
rect_
.
width
())
{}
chip_details
(
const
drectangle
&
rect_
)
:
rect
(
rect_
),
angle
(
0
),
rows
((
unsigned
long
)(
rect_
.
height
()
+
0
.
5
)),
cols
((
unsigned
long
)(
rect_
.
width
()
+
0
.
5
))
{}
chip_details
(
const
drectangle
&
rect_
,
unsigned
long
size
)
:
rect
(
rect_
),
angle
(
0
)
{
compute_dims_from_size
(
size
);
}
chip_details
(
const
drectangle
&
rect_
,
unsigned
long
size
,
double
angle_
)
:
rect
(
rect_
),
angle
(
angle_
)
...
...
@@ -1617,6 +1618,8 @@ namespace dlib
const
double
relative_size
=
std
::
sqrt
(
size
/
(
double
)
rect
.
area
());
rows
=
static_cast
<
unsigned
long
>
(
rect
.
height
()
*
relative_size
+
0
.
5
);
cols
=
static_cast
<
unsigned
long
>
(
size
/
(
double
)
rows
+
0
.
5
);
rows
=
std
::
max
(
1ul
,
rows
);
cols
=
std
::
max
(
1ul
,
cols
);
}
};
...
...
@@ -1738,22 +1741,36 @@ namespace dlib
// interpolation. So we use an image pyramid to make sure the interpolation is
// fast but also high quality. The first thing we do is figure out how deep the
// image pyramid needs to be.
rectangle
bounding_box
;
for
(
unsigned
long
i
=
0
;
i
<
chip_locations
.
size
();
++
i
)
{
long
depth
=
0
;
double
grow
=
2
;
drectangle
rect
=
pyr
.
rect_down
(
chip_locations
[
i
].
rect
);
while
(
rect
.
area
()
>
chip_locations
[
i
].
size
())
{
rect
=
pyr
.
rect_down
(
rect
);
++
depth
;
// We drop the image size by a factor of 2 each iteration and then assume a
// border of 2 pixels is needed to avoid any border effects of the crop.
grow
=
grow
*
2
+
2
;
}
drectangle
rot_rect
;
const
vector
<
double
,
2
>
cent
=
center
(
chip_locations
[
i
].
rect
);
rot_rect
+=
rotate_point
<
double
>
(
cent
,
chip_locations
[
i
].
rect
.
tl_corner
(),
chip_locations
[
i
].
angle
);
rot_rect
+=
rotate_point
<
double
>
(
cent
,
chip_locations
[
i
].
rect
.
tr_corner
(),
chip_locations
[
i
].
angle
);
rot_rect
+=
rotate_point
<
double
>
(
cent
,
chip_locations
[
i
].
rect
.
bl_corner
(),
chip_locations
[
i
].
angle
);
rot_rect
+=
rotate_point
<
double
>
(
cent
,
chip_locations
[
i
].
rect
.
br_corner
(),
chip_locations
[
i
].
angle
);
bounding_box
+=
grow_rect
(
rot_rect
,
grow
).
intersect
(
get_rect
(
img
));
max_depth
=
std
::
max
(
depth
,
max_depth
);
}
//std::cout << "max_depth: " << max_depth << std::endl;
//std::cout << "crop amount: " << bounding_box.area()/(double)get_rect(img).area() << std::endl;
// now make an image pyramid
dlib
::
array
<
array2d
<
typename
image_traits
<
image_type1
>::
pixel_type
>
>
levels
(
max_depth
);
if
(
levels
.
size
()
!=
0
)
pyr
(
img
,
levels
[
0
]);
pyr
(
sub_image
(
img
,
bounding_box
)
,
levels
[
0
]);
for
(
unsigned
long
i
=
1
;
i
<
levels
.
size
();
++
i
)
pyr
(
levels
[
i
-
1
],
levels
[
i
]);
...
...
@@ -1777,7 +1794,7 @@ namespace dlib
// figure out which level in the pyramid to use to extract the chip
int
level
=
-
1
;
drectangle
rect
=
chip_locations
[
i
].
rect
;
drectangle
rect
=
translate_rect
(
chip_locations
[
i
].
rect
,
-
bounding_box
.
tl_corner
())
;
while
(
pyr
.
rect_down
(
rect
).
area
()
>
chip_locations
[
i
].
size
())
{
++
level
;
...
...
@@ -1795,7 +1812,7 @@ namespace dlib
// now extract the actual chip
if
(
level
==
-
1
)
transform_image
(
img
,
chips
[
i
],
interpolate_bilinear
(),
trns
);
transform_image
(
sub_image
(
img
,
bounding_box
)
,
chips
[
i
],
interpolate_bilinear
(),
trns
);
else
transform_image
(
levels
[
level
],
chips
[
i
],
interpolate_bilinear
(),
trns
);
}
...
...
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