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
c0eaf1fd
Commit
c0eaf1fd
authored
Dec 08, 2014
by
Davis King
Browse files
Added hough transform unit tests
parent
81ddd13b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
3 deletions
+62
-3
dlib/test/image.cpp
dlib/test/image.cpp
+62
-3
No files found.
dlib/test/image.cpp
View file @
c0eaf1fd
...
...
@@ -1611,12 +1611,12 @@ namespace
if
(
get_rect
(
out
).
contains
(
rect
))
{
T
val
=
sum
(
pointwise_multiply
(
filt
,
subm
(
mat
(
img
),
rect
)));
DLIB_
CASSERT
(
val
==
out
[
r
][
c
],
"err: "
<<
val
-
out
[
r
][
c
]);
DLIB_
CASSER
T
(
area
.
contains
(
point
(
c
,
r
))
,
""
);
DLIB_
TEST_MSG
(
val
==
out
[
r
][
c
],
"err: "
<<
val
-
out
[
r
][
c
]);
DLIB_
TES
T
(
area
.
contains
(
point
(
c
,
r
)));
}
else
{
DLIB_
CASSER
T
(
!
area
.
contains
(
point
(
c
,
r
))
,
""
);
DLIB_
TES
T
(
!
area
.
contains
(
point
(
c
,
r
)));
}
}
}
...
...
@@ -1671,6 +1671,64 @@ namespace
}
}
// ----------------------------------------------------------------------------------------
void
run_hough_test
()
{
array2d
<
unsigned
char
>
img
(
300
,
300
);
for
(
int
k
=
-
2
;
k
<=
2
;
++
k
)
{
print_spinner
();
running_stats
<
double
>
rs
;
array2d
<
int
>
himg
;
hough_transform
ht
(
200
+
k
);
double
angle1
=
0
;
double
angle2
=
0
;
const
int
len
=
90
;
// Draw a bunch of random lines, hough transform them, then make sure the hough
// transform detects them accurately.
for
(
int
i
=
0
;
i
<
500
;
++
i
)
{
point
cent
=
center
(
get_rect
(
img
));
point
arc
=
cent
+
point
(
len
,
0
);
arc
=
rotate_point
(
cent
,
arc
,
angle1
);
point
l
=
arc
+
point
(
500
,
0
);
point
r
=
arc
-
point
(
500
,
0
);
l
=
rotate_point
(
arc
,
l
,
angle2
);
r
=
rotate_point
(
arc
,
r
,
angle2
);
angle1
+=
pi
/
13
;
angle2
+=
pi
/
40
;
assign_all_pixels
(
img
,
0
);
draw_line
(
img
,
l
,
r
,
255
);
rectangle
box
=
translate_rect
(
get_rect
(
ht
),
point
(
50
,
50
));
ht
(
img
,
box
,
himg
);
point
p
=
max_point
(
mat
(
himg
));
DLIB_TEST
(
himg
[
p
.
y
()][
p
.
x
()]
>
255
*
3
);
l
-=
point
(
50
,
50
);
r
-=
point
(
50
,
50
);
std
::
pair
<
point
,
point
>
line
=
ht
.
get_line
(
p
);
// make sure the best scoring hough point matches the line we drew.
double
dist1
=
distance_to_line
(
make_pair
(
l
,
r
),
line
.
first
);
double
dist2
=
distance_to_line
(
make_pair
(
l
,
r
),
line
.
second
);
//cout << "DIST1: " << dist1 << endl;
//cout << "DIST2: " << dist2 << endl;
rs
.
add
(
dist1
);
rs
.
add
(
dist2
);
DLIB_TEST
(
dist1
<
2.5
);
DLIB_TEST
(
dist2
<
2.5
);
}
//cout << "rs.mean(): " << rs.mean() << endl;
DLIB_TEST
(
rs
.
mean
()
<
0.7
);
}
}
// ----------------------------------------------------------------------------------------
class
image_tester
:
public
tester
...
...
@@ -1686,6 +1744,7 @@ namespace
)
{
image_test
();
run_hough_test
();
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