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
ad99a666
Commit
ad99a666
authored
Dec 09, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added an example program for the new hough_transform object.
parent
bb673f40
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
0 deletions
+85
-0
CMakeLists.txt
examples/CMakeLists.txt
+1
-0
hough_transform_ex.cpp
examples/hough_transform_ex.cpp
+84
-0
No files found.
examples/CMakeLists.txt
View file @
ad99a666
...
...
@@ -39,6 +39,7 @@ add_example(fhog_object_detector_ex)
add_example
(
file_to_code_ex
)
add_example
(
graph_labeling_ex
)
add_example
(
gui_api_ex
)
add_example
(
hough_transform_ex
)
add_example
(
image_ex
)
add_example
(
integrate_function_adapt_simp_ex
)
add_example
(
iosockstream_ex
)
...
...
examples/hough_transform_ex.cpp
0 → 100644
View file @
ad99a666
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This is an example illustrating the use of the Hough transform tool in the
dlib C++ Library.
In this example we are going to draw a line on an image and then use the
Hough transform to detect the location of the line. Moreover, we do this in
a loop that changes the line's position slightly each iteration, which gives
a pretty animation of the Hough transform in action.
*/
#include <dlib/gui_widgets.h>
#include <dlib/image_transforms.h>
using
namespace
dlib
;
int
main
()
{
// First let's make a 400x400 image. This will form the input to the Hough transform.
array2d
<
unsigned
char
>
img
(
400
,
400
);
// Now we make a hough_transform object. The 300 here means that the Hough transform
// will operate on a 300x300 subwindow of its input image.
hough_transform
ht
(
300
);
image_window
win
,
win2
;
double
angle1
=
0
;
double
angle2
=
0
;
while
(
true
)
{
// Generate a line segment that is rotating around inside the image. The line is
// generated based on the values in angle1 and angle2. So each iteration creates a
// slightly different line.
angle1
+=
pi
/
130
;
angle2
+=
pi
/
400
;
const
point
cent
=
center
(
get_rect
(
img
));
// A point 90 pixels away from the center of the image but rotated by angle1.
const
point
arc
=
rotate_point
(
cent
,
cent
+
point
(
90
,
0
),
angle1
);
// Now make a line that goes though arc but rotate it by angle2.
const
point
l
=
rotate_point
(
arc
,
arc
+
point
(
500
,
0
),
angle2
);
const
point
r
=
rotate_point
(
arc
,
arc
-
point
(
500
,
0
),
angle2
);
// Next, blank out the input image and then draw our line on it.
assign_all_pixels
(
img
,
0
);
draw_line
(
img
,
l
,
r
,
255
);
const
point
offset
(
50
,
50
);
array2d
<
int
>
himg
;
// pick the window inside img on which we will run the Hough transform.
const
rectangle
box
=
translate_rect
(
get_rect
(
ht
),
offset
);
// Now let's compute the hough transform for a subwindow in the image. In
// particular, we run it on the 300x300 subwindow with an upper left corner at the
// pixel point(50,50). The output is stored in himg.
ht
(
img
,
box
,
himg
);
// Now that we have the transformed image, the Hough image pixel with the largest
// value should indicate where the line is. So we find the coordinates of the
// largest pixel:
point
p
=
max_point
(
mat
(
himg
));
// And then ask the ht object for the line segment in the original image that
// corresponds to this point in Hough transform space.
std
::
pair
<
point
,
point
>
line
=
ht
.
get_line
(
p
);
// Finally, let's display all these things on the screen. We copy the original
// input image into a color image and then draw the detected line on top in red.
array2d
<
rgb_pixel
>
temp
;
assign_image
(
temp
,
img
);
// Note that we must offset the output line to account for our offset subwindow.
// We do this by just adding in the offset to the line endpoints.
draw_line
(
temp
,
line
.
first
+
offset
,
line
.
second
+
offset
,
rgb_pixel
(
255
,
0
,
0
));
win
.
clear_overlay
();
win
.
set_image
(
temp
);
// Also show the subwindow we ran the Hough transform on as a green box. You will
// see that the detected line is exactly contained within this box and also
// overlaps the original line.
win
.
add_overlay
(
box
,
rgb_pixel
(
0
,
255
,
0
));
// We can also display the Hough transform itself using the jet color scheme.
win2
.
set_image
(
jet
(
himg
));
}
}
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