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
f711daaa
"tests/git@developer.sourcefind.cn:OpenDAS/dgl.git" did not exist on "46455328e48200c078b66451d2c7471c650cf7c5"
Commit
f711daaa
authored
Feb 28, 2015
by
Davis King
Browse files
Added unit tests for extract_image_chips()
parent
e2c79e8e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
3 deletions
+87
-3
dlib/test/image.cpp
dlib/test/image.cpp
+87
-3
No files found.
dlib/test/image.cpp
View file @
f711daaa
...
@@ -1659,13 +1659,13 @@ namespace
...
@@ -1659,13 +1659,13 @@ namespace
if
(
get_rect
(
out
).
contains
(
rect
))
if
(
get_rect
(
out
).
contains
(
rect
))
{
{
T
val
=
sum
(
pointwise_multiply
(
col_filt
*
row_filt
,
subm
(
mat
(
img
),
rect
)));
T
val
=
sum
(
pointwise_multiply
(
col_filt
*
row_filt
,
subm
(
mat
(
img
),
rect
)));
DLIB_
CASSERT
(
val
==
out
[
r
][
c
],
"err: "
<<
val
-
out
[
r
][
c
]);
DLIB_
TEST_MSG
(
val
==
out
[
r
][
c
],
"err: "
<<
val
-
out
[
r
][
c
]);
DLIB_
CASSER
T
(
area
.
contains
(
point
(
c
,
r
))
,
""
);
DLIB_
TES
T
(
area
.
contains
(
point
(
c
,
r
)));
}
}
else
else
{
{
DLIB_
CASSER
T
(
!
area
.
contains
(
point
(
c
,
r
))
,
""
);
DLIB_
TES
T
(
!
area
.
contains
(
point
(
c
,
r
)));
}
}
}
}
}
}
...
@@ -1729,6 +1729,89 @@ namespace
...
@@ -1729,6 +1729,89 @@ namespace
}
}
}
}
// ----------------------------------------------------------------------------------------
void
test_extract_image_chips
()
{
dlib
::
rand
rnd
;
// Make sure that cropping a white box out of a larger white image always produces an
// exact white box. This should catch any bad border effects from a messed up internal
// cropping.
for
(
int
iter
=
0
;
iter
<
1000
;
++
iter
)
{
print_spinner
();
const
long
nr
=
rnd
.
get_random_32bit_number
()
%
100
+
1
;
const
long
nc
=
rnd
.
get_random_32bit_number
()
%
100
+
1
;
const
long
size
=
rnd
.
get_random_32bit_number
()
%
10000
+
4
;
const
double
angle
=
rnd
.
get_random_double
()
*
pi
;
matrix
<
int
>
img
(
501
,
501
),
chip
;
img
=
255
;
chip_details
details
(
centered_rect
(
center
(
get_rect
(
img
)),
nr
,
nc
),
size
,
angle
);
extract_image_chip
(
img
,
details
,
chip
);
DLIB_TEST_MSG
(
max
(
abs
(
chip
-
255
))
==
0
,
"nr: "
<<
nr
<<
" nc: "
<<
nc
<<
" size: "
<<
size
<<
" angle: "
<<
angle
<<
" error: "
<<
max
(
abs
(
chip
-
255
))
);
}
{
// Make sure that the interpolation in extract_image_chip() keeps stuff in the
// right places.
matrix
<
unsigned
char
>
img
(
10
,
10
),
chip
;
img
=
0
;
img
(
1
,
1
)
=
255
;
img
(
8
,
8
)
=
255
;
extract_image_chip
(
img
,
chip_details
(
get_rect
(
img
),
9
*
9
),
chip
);
DLIB_TEST
(
chip
(
1
,
1
)
==
195
);
DLIB_TEST
(
chip
(
7
,
7
)
==
195
);
chip
(
1
,
1
)
-=
195
;
chip
(
7
,
7
)
-=
195
;
DLIB_TEST
(
sum
(
matrix_cast
<
int
>
(
chip
))
==
0
);
}
// Test the rotation ability of extract_image_chip(). Do this by drawing a line and
// then rotating it so it's horizontal. Check that it worked correctly by hough
// transforming it.
hough_transform
ht
(
151
);
matrix
<
unsigned
char
>
img
(
300
,
300
);
for
(
int
iter
=
0
;
iter
<
1000
;
++
iter
)
{
print_spinner
();
img
=
0
;
const
int
len
=
9000
;
point
cent
=
center
(
get_rect
(
img
));
point
l
=
cent
+
point
(
len
,
0
);
point
r
=
cent
-
point
(
len
,
0
);
const
double
angle
=
rnd
.
get_random_double
()
*
pi
*
3
;
l
=
rotate_point
(
cent
,
l
,
angle
);
r
=
rotate_point
(
cent
,
r
,
angle
);
draw_line
(
img
,
l
,
r
,
255
);
const
long
wsize
=
rnd
.
get_random_32bit_number
()
%
350
+
150
;
matrix
<
unsigned
char
>
temp
;
chip_details
details
(
centered_rect
(
center
(
get_rect
(
img
)),
wsize
,
wsize
),
chip_dims
(
ht
.
size
(),
ht
.
size
()),
angle
);
extract_image_chip
(
img
,
details
,
temp
);
matrix
<
long
>
tform
;
ht
(
temp
,
get_rect
(
temp
),
tform
);
std
::
pair
<
point
,
point
>
line
=
ht
.
get_line
(
max_point
(
tform
));
DLIB_TEST_MSG
(
line
.
first
.
y
()
==
line
.
second
.
y
(),
" wsize: "
<<
wsize
);
DLIB_TEST
(
length
(
line
.
first
-
line
.
second
)
>
100
);
DLIB_TEST
(
length
((
line
.
first
+
line
.
second
)
/
2.0
-
center
(
get_rect
(
temp
)))
<=
1
);
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
class
image_tester
:
public
tester
class
image_tester
:
public
tester
...
@@ -1745,6 +1828,7 @@ namespace
...
@@ -1745,6 +1828,7 @@ namespace
{
{
image_test
();
image_test
();
run_hough_test
();
run_hough_test
();
test_extract_image_chips
();
test_integral_image
<
long
,
unsigned
char
>
();
test_integral_image
<
long
,
unsigned
char
>
();
test_integral_image
<
double
,
int
>
();
test_integral_image
<
double
,
int
>
();
test_integral_image
<
long
,
unsigned
char
>
();
test_integral_image
<
long
,
unsigned
char
>
();
...
...
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