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
c00edf8c
Commit
c00edf8c
authored
Mar 29, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'jackculpepper-py_det_conf_and_idx'
parents
edb85555
216eb3f3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
118 additions
and
16 deletions
+118
-16
face_detector_scores_idx.py
python_examples/face_detector_scores_idx.py
+13
-0
object_detection.cpp
tools/python/src/object_detection.cpp
+13
-1
simple_object_detector_py.h
tools/python/src/simple_object_detector_py.h
+92
-15
No files found.
python_examples/face_detector_scores_idx.py
0 → 100644
View file @
c00edf8c
from
PIL
import
Image
import
numpy
as
np
import
dlib
img
=
np
.
array
(
Image
.
open
(
'../examples/faces/2008_002506.jpg'
))
detector
=
dlib
.
get_frontal_face_detector
()
dets
,
scores
,
idx
=
detector
.
run
(
img
,
1
)
for
i
,
d
in
enumerate
(
dets
):
print
d
,
scores
[
i
],
idx
[
i
]
tools/python/src/object_detection.cpp
View file @
c00edf8c
...
...
@@ -342,7 +342,7 @@ ensures \n\
"Loads an object detector from a file that contains the output of the
\n
\
train_simple_object_detector() routine or a serialized C++ object of type
\n
\
object_detector<scan_fhog_pyramid<pyramid_down<6>>>."
)
.
def
(
"__call__"
,
run_detector_with_upscale
,
(
arg
(
"image"
),
arg
(
"upsample_num_times"
)
=
0
),
.
def
(
"__call__"
,
run_detector_with_upscale
2
,
(
arg
(
"image"
),
arg
(
"upsample_num_times"
)
=
0
),
"requires
\n
\
- image is a numpy ndarray containing either an 8bit grayscale or RGB
\n
\
image.
\n
\
...
...
@@ -350,6 +350,18 @@ object_detector<scan_fhog_pyramid<pyramid_down<6>>>.")
ensures
\n
\
- This function runs the object detector on the input image and returns
\n
\
a list of detections.
\n
\
- Upsamples the image upsample_num_times before running the basic
\n
\
detector. If you don't know how many times you want to upsample then
\n
\
don't provide a value for upsample_num_times and an appropriate
\n
\
default will be used."
)
.
def
(
"run"
,
run_rect_detector
,
(
arg
(
"image"
),
arg
(
"upsample_num_times"
)),
"requires
\n
\
- image is a numpy ndarray containing either an 8bit grayscale or RGB
\n
\
image.
\n
\
- upsample_num_times >= 0
\n
\
ensures
\n
\
- This function runs the object detector on the input image and returns
\n
\
a tuple of (list of detections, list of scores, list of weight_indices).
\n
\
- Upsamples the image upsample_num_times before running the basic
\n
\
detector. If you don't know how many times you want to upsample then
\n
\
don't provide a value for upsample_num_times and an appropriate
\n
\
...
...
tools/python/src/simple_object_detector_py.h
View file @
c00edf8c
...
...
@@ -13,20 +13,48 @@ namespace dlib
{
typedef
object_detector
<
scan_fhog_pyramid
<
pyramid_down
<
6
>
>
>
simple_object_detector
;
inline
std
::
vector
<
dlib
::
rectangle
>
run_detector_with_upscale
(
inline
void
split_rect_detections
(
std
::
vector
<
rect_detection
>&
rect_detections
,
std
::
vector
<
rectangle
>&
rectangles
,
std
::
vector
<
double
>&
detection_confidences
,
std
::
vector
<
double
>&
weight_indices
)
{
rectangles
.
clear
();
detection_confidences
.
clear
();
weight_indices
.
clear
();
for
(
unsigned
long
i
=
0
;
i
<
rect_detections
.
size
();
++
i
)
{
rectangles
.
push_back
(
rect_detections
[
i
].
rect
);
detection_confidences
.
push_back
(
rect_detections
[
i
].
detection_confidence
);
weight_indices
.
push_back
(
rect_detections
[
i
].
weight_index
);
}
}
inline
std
::
vector
<
dlib
::
rectangle
>
run_detector_with_upscale1
(
dlib
::
simple_object_detector
&
detector
,
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount
const
unsigned
int
upsampling_amount
,
std
::
vector
<
double
>&
detection_confidences
,
std
::
vector
<
double
>&
weight_indices
)
{
pyramid_down
<
2
>
pyr
;
std
::
vector
<
rectangle
>
rectangles
;
std
::
vector
<
rect_detection
>
rect_detections
;
if
(
is_gray_python_image
(
img
))
{
array2d
<
unsigned
char
>
temp
;
if
(
upsampling_amount
==
0
)
{
return
detector
(
numpy_gray_image
(
img
));
detector
(
numpy_gray_image
(
img
),
rect_detections
,
0
.
0
);
split_rect_detections
(
rect_detections
,
rectangles
,
detection_confidences
,
weight_indices
);
return
rectangles
;
}
else
{
...
...
@@ -38,10 +66,14 @@ namespace dlib
pyramid_up
(
temp
);
}
std
::
vector
<
rectangle
>
res
=
detector
(
temp
);
for
(
unsigned
long
i
=
0
;
i
<
res
.
size
();
++
i
)
res
[
i
]
=
pyr
.
rect_down
(
res
[
i
],
upsampling_amount
);
return
res
;
detector
(
temp
,
rect_detections
,
0
.
0
);
for
(
unsigned
long
i
=
0
;
i
<
rect_detections
.
size
();
++
i
)
rect_detections
[
i
].
rect
=
pyr
.
rect_down
(
rect_detections
[
i
].
rect
,
upsampling_amount
);
split_rect_detections
(
rect_detections
,
rectangles
,
detection_confidences
,
weight_indices
);
return
rectangles
;
}
}
else
if
(
is_rgb_python_image
(
img
))
...
...
@@ -49,7 +81,10 @@ namespace dlib
array2d
<
rgb_pixel
>
temp
;
if
(
upsampling_amount
==
0
)
{
return
detector
(
numpy_rgb_image
(
img
));
detector
(
numpy_rgb_image
(
img
),
rect_detections
,
0
.
0
);
split_rect_detections
(
rect_detections
,
rectangles
,
detection_confidences
,
weight_indices
);
return
rectangles
;
}
else
{
...
...
@@ -61,10 +96,14 @@ namespace dlib
pyramid_up
(
temp
);
}
std
::
vector
<
rectangle
>
res
=
detector
(
temp
);
for
(
unsigned
long
i
=
0
;
i
<
res
.
size
();
++
i
)
res
[
i
]
=
pyr
.
rect_down
(
res
[
i
],
upsampling_amount
);
return
res
;
detector
(
temp
,
rect_detections
,
0
.
0
);
for
(
unsigned
long
i
=
0
;
i
<
rect_detections
.
size
();
++
i
)
rect_detections
[
i
].
rect
=
pyr
.
rect_down
(
rect_detections
[
i
].
rect
,
upsampling_amount
);
split_rect_detections
(
rect_detections
,
rectangles
,
detection_confidences
,
weight_indices
);
return
rectangles
;
}
}
else
...
...
@@ -73,6 +112,37 @@ namespace dlib
}
}
inline
std
::
vector
<
dlib
::
rectangle
>
run_detector_with_upscale2
(
dlib
::
simple_object_detector
&
detector
,
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount
)
{
std
::
vector
<
double
>
detection_confidences
;
std
::
vector
<
double
>
weight_indices
;
return
run_detector_with_upscale1
(
detector
,
img
,
upsampling_amount
,
detection_confidences
,
weight_indices
);
}
inline
boost
::
python
::
tuple
run_rect_detector
(
dlib
::
simple_object_detector
&
detector
,
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount
)
{
boost
::
python
::
tuple
t
;
std
::
vector
<
double
>
detection_confidences
;
std
::
vector
<
double
>
weight_indices
;
std
::
vector
<
rectangle
>
rectangles
;
rectangles
=
run_detector_with_upscale1
(
detector
,
img
,
upsampling_amount
,
detection_confidences
,
weight_indices
);
return
boost
::
python
::
make_tuple
(
rectangles
,
detection_confidences
,
weight_indices
);
}
struct
simple_object_detector_py
{
simple_object_detector
detector
;
...
...
@@ -82,11 +152,18 @@ namespace dlib
simple_object_detector_py
(
simple_object_detector
&
_detector
,
unsigned
int
_upsampling_amount
)
:
detector
(
_detector
),
upsampling_amount
(
_upsampling_amount
)
{}
std
::
vector
<
dlib
::
rectangle
>
run_detector1
(
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount_
)
{
return
run_detector_with_upscale
(
detector
,
img
,
upsampling_amount_
);
}
std
::
vector
<
dlib
::
rectangle
>
run_detector1
(
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount_
)
{
return
run_detector_with_upscale2
(
detector
,
img
,
upsampling_amount_
);
}
std
::
vector
<
dlib
::
rectangle
>
run_detector2
(
boost
::
python
::
object
img
)
{
return
run_detector_with_upscale
(
detector
,
img
,
upsampling_amount
);
}
{
return
run_detector_with_upscale2
(
detector
,
img
,
upsampling_amount
);
}
};
}
...
...
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