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
154f9e49
Commit
154f9e49
authored
Mar 11, 2015
by
Jack Culpepper
Browse files
add ability to return detection confidences and weight index to python
parent
154f4354
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
14 deletions
+93
-14
tools/python/src/object_detection.cpp
tools/python/src/object_detection.cpp
+12
-0
tools/python/src/simple_object_detector_py.h
tools/python/src/simple_object_detector_py.h
+81
-14
No files found.
tools/python/src/object_detection.cpp
View file @
154f9e49
...
@@ -383,6 +383,18 @@ ensures \n\
...
@@ -383,6 +383,18 @@ ensures \n\
ensures
\n
\
ensures
\n
\
- This function runs the object detector on the input image and returns
\n
\
- This function runs the object detector on the input image and returns
\n
\
a list of detections."
)
a list of detections."
)
.
def
(
"run"
,
&
type
::
run_detector3
,
(
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
\
default will be used."
)
.
def
(
"save"
,
save_simple_object_detector_py
,
(
arg
(
"detector_output_filename"
)),
"Save a simple_object_detector to the provided path."
)
.
def
(
"save"
,
save_simple_object_detector_py
,
(
arg
(
"detector_output_filename"
)),
"Save a simple_object_detector to the provided path."
)
.
def_pickle
(
serialize_pickle
<
type
>
());
.
def_pickle
(
serialize_pickle
<
type
>
());
}
}
...
...
tools/python/src/simple_object_detector_py.h
View file @
154f9e49
...
@@ -13,20 +13,47 @@ namespace dlib
...
@@ -13,20 +13,47 @@ namespace dlib
{
{
typedef
object_detector
<
scan_fhog_pyramid
<
pyramid_down
<
6
>
>
>
simple_object_detector
;
typedef
object_detector
<
scan_fhog_pyramid
<
pyramid_down
<
6
>
>
>
simple_object_detector
;
inline
void
split_rect_detections
(
std
::
vector
<
rect_detection
>&
rect_detections
,
std
::
vector
<
rectangle
>&
rectangles
,
std
::
vector
<
double
>&
detection_confidences
,
std
::
vector
<
int
>&
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_upscale
(
inline
std
::
vector
<
dlib
::
rectangle
>
run_detector_with_upscale
(
dlib
::
simple_object_detector
&
detector
,
dlib
::
simple_object_detector
&
detector
,
boost
::
python
::
object
img
,
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount
const
unsigned
int
upsampling_amount
,
std
::
vector
<
double
>&
detection_confidences
,
std
::
vector
<
int
>&
weight_indices
)
)
{
{
pyramid_down
<
2
>
pyr
;
pyramid_down
<
2
>
pyr
;
std
::
vector
<
rectangle
>
rectangles
;
std
::
vector
<
rect_detection
>
rect_detections
;
if
(
is_gray_python_image
(
img
))
if
(
is_gray_python_image
(
img
))
{
{
array2d
<
unsigned
char
>
temp
;
array2d
<
unsigned
char
>
temp
;
if
(
upsampling_amount
==
0
)
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
else
{
{
...
@@ -38,10 +65,14 @@ namespace dlib
...
@@ -38,10 +65,14 @@ namespace dlib
pyramid_up
(
temp
);
pyramid_up
(
temp
);
}
}
std
::
vector
<
rectangle
>
res
=
detector
(
temp
);
detector
(
temp
,
rect_detections
,
0.0
);
for
(
unsigned
long
i
=
0
;
i
<
res
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
rect_detections
.
size
();
++
i
)
res
[
i
]
=
pyr
.
rect_down
(
res
[
i
],
upsampling_amount
);
rect_detections
[
i
].
rect
=
pyr
.
rect_down
(
rect_detections
[
i
].
rect
,
return
res
;
upsampling_amount
);
split_rect_detections
(
rect_detections
,
rectangles
,
detection_confidences
,
weight_indices
);
return
rectangles
;
}
}
}
}
else
if
(
is_rgb_python_image
(
img
))
else
if
(
is_rgb_python_image
(
img
))
...
@@ -49,7 +80,10 @@ namespace dlib
...
@@ -49,7 +80,10 @@ namespace dlib
array2d
<
rgb_pixel
>
temp
;
array2d
<
rgb_pixel
>
temp
;
if
(
upsampling_amount
==
0
)
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
else
{
{
...
@@ -61,10 +95,14 @@ namespace dlib
...
@@ -61,10 +95,14 @@ namespace dlib
pyramid_up
(
temp
);
pyramid_up
(
temp
);
}
}
std
::
vector
<
rectangle
>
res
=
detector
(
temp
);
detector
(
temp
,
rect_detections
,
0.0
);
for
(
unsigned
long
i
=
0
;
i
<
res
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
rect_detections
.
size
();
++
i
)
res
[
i
]
=
pyr
.
rect_down
(
res
[
i
],
upsampling_amount
);
rect_detections
[
i
].
rect
=
pyr
.
rect_down
(
rect_detections
[
i
].
rect
,
return
res
;
upsampling_amount
);
split_rect_detections
(
rect_detections
,
rectangles
,
detection_confidences
,
weight_indices
);
return
rectangles
;
}
}
}
}
else
else
...
@@ -82,11 +120,40 @@ namespace dlib
...
@@ -82,11 +120,40 @@ namespace dlib
simple_object_detector_py
(
simple_object_detector
&
_detector
,
unsigned
int
_upsampling_amount
)
:
simple_object_detector_py
(
simple_object_detector
&
_detector
,
unsigned
int
_upsampling_amount
)
:
detector
(
_detector
),
upsampling_amount
(
_upsampling_amount
)
{}
detector
(
_detector
),
upsampling_amount
(
_upsampling_amount
)
{}
std
::
vector
<
dlib
::
rectangle
>
run_detector1
(
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount_
)
std
::
vector
<
dlib
::
rectangle
>
run_detector1
(
boost
::
python
::
object
img
,
{
return
run_detector_with_upscale
(
detector
,
img
,
upsampling_amount_
);
}
const
unsigned
int
upsampling_amount_
)
{
std
::
vector
<
double
>
detection_confidences
;
std
::
vector
<
int
>
weight_indices
;
return
run_detector_with_upscale
(
detector
,
img
,
upsampling_amount_
,
detection_confidences
,
weight_indices
);
}
std
::
vector
<
dlib
::
rectangle
>
run_detector2
(
boost
::
python
::
object
img
)
std
::
vector
<
dlib
::
rectangle
>
run_detector2
(
boost
::
python
::
object
img
)
{
return
run_detector_with_upscale
(
detector
,
img
,
upsampling_amount
);
}
{
std
::
vector
<
double
>
detection_confidences
;
std
::
vector
<
int
>
weight_indices
;
return
run_detector_with_upscale
(
detector
,
img
,
upsampling_amount
,
detection_confidences
,
weight_indices
);
}
boost
::
python
::
tuple
run_detector3
(
boost
::
python
::
object
img
,
const
unsigned
int
upsampling_amount_
)
{
boost
::
python
::
tuple
t
;
std
::
vector
<
double
>
detection_confidences
;
std
::
vector
<
int
>
weight_indices
;
std
::
vector
<
rectangle
>
rectangles
;
rectangles
=
run_detector_with_upscale
(
detector
,
img
,
upsampling_amount
,
detection_confidences
,
weight_indices
);
return
boost
::
python
::
make_tuple
(
rectangles
,
detection_confidences
,
weight_indices
);
}
};
};
}
}
...
...
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