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
a97a2c90
Commit
a97a2c90
authored
Mar 03, 2013
by
Davis King
Browse files
simplified SURF example program
parent
9160565f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
45 deletions
+26
-45
examples/surf_ex.cpp
examples/surf_ex.cpp
+26
-45
No files found.
examples/surf_ex.cpp
View file @
a97a2c90
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This is a simple example illustrating the use of the get_surf_points()
function. It pulls out the first 100 SURF points from an input image
and displays them on the screen as an overlay
on the image.
This is a simple example illustrating the use of the get_surf_points()
function. It
pulls out SURF points from an input image and displays them on the screen as an overlay
on the image.
For a description of the SURF algorithm you should consult the following
papers:
For a description of the SURF algorithm you should consult the following papers:
This is the original paper which introduced the algorithm:
SURF: Speeded Up Robust Features
By Herbert Bay, Tinne Tuytelaars, and Luc Van Gool
...
...
@@ -18,7 +17,7 @@
#include <dlib/
gui_widge
ts.h>
#include <dlib/
image_keypoint/draw_surf_poin
ts.h>
#include <dlib/image_io.h>
#include <dlib/image_keypoint.h>
#include <fstream>
...
...
@@ -40,53 +39,35 @@ int main(int argc, char** argv)
return
1
;
}
// Here we declare an image object that can store rgb_pixels. Note that in
// dlib there is no explicit image object, just a 2D array and
// various pixel types.
// Here we declare an image object that can store rgb_pixels. Note that in dlib
// there is no explicit image object, just a 2D array and various pixel types.
array2d
<
rgb_pixel
>
img
;
// Now load the image file into our image. If something is wrong then
// load_image() will throw an exception. Also, if you linked with libpng
// and libjpeg then load_image() can load PNG and JPEG files in addition
// to BMP files.
// Now load the image file into our image. If something is wrong then load_image()
// will throw an exception. Also, if you linked with libpng and libjpeg then
// load_image() can load PNG and JPEG files in addition to BMP files.
load_image
(
img
,
argv
[
1
]);
// get the 100 strongest SURF points from the image
std
::
vector
<
surf_point
>
sp
=
get_surf_points
(
img
,
100
);
// Get SURF points from the image. Note that get_surf_points() has some optional
// arguments that allow you to control the number of points you get back. Here we
// simply take the default.
std
::
vector
<
surf_point
>
sp
=
get_surf_points
(
img
);
cout
<<
"number of SURF points found: "
<<
sp
.
size
()
<<
endl
;
// create a window to display the input image and the SURF boxes. (Note that
// you can zoom into the window by holding CTRL and scrolling the mouse wheel)
image_window
my_window
(
img
);
// Now lets draw some rectangles on top of the image so we can see where
// SURF found its points.
for
(
unsigned
long
i
=
0
;
i
<
sp
.
size
();
++
i
)
if
(
sp
.
size
()
>
0
)
{
// Pull out the info from the SURF point relevant to figuring out
// where its rotated box should be. This is the box it extracted
// the SURF descriptor vector from.
const
unsigned
long
box_size
=
static_cast
<
unsigned
long
>
(
sp
[
i
].
p
.
scale
*
20
);
const
double
ang
=
sp
[
i
].
angle
;
const
point
center
(
sp
[
i
].
p
.
center
);
const
rectangle
rect
=
centered_rect
(
center
,
box_size
,
box_size
);
// Rotate the 4 corners of the rectangle
const
point
p1
=
rotate_point
(
center
,
rect
.
tl_corner
(),
ang
);
const
point
p2
=
rotate_point
(
center
,
rect
.
tr_corner
(),
ang
);
const
point
p3
=
rotate_point
(
center
,
rect
.
bl_corner
(),
ang
);
const
point
p4
=
rotate_point
(
center
,
rect
.
br_corner
(),
ang
);
// Draw the sides of the box as red lines
my_window
.
add_overlay
(
p1
,
p2
,
rgb_pixel
(
255
,
0
,
0
));
my_window
.
add_overlay
(
p1
,
p3
,
rgb_pixel
(
255
,
0
,
0
));
my_window
.
add_overlay
(
p4
,
p2
,
rgb_pixel
(
255
,
0
,
0
));
my_window
.
add_overlay
(
p4
,
p3
,
rgb_pixel
(
255
,
0
,
0
));
// Draw a line from the center to the top side so we can see how the box is oriented.
// Also make this line green.
my_window
.
add_overlay
(
center
,
(
p1
+
p2
)
/
2
,
rgb_pixel
(
0
,
255
,
0
));
// A surf_point object contains a lot of information describing each point.
// The most important fields are shown below:
cout
<<
"center of first SURF point: "
<<
sp
[
0
].
p
.
center
<<
endl
;
cout
<<
"pyramid scale: "
<<
sp
[
0
].
p
.
scale
<<
endl
;
cout
<<
"SURF descriptor:
\n
"
<<
sp
[
0
].
des
<<
endl
;
}
// Create a window to display the input image and the SURF points. (Note that
// you can zoom into the window by holding CTRL and scrolling the mouse wheel)
image_window
my_window
(
img
);
draw_surf_points
(
my_window
,
sp
);
// wait until the user closes the window before we let the program
// terminate.
my_window
.
wait_until_closed
();
...
...
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