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
c81c5e2f
Commit
c81c5e2f
authored
Sep 07, 2011
by
Davis King
Browse files
Added the object_detector object.
parent
290de9b4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
337 additions
and
0 deletions
+337
-0
dlib/image_processing.h
dlib/image_processing.h
+1
-0
dlib/image_processing/object_detector.h
dlib/image_processing/object_detector.h
+223
-0
dlib/image_processing/object_detector_abstract.h
dlib/image_processing/object_detector_abstract.h
+113
-0
No files found.
dlib/image_processing.h
View file @
c81c5e2f
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include "image_processing/scan_image.h"
#include "image_processing/scan_image.h"
#include "image_processing/scan_image_pyramid.h"
#include "image_processing/scan_image_pyramid.h"
#include "image_processing/detection_template_tools.h"
#include "image_processing/detection_template_tools.h"
#include "image_processing/object_detector.h"
#endif // DLIB_IMAGE_PROCESSInG_H___
#endif // DLIB_IMAGE_PROCESSInG_H___
...
...
dlib/image_processing/object_detector.h
0 → 100644
View file @
c81c5e2f
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_OBJECT_DeTECTOR_H__
#define DLIB_OBJECT_DeTECTOR_H__
#include "object_detector_abstract.h"
#include "../matrix.h"
#include "../geometry.h"
#include <vector>
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
,
typename
overlap_tester_type
>
class
object_detector
{
public:
object_detector
(
);
object_detector
(
const
object_detector
&
item
);
object_detector
(
const
image_scanner_type
&
scanner_
,
const
overlap_tester_type
&
overlap_tester_
,
const
matrix
<
double
,
0
,
1
>&
w_
);
object_detector
&
operator
=
(
const
object_detector
&
item
);
template
<
typename
image_type
>
std
::
vector
<
rectangle
>
operator
()
(
const
image_type
&
img
)
const
;
template
<
typename
T
,
typename
U
>
friend
void
serialize
(
const
object_detector
<
T
,
U
>&
item
,
std
::
ostream
&
out
);
template
<
typename
T
,
typename
U
>
friend
void
deserialize
(
object_detector
<
T
,
U
>&
item
,
std
::
istream
&
in
);
private:
bool
overlaps_any_box
(
const
std
::
vector
<
rectangle
>&
rects
,
const
dlib
::
rectangle
&
rect
)
const
{
for
(
unsigned
long
i
=
0
;
i
<
rects
.
size
();
++
i
)
{
if
(
boxes_overlap
(
rects
[
i
],
rect
))
return
true
;
}
return
false
;
}
overlap_tester_type
boxes_overlap
;
matrix
<
double
,
0
,
1
>
w
;
mutable
image_scanner_type
scanner
;
};
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
U
>
void
serialize
(
const
object_detector
<
T
,
U
>&
item
,
std
::
ostream
&
out
)
{
T
scanner
;
scanner
.
copy_configuration
(
item
.
scanner
);
serialize
(
scanner
,
out
);
serialize
(
item
.
w
,
out
);
serialize
(
item
.
boxes_overlap
,
out
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
U
>
void
deserialize
(
object_detector
<
T
,
U
>&
item
,
std
::
istream
&
in
)
{
deserialize
(
item
.
scanner
,
in
);
deserialize
(
item
.
w
,
in
);
deserialize
(
item
.
boxes_overlap
,
in
);
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
// object_detector member functions
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
,
typename
overlap_tester_type
>
object_detector
<
image_scanner_type
,
overlap_tester_type
>::
object_detector
(
)
{
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
,
typename
overlap_tester_type
>
object_detector
<
image_scanner_type
,
overlap_tester_type
>::
object_detector
(
const
object_detector
&
item
)
{
boxes_overlap
=
item
.
boxes_overlap
;
w
=
item
.
w
;
scanner
.
copy_configuration
(
item
.
scanner
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
,
typename
overlap_tester_type
>
object_detector
<
image_scanner_type
,
overlap_tester_type
>::
object_detector
(
const
image_scanner_type
&
scanner_
,
const
overlap_tester_type
&
overlap_tester
,
const
matrix
<
double
,
0
,
1
>&
w_
)
:
boxes_overlap
(
overlap_tester
),
w
(
w_
)
{
scanner
.
copy_configuration
(
scanner_
);
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
,
typename
overlap_tester_type
>
object_detector
<
image_scanner_type
,
overlap_tester_type
>&
object_detector
<
image_scanner_type
,
overlap_tester_type
>::
operator
=
(
const
object_detector
&
item
)
{
if
(
this
==
&
item
)
return
*
this
;
boxes_overlap
=
item
.
boxes_overlap
;
w
=
item
.
w
;
scanner
.
copy_configuration
(
item
.
scanner
);
return
*
this
;
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
,
typename
overlap_tester_type
>
template
<
typename
image_type
>
std
::
vector
<
rectangle
>
object_detector
<
image_scanner_type
,
overlap_tester_type
>::
operator
()
(
const
image_type
&
img
)
const
{
std
::
vector
<
rectangle
>
final_dets
;
if
(
w
.
size
()
!=
0
)
{
std
::
vector
<
std
::
pair
<
double
,
rectangle
>
>
dets
;
const
double
thresh
=
w
(
scanner
.
get_num_dimensions
());
std
::
cout
<<
"!!!!! thresh: "
<<
thresh
<<
std
::
endl
;
scanner
.
load
(
img
);
scanner
.
detect
(
w
,
dets
,
thresh
);
std
::
cout
<<
"dets.size(): "
<<
dets
.
size
()
<<
std
::
endl
;
for
(
unsigned
long
i
=
0
;
i
<
dets
.
size
()
&&
final_dets
.
size
()
<
100
;
++
i
)
{
if
(
overlaps_any_box
(
final_dets
,
dets
[
i
].
second
))
continue
;
final_dets
.
push_back
(
dets
[
i
].
second
);
}
}
return
final_dets
;
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_OBJECT_DeTECTOR_H__
dlib/image_processing/object_detector_abstract.h
0 → 100644
View file @
c81c5e2f
// Copyright (C) 2011 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_OBJECT_DeTECTOR_ABSTRACT_H__
#ifdef DLIB_OBJECT_DeTECTOR_ABSTRACT_H__
#include "../matrix.h"
#include "../geometry.h"
#include <vector>
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
image_scanner_type
,
typename
overlap_tester_type
>
class
object_detector
{
/*!
WHAT THIS OBJECT REPRESENTS
!*/
public:
object_detector
(
);
/*!
ensures
- This detector won't generate any detections when
presented with an image.
!*/
object_detector
(
const
object_detector
&
item
);
/*!
ensures
- #*this is a copy of item
!*/
object_detector
(
const
image_scanner_type
&
scanner_
,
const
overlap_tester_type
&
overlap_tester_
,
const
matrix
<
double
,
0
,
1
>&
w_
);
/*!
requires
- w_.size() == scanner_.get_num_dimensions() + 1
- scanner_.num_detection_templates() > 0
ensures
- Initializes this detector... TODO describe
- when #*this is used to detect objects, the set of
output detections will never contain any overlaps
with respect to overlap_tester_. That is, for all
pairs of returned detections A and B, we will always
have: overlap_tester_(A,B) == false
!*/
object_detector
&
operator
=
(
const
object_detector
&
item
);
/*!
ensures
- #*this is a copy of item
- returns #*this
!*/
template
<
typename
image_type
>
std
::
vector
<
rectangle
>
operator
()
(
const
image_type
&
img
)
const
;
/*!
requires
- image_type == is an implementation of array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type>::has_alpha == false
ensures
- performs object detection on the given image and returns a
vector which indicates the locations of all detected objects.
!*/
};
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
U
>
void
serialize
(
const
object_detector
<
T
,
U
>&
item
,
std
::
ostream
&
out
);
/*!
provides serialization support
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
typename
U
>
void
deserialize
(
object_detector
<
T
,
U
>&
item
,
std
::
istream
&
in
);
/*!
provides deserialization support
!*/
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_OBJECT_DeTECTOR_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