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
8808006c
Commit
8808006c
authored
Dec 27, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated examples
parent
bfa7d1d7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
21 deletions
+32
-21
object_detector_advanced_ex.cpp
examples/object_detector_advanced_ex.cpp
+3
-6
object_detector_ex.cpp
examples/object_detector_ex.cpp
+29
-15
No files found.
examples/object_detector_advanced_ex.cpp
View file @
8808006c
...
...
@@ -199,7 +199,8 @@ int main()
typedef
scan_image_pyramid
<
pyramid_down_5_4
,
very_simple_feature_extractor
>
image_scanner_type
;
image_scanner_type
scanner
;
// Setup the sliding window box. Lets use a window with the same shape as the white boxes we
// Instead of using setup_grid_detection_templates() like in object_detector_ex.cpp, lets manually
// setup the sliding window box. We use a window with the same shape as the white boxes we
// are trying to detect.
const
rectangle
object_box
=
compute_box_dimensions
(
1
,
// width/height ratio
70
*
70
// box area
...
...
@@ -234,10 +235,6 @@ int main()
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
trainer
.
set_num_threads
(
4
);
// Set this to the number of processing cores on your machine.
// This line tells the algorithm that it is never OK for two detections to overlap. So
// this controls how the non-max suppression is performed and in general you can set this up
// any way you like.
trainer
.
set_overlap_tester
(
test_box_overlap
(
0
));
// The trainer will try and find the detector which minimizes the number of detection mistakes.
// This function controls how it decides if a detection output is a mistake or not. The bigger
...
...
@@ -246,7 +243,7 @@ int main()
// see that the detections aren't exactly on top of the white squares anymore. See the documentation
// for the structural_object_detection_trainer and structural_svm_object_detection_problem objects
// for a more detailed discussion of this parameter.
trainer
.
set_
overlap
_eps
(
0.95
);
trainer
.
set_
match
_eps
(
0.95
);
object_detector
<
image_scanner_type
>
detector
=
trainer
.
train
(
images
,
object_locations
);
...
...
examples/object_detector_ex.cpp
View file @
8808006c
...
...
@@ -78,6 +78,20 @@ void make_simple_test_data (
temp
.
push_back
(
centered_rect
(
point
(
123
,
121
),
70
,
70
));
fill_rect
(
images
[
2
],
temp
.
back
(),
255
);
// Paint the square white
object_locations
.
push_back
(
temp
);
// corrupt each image with random noise just to make this a little more
// challenging
dlib
::
rand
rnd
;
for
(
unsigned
long
i
=
0
;
i
<
images
.
size
();
++
i
)
{
for
(
long
r
=
0
;
r
<
images
[
i
].
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
images
[
i
].
nc
();
++
c
)
{
images
[
i
][
r
][
c
]
=
put_in_range
(
0
,
255
,
images
[
i
][
r
][
c
]
+
50
*
rnd
.
get_random_gaussian
());
}
}
}
}
// ----------------------------------------------------------------------------------------
...
...
@@ -140,18 +154,22 @@ int main()
typedef
hashed_feature_image
<
hog_image
<
3
,
3
,
1
,
4
,
hog_signed_gradient
,
hog_full_interpolation
>
>
feature_extractor_type
;
typedef
scan_image_pyramid
<
pyramid_down
,
feature_extractor_type
>
image_scanner_type
;
image_scanner_type
scanner
;
// Setup the sliding window box. Lets use a window with the same shape as the white boxes we
// are trying to detect.
const
rectangle
object_box
=
compute_box_dimensions
(
1
,
// width/height ratio
70
*
70
// box area
);
// Setup the detection template so it contains 4 feature extraction zones inside the object_box. These
// are the upper left, upper right, lower left, and lower right quadrants of object_box. (Note that
// in general we can add more than one detection template. But in this case one is enough.)
scanner
.
add_detection_template
(
object_box
,
create_grid_detection_template
(
object_box
,
2
,
2
));
// The hashed_feature_image feature extractor needs to be supplied with a hash function capable
// of hashing the outputs of the hog_image. Calling this function will set it up for us. The 10
// here indicates that the hash will hash hog vectors into the range [0, pow(2,10)). Therefore,
// the feature vectors output by the hashed_feature_image will have dimension pow(2,10).
setup_hashed_features
(
scanner
,
images
,
10
);
// We also need to setup the detection templates the scanner will use. It is important that
// we add detection templates which are capable of matching all the output boxes we want to learn.
// For example, if object_locations contained a rectangle with a height to width ratio of 10 but
// we only added square detection templates then it would be impossible to detect this non-square
// rectangle. The setup_grid_detection_templates() routine will take care of this for us by looking
// at the contents of object_locations and automatically picking an appropriate set. Also, the final
// arguments indicate that we want our detection templates to have 4 enveloping rectangles laid out
// in a 2x2 regular grid inside each sliding window.
setup_grid_detection_templates
(
scanner
,
object_locations
,
2
,
2
);
// Now that we have defined the kind of sliding window classifier system we want and stored
...
...
@@ -160,14 +178,10 @@ int main()
structural_object_detection_trainer
<
image_scanner_type
>
trainer
(
scanner
);
trainer
.
set_num_threads
(
4
);
// Set this to the number of processing cores on your machine.
// This line tells the algorithm that it is never OK for two detections to overlap. So
// this controls how the non-max suppression is performed and in general you can set this up
// any way you like.
trainer
.
set_overlap_tester
(
test_box_overlap
(
0
));
// There are a variety of other useful parameters to the structural_object_detection_trainer.
// Examples of the ones you are most likely to use follow (see dlib documentation for what they do):
//trainer.set_
overlap
_eps(0.80);
//trainer.set_
match
_eps(0.80);
//trainer.set_c(1.0);
//trainer.set_loss_per_missed_target(1);
//trainer.set_loss_per_false_alarm(1);
...
...
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