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
ca13ff7c
Commit
ca13ff7c
authored
Jul 15, 2012
by
Davis King
Browse files
Refactored code and added find_points_above_thresh()
parent
9ff6efab
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
71 deletions
+84
-71
dlib/image_processing/scan_image.h
dlib/image_processing/scan_image.h
+53
-71
dlib/image_processing/scan_image_abstract.h
dlib/image_processing/scan_image_abstract.h
+31
-0
No files found.
dlib/image_processing/scan_image.h
View file @
ca13ff7c
...
@@ -184,6 +184,57 @@ namespace dlib
...
@@ -184,6 +184,57 @@ namespace dlib
return
static_cast
<
double
>
(
temp
);
return
static_cast
<
double
>
(
temp
);
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
void
find_points_above_thresh
(
std
::
vector
<
std
::
pair
<
double
,
point
>
>&
dets
,
const
image_type
&
img
,
const
double
thresh
,
const
unsigned
long
max_dets
)
{
typedef
typename
image_type
::
type
ptype
;
dets
.
clear
();
if
(
max_dets
==
0
)
return
;
unsigned
long
count
=
0
;
dlib
::
rand
rnd
;
for
(
long
r
=
0
;
r
<
img
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
img
.
nc
();
++
c
)
{
const
ptype
val
=
img
[
r
][
c
];
if
(
val
>=
thresh
)
{
++
count
;
if
(
dets
.
size
()
<
max_dets
)
{
dets
.
push_back
(
std
::
make_pair
(
val
,
point
(
c
,
r
)));
}
else
{
// The idea here is to cause us to randomly sample possible detection
// locations throughout the image rather than just stopping the detection
// procedure once we hit the max_dets limit. So this method will result
// in a random subsample of all the detections >= thresh being in dets
// at the end of scan_image().
const
unsigned
long
random_index
=
rnd
.
get_random_32bit_number
()
%
count
;
if
(
random_index
<
dets
.
size
())
{
dets
[
random_index
]
=
std
::
make_pair
(
val
,
point
(
c
,
r
));
}
}
}
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
@@ -217,9 +268,6 @@ namespace dlib
...
@@ -217,9 +268,6 @@ namespace dlib
#endif
#endif
dets
.
clear
();
if
(
max_dets
==
0
)
return
;
typedef
typename
image_array_type
::
type
::
type
pixel_type
;
typedef
typename
image_array_type
::
type
::
type
pixel_type
;
...
@@ -231,37 +279,7 @@ namespace dlib
...
@@ -231,37 +279,7 @@ namespace dlib
for
(
unsigned
long
i
=
0
;
i
<
rects
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
rects
.
size
();
++
i
)
sum_filter
(
images
[
rects
[
i
].
first
],
accum
,
rects
[
i
].
second
);
sum_filter
(
images
[
rects
[
i
].
first
],
accum
,
rects
[
i
].
second
);
unsigned
long
count
=
0
;
find_points_above_thresh
(
dets
,
accum
,
thresh
,
max_dets
);
dlib
::
rand
rnd
;
for
(
long
r
=
0
;
r
<
accum
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
accum
.
nc
();
++
c
)
{
const
ptype
cur_sum
=
accum
[
r
][
c
];
if
(
cur_sum
>=
thresh
)
{
++
count
;
if
(
dets
.
size
()
<
max_dets
)
{
dets
.
push_back
(
std
::
make_pair
(
cur_sum
,
point
(
c
,
r
)));
}
else
{
// The idea here is to cause us to randomly sample possible detection
// locations throughout the image rather than just stopping the detection
// procedure once we hit the max_dets limit. So this method will result
// in a random subsample of all the detections >= thresh being in dets
// at the end of scan_image().
const
unsigned
long
random_index
=
rnd
.
get_random_32bit_number
()
%
count
;
if
(
random_index
<
dets
.
size
())
{
dets
[
random_index
]
=
std
::
make_pair
(
cur_sum
,
point
(
c
,
r
));
}
}
}
}
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
@@ -318,14 +336,9 @@ namespace dlib
...
@@ -318,14 +336,9 @@ namespace dlib
}
}
#endif
#endif
dets
.
clear
();
if
(
max_dets
==
0
)
return
;
if
(
movable_rects
.
size
()
==
0
&&
fixed_rects
.
size
()
==
0
)
if
(
movable_rects
.
size
()
==
0
&&
fixed_rects
.
size
()
==
0
)
return
;
return
;
typedef
typename
image_array_type
::
type
::
type
pixel_type
;
typedef
typename
image_array_type
::
type
::
type
pixel_type
;
typedef
typename
promote
<
pixel_type
>::
type
ptype
;
typedef
typename
promote
<
pixel_type
>::
type
ptype
;
...
@@ -344,38 +357,7 @@ namespace dlib
...
@@ -344,38 +357,7 @@ namespace dlib
max_filter
(
temp
,
accum
,
window
.
width
(),
window
.
height
(),
0
);
max_filter
(
temp
,
accum
,
window
.
width
(),
window
.
height
(),
0
);
}
}
// TODO, make this block its own function and reuse it in scan_image().
find_points_above_thresh
(
dets
,
accum
,
thresh
,
max_dets
);
unsigned
long
count
=
0
;
dlib
::
rand
rnd
;
for
(
long
r
=
0
;
r
<
accum
.
nr
();
++
r
)
{
for
(
long
c
=
0
;
c
<
accum
.
nc
();
++
c
)
{
const
ptype
cur_sum
=
accum
[
r
][
c
];
if
(
cur_sum
>=
thresh
)
{
++
count
;
if
(
dets
.
size
()
<
max_dets
)
{
dets
.
push_back
(
std
::
make_pair
(
cur_sum
,
point
(
c
,
r
)));
}
else
{
// The idea here is to cause us to randomly sample possible detection
// locations throughout the image rather than just stopping the detection
// procedure once we hit the max_dets limit. So this method will result
// in a random subsample of all the detections >= thresh being in dets
// at the end of scan_image_movable_parts().
const
unsigned
long
random_index
=
rnd
.
get_random_32bit_number
()
%
count
;
if
(
random_index
<
dets
.
size
())
{
dets
[
random_index
]
=
std
::
make_pair
(
cur_sum
,
point
(
c
,
r
));
}
}
}
}
}
}
}
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
...
...
dlib/image_processing/scan_image_abstract.h
View file @
ca13ff7c
...
@@ -96,6 +96,37 @@ namespace dlib
...
@@ -96,6 +96,37 @@ namespace dlib
Then this function returns TOTAL_FIXED + TOTAL_MOVABLE.
Then this function returns TOTAL_FIXED + TOTAL_MOVABLE.
!*/
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
void
find_points_above_thresh
(
std
::
vector
<
std
::
pair
<
double
,
point
>
>&
dets
,
const
image_type
&
img
,
const
double
thresh
,
const
unsigned
long
max_dets
);
/*!
requires
- image_type == an implementation of array2d/array2d_kernel_abstract.h
- image_type::type == a scalar pixel type (e.g. int rather than rgb_pixel)
ensures
- #dets == a list of points from img which had pixel values >= thresh.
- Specifically, we have:
- #dets.size() <= max_dets
(note that dets is cleared before new detections are added by find_points_above_thresh())
- for all valid i:
- #dets[i].first == img[#dets[i].second.y()][#dets[i].second.x()]
(i.e. the first field contains the value of the pixel at this detection location)
- #dets[i].first >= thresh
- if (there are more than max_dets locations that pass the above threshold test) then
- #dets == a random subsample of all the locations which passed the threshold
test.
- else
- #dets == all the points which passed the threshold test.
!*/
// ----------------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------------
template
<
template
<
...
...
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