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
374bdd52
Commit
374bdd52
authored
Sep 25, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added some tests for the label_connected_blobs() function.
parent
463ef33f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
0 deletions
+126
-0
image.cpp
dlib/test/image.cpp
+126
-0
No files found.
dlib/test/image.cpp
View file @
374bdd52
...
...
@@ -987,6 +987,129 @@ namespace
DLIB_TEST
(
img
[
2
][
2
]
==
1
);
}
void
test_label_connected_blobs
()
{
array2d
<
unsigned
char
>
img
;
img
.
set_size
(
400
,
401
);
assign_all_pixels
(
img
,
0
);
rectangle
rect1
,
rect2
,
rect3
;
rect1
=
centered_rect
(
99
,
120
,
50
,
70
);
rect2
=
centered_rect
(
199
,
80
,
34
,
68
);
rect3
=
centered_rect
(
249
,
180
,
120
,
78
);
fill_rect
(
img
,
rect1
,
255
);
fill_rect
(
img
,
rect2
,
255
);
fill_rect
(
img
,
rect3
,
255
);
array2d
<
unsigned
char
>
labels
;
unsigned
long
num
;
num
=
label_connected_blobs
(
img
,
zero_pixels_are_background
(),
neighbors_8
(),
connected_if_both_not_zero
(),
labels
);
DLIB_TEST
(
num
==
4
);
DLIB_TEST
(
labels
.
nr
()
==
img
.
nr
());
DLIB_TEST
(
labels
.
nc
()
==
img
.
nc
());
const
unsigned
char
l1
=
labels
[
rect1
.
top
()][
rect1
.
left
()];
const
unsigned
char
l2
=
labels
[
rect2
.
top
()][
rect2
.
left
()];
const
unsigned
char
l3
=
labels
[
rect3
.
top
()][
rect3
.
left
()];
DLIB_TEST
(
l1
!=
0
&&
l2
!=
0
&&
l3
!=
0
);
DLIB_TEST
(
l1
!=
l2
&&
l1
!=
l3
&&
l2
!=
l3
);
for
(
long
r
=
0
;
r
<
labels
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
labels
.
nc
();
++
c
)
{
if
(
rect1
.
contains
(
c
,
r
))
{
DLIB_TEST
(
labels
[
r
][
c
]
==
l1
);
}
else
if
(
rect2
.
contains
(
c
,
r
))
{
DLIB_TEST
(
labels
[
r
][
c
]
==
l2
);
}
else
if
(
rect3
.
contains
(
c
,
r
))
{
DLIB_TEST
(
labels
[
r
][
c
]
==
l3
);
}
else
{
DLIB_TEST
(
labels
[
r
][
c
]
==
0
);
}
}
}
}
void
test_label_connected_blobs2
()
{
array2d
<
unsigned
char
>
img
;
img
.
set_size
(
400
,
401
);
assign_all_pixels
(
img
,
0
);
rectangle
rect1
,
rect2
,
rect3
;
rect1
=
centered_rect
(
99
,
120
,
50
,
70
);
rect2
=
centered_rect
(
199
,
80
,
34
,
68
);
rect3
=
centered_rect
(
249
,
180
,
120
,
78
);
fill_rect
(
img
,
rect1
,
255
);
fill_rect
(
img
,
rect2
,
253
);
fill_rect
(
img
,
rect3
,
255
);
array2d
<
unsigned
char
>
labels
;
unsigned
long
num
;
num
=
label_connected_blobs
(
img
,
nothing_is_background
(),
neighbors_4
(),
connected_if_equal
(),
labels
);
DLIB_TEST
(
num
==
5
);
DLIB_TEST
(
labels
.
nr
()
==
img
.
nr
());
DLIB_TEST
(
labels
.
nc
()
==
img
.
nc
());
const
unsigned
char
l0
=
labels
[
0
][
0
];
const
unsigned
char
l1
=
labels
[
rect1
.
top
()][
rect1
.
left
()];
const
unsigned
char
l2
=
labels
[
rect2
.
top
()][
rect2
.
left
()];
const
unsigned
char
l3
=
labels
[
rect3
.
top
()][
rect3
.
left
()];
DLIB_TEST
(
l0
!=
0
&&
l1
!=
0
&&
l2
!=
0
&&
l3
!=
0
);
DLIB_TEST
(
l1
!=
l2
&&
l1
!=
l3
&&
l2
!=
l3
&&
l0
!=
l1
&&
l0
!=
l2
&&
l0
!=
l3
);
for
(
long
r
=
0
;
r
<
labels
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
labels
.
nc
();
++
c
)
{
if
(
rect1
.
contains
(
c
,
r
))
{
DLIB_TEST
(
labels
[
r
][
c
]
==
l1
);
}
else
if
(
rect2
.
contains
(
c
,
r
))
{
DLIB_TEST
(
labels
[
r
][
c
]
==
l2
);
}
else
if
(
rect3
.
contains
(
c
,
r
))
{
DLIB_TEST
(
labels
[
r
][
c
]
==
l3
);
}
else
{
DLIB_TEST
(
labels
[
r
][
c
]
==
l0
);
}
}
}
}
class
image_tester
:
public
tester
{
public
:
...
...
@@ -1015,6 +1138,9 @@ namespace
test_filtering
<
int
>
(
true
,
1
);
test_filtering
<
int
>
(
false
,
3
);
test_filtering
<
int
>
(
true
,
3
);
test_label_connected_blobs
();
test_label_connected_blobs2
();
}
}
a
;
...
...
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