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
f711daaa
Commit
f711daaa
authored
Feb 28, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for extract_image_chips()
parent
e2c79e8e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
87 additions
and
3 deletions
+87
-3
image.cpp
dlib/test/image.cpp
+87
-3
No files found.
dlib/test/image.cpp
View file @
f711daaa
...
...
@@ -1659,13 +1659,13 @@ namespace
if
(
get_rect
(
out
).
contains
(
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_
CASSERT
(
area
.
contains
(
point
(
c
,
r
)),
""
);
DLIB_
TEST
(
area
.
contains
(
point
(
c
,
r
))
);
}
else
{
DLIB_
CASSERT
(
!
area
.
contains
(
point
(
c
,
r
)),
""
);
DLIB_
TEST
(
!
area
.
contains
(
point
(
c
,
r
))
);
}
}
}
...
...
@@ -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
...
...
@@ -1745,6 +1828,7 @@ namespace
{
image_test
();
run_hough_test
();
test_extract_image_chips
();
test_integral_image
<
long
,
unsigned
char
>
();
test_integral_image
<
double
,
int
>
();
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