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
290de9b4
"src/array/vscode:/vscode.git/clone" did not exist on "3d179846d51d9695ed1b196c11210e17688c24e3"
Commit
290de9b4
authored
Sep 07, 2011
by
Davis King
Browse files
Added some functions for creating detection templates.
parent
51c0c148
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
209 additions
and
0 deletions
+209
-0
dlib/image_processing.h
dlib/image_processing.h
+1
-0
dlib/image_processing/detection_template_tools.h
dlib/image_processing/detection_template_tools.h
+113
-0
dlib/image_processing/detection_template_tools_abstract.h
dlib/image_processing/detection_template_tools_abstract.h
+95
-0
No files found.
dlib/image_processing.h
View file @
290de9b4
...
...
@@ -5,6 +5,7 @@
#include "image_processing/scan_image.h"
#include "image_processing/scan_image_pyramid.h"
#include "image_processing/detection_template_tools.h"
#endif // DLIB_IMAGE_PROCESSInG_H___
...
...
dlib/image_processing/detection_template_tools.h
0 → 100644
View file @
290de9b4
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_DETECTION_TEMPlATE_TOOLS_H__
#define DLIB_DETECTION_TEMPlATE_TOOLS_H__
#include "detection_template_tools_abstract.h"
#include "../geometry.h"
#include "../matrix.h"
#include <utility>
#include <vector>
#include <cmath>
namespace
dlib
{
// ----------------------------------------------------------------------------------------
inline
rectangle
compute_box_dimensions
(
const
double
width_to_height_ratio
,
const
double
area
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
width_to_height_ratio
>
0
&&
area
>
0
,
"
\t
rectangle compute_box_dimensions()"
<<
"
\n\t
Invalid arguments were given to this function. "
<<
"
\n\t
width_to_height_ratio: "
<<
width_to_height_ratio
<<
"
\n\t
area: "
<<
area
);
/*
width*height == area
width/height == width_to_height_ratio
*/
using
namespace
std
;
const
int
height
=
std
::
floor
(
std
::
sqrt
(
area
/
width_to_height_ratio
)
+
0.5
);
const
int
width
=
std
::
floor
(
area
/
height
+
0.5
);
return
centered_rect
(
0
,
0
,
width
,
height
);
}
// ----------------------------------------------------------------------------------------
inline
std
::
vector
<
rectangle
>
create_single_box_detection_template
(
const
rectangle
&
object_box
)
{
std
::
vector
<
rectangle
>
temp
;
temp
.
push_back
(
object_box
);
return
temp
;
}
// ----------------------------------------------------------------------------------------
inline
std
::
vector
<
rectangle
>
create_overlapped_2x2_detection_template
(
const
rectangle
&
object_box
)
{
std
::
vector
<
rectangle
>
result
;
const
point
c
=
center
(
object_box
);
result
.
push_back
(
rectangle
()
+
c
+
object_box
.
tl_corner
()
+
object_box
.
tr_corner
());
result
.
push_back
(
rectangle
()
+
c
+
object_box
.
bl_corner
()
+
object_box
.
br_corner
());
result
.
push_back
(
rectangle
()
+
c
+
object_box
.
tl_corner
()
+
object_box
.
bl_corner
());
result
.
push_back
(
rectangle
()
+
c
+
object_box
.
tr_corner
()
+
object_box
.
br_corner
());
return
result
;
}
// ----------------------------------------------------------------------------------------
inline
std
::
vector
<
rectangle
>
create_grid_detection_template
(
const
rectangle
&
object_box
,
unsigned
int
cells_x
,
unsigned
int
cells_y
)
{
// make sure requires clause is not broken
DLIB_ASSERT
(
cells_x
>
0
&&
cells_y
>
0
,
"
\t
std::vector<rectangle> create_grid_detection_template()"
<<
"
\n\t
The number of cells along a dimension can't be zero. "
<<
"
\n\t
cells_x: "
<<
cells_x
<<
"
\n\t
cells_y: "
<<
cells_y
);
std
::
vector
<
rectangle
>
result
;
const
matrix
<
double
,
1
>
x
=
linspace
(
object_box
.
left
(),
object_box
.
right
(),
cells_x
+
1
);
const
matrix
<
double
,
1
>
y
=
linspace
(
object_box
.
top
(),
object_box
.
bottom
(),
cells_y
+
1
);
for
(
long
j
=
0
;
j
+
1
<
y
.
size
();
++
j
)
{
for
(
long
i
=
0
;
i
+
1
<
x
.
size
();
++
i
)
{
const
dlib
::
vector
<
double
,
2
>
tl
(
x
(
i
),
y
(
j
));
const
dlib
::
vector
<
double
,
2
>
br
(
x
(
i
+
1
),
y
(
j
+
1
));
result
.
push_back
(
rectangle
(
tl
,
br
));
}
}
return
result
;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_DETECTION_TEMPlATE_TOOLS_H__
dlib/image_processing/detection_template_tools_abstract.h
0 → 100644
View file @
290de9b4
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_DETECTION_TEMPlATE_TOOLS_ABSTRACT_H__
#ifdef DLIB_DETECTION_TEMPlATE_TOOLS_ABSTRACT_H__
#include "../geometry.h"
#include <utility>
#include <vector>
namespace
dlib
{
// ----------------------------------------------------------------------------------------
rectangle
compute_box_dimensions
(
const
double
width_to_height_ratio
,
const
double
area
);
/*!
requires
- area > 0
- width_to_height_ratio > 0
ensures
- returns a rectangle with the given area and width_to_height_ratio.
- In particular, returns a rectangle R such that:
- R.area() == area (to within integer precision)
- R.width()/R.height() == width_to_height_ratio (to within integer precision)
- center(R) == point(0,0)
!*/
// ----------------------------------------------------------------------------------------
std
::
vector
<
rectangle
>
create_single_box_detection_template
(
const
rectangle
&
object_box
);
/*!
ensures
- returns a vector that contains only object_box.
- In particular, returns a vector V such that:
- V.size() == 1
- V[0] == object_box
!*/
// ----------------------------------------------------------------------------------------
std
::
vector
<
rectangle
>
create_overlapped_2x2_detection_template
(
const
rectangle
&
object_box
);
/*!
ensures
- Divides object_box up into four overlapping regions, the
top half, bottom half, left half, and right half. These
four rectangles are returned inside a std::vector.
- In particular, returns a vector V such that:
- V.size() == 4
- V[0] == top half of object_box
- V[1] == bottom half of object_box
- V[2] == left half of object_box
- V[3] == right half of object_box
- for all valid i: object_box.contains(V[i]) == true
!*/
// ----------------------------------------------------------------------------------------
std
::
vector
<
rectangle
>
create_grid_detection_template
(
const
rectangle
&
object_box
,
unsigned
int
cells_x
,
unsigned
int
cells_y
);
/*!
requires
- cells_x > 0
- cells_y > 0
ensures
- Divides object_box up into a grid and returns a vector
containing all the rectangles corresponding to elements
of the grid. Moreover, the grid will be cells_x elements
wide and cells_y elements tall.
- In particular, returns a vector V such that:
- V.size() == cells_x*cells_y
- for all valid i:
- object_box.contains(V[i]) == true
- V[i] == The rectangle corresponding to the ith grid
element.
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_DETECTION_TEMPlATE_TOOLS_ABSTRACT_H__
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