Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
2241e2c2
Commit
2241e2c2
authored
Aug 18, 2017
by
Davis King
Browse files
merged
parents
08633868
98cf44e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
dlib/image_transforms/random_cropper.h
dlib/image_transforms/random_cropper.h
+8
-6
No files found.
dlib/image_transforms/random_cropper.h
View file @
2241e2c2
...
@@ -235,7 +235,7 @@ namespace dlib
...
@@ -235,7 +235,7 @@ namespace dlib
}
}
else
else
{
{
crop_rect
=
make_random_cropping_rect
_resnet
(
img
);
crop_rect
=
make_random_cropping_rect
(
img
);
}
}
should_flip_crop
=
randomly_flip
&&
rnd
.
get_random_double
()
>
0.5
;
should_flip_crop
=
randomly_flip
&&
rnd
.
get_random_double
()
>
0.5
;
const
double
angle
=
rnd
.
get_double_in_range
(
-
max_rotation_degrees
,
max_rotation_degrees
)
*
pi
/
180
;
const
double
angle
=
rnd
.
get_double_in_range
(
-
max_rotation_degrees
,
max_rotation_degrees
)
*
pi
/
180
;
...
@@ -266,16 +266,18 @@ namespace dlib
...
@@ -266,16 +266,18 @@ namespace dlib
}
}
template
<
typename
image_type
>
template
<
typename
image_type
>
rectangle
make_random_cropping_rect
_resnet
(
rectangle
make_random_cropping_rect
(
const
image_type
&
img_
const
image_type
&
img_
)
)
{
{
const_image_view
<
image_type
>
img
(
img_
);
const_image_view
<
image_type
>
img
(
img_
);
// figure out what rectangle we want to crop from the image
// Figure out what rectangle we want to crop from the image. We are going to
double
mins
=
0.1
,
maxs
=
0.95
;
// crop out an image of size this->dims, so we pick a random scale factor that
// lets this random box be either as big as it can be while still fitting in
// the image or as small as a 3x zoomed in box randomly somewhere in the image.
double
mins
=
1.0
/
3.0
,
maxs
=
std
::
min
(
img
.
nr
()
/
(
double
)
dims
.
rows
,
img
.
nc
()
/
(
double
)
dims
.
cols
);
auto
scale
=
rnd
.
get_double_in_range
(
mins
,
maxs
);
auto
scale
=
rnd
.
get_double_in_range
(
mins
,
maxs
);
auto
size
=
scale
*
std
::
min
(
img
.
nr
(),
img
.
nc
());
rectangle
rect
(
scale
*
dims
.
cols
,
scale
*
dims
.
rows
);
rectangle
rect
(
size
,
size
);
// randomly shift the box around
// randomly shift the box around
point
offset
(
rnd
.
get_random_32bit_number
()
%
(
img
.
nc
()
-
rect
.
width
()),
point
offset
(
rnd
.
get_random_32bit_number
()
%
(
img
.
nc
()
-
rect
.
width
()),
rnd
.
get_random_32bit_number
()
%
(
img
.
nr
()
-
rect
.
height
()));
rnd
.
get_random_32bit_number
()
%
(
img
.
nr
()
-
rect
.
height
()));
...
...
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