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
38b78800
Commit
38b78800
authored
Aug 11, 2011
by
Davis King
Browse files
Made hog_image clearable and serializable.
parent
259c32ec
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
162 additions
and
1 deletion
+162
-1
dlib/image_keypoint/hog.h
dlib/image_keypoint/hog.h
+91
-0
dlib/image_keypoint/hog_abstract.h
dlib/image_keypoint/hog_abstract.h
+41
-0
dlib/test/hog_image.cpp
dlib/test/hog_image.cpp
+30
-1
No files found.
dlib/image_keypoint/hog.h
View file @
38b78800
...
...
@@ -63,6 +63,14 @@ namespace dlib
num_block_cols
(
0
)
{}
void
clear
(
)
{
num_block_rows
=
0
;
num_block_cols
=
0
;
hist_cells
.
clear
();
}
template
<
typename
image_type
>
...
...
@@ -201,6 +209,32 @@ namespace dlib
return
rectangle
(
feat_to_image_space
(
rect
.
tl_corner
()),
feat_to_image_space
(
rect
.
br_corner
()));
}
template
<
unsigned
long
T1
,
unsigned
long
T2
,
unsigned
long
T3
,
unsigned
long
T4
,
int
T5
,
int
T6
>
friend
void
serialize
(
const
hog_image
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
>&
item
,
std
::
ostream
&
out
);
template
<
unsigned
long
T1
,
unsigned
long
T2
,
unsigned
long
T3
,
unsigned
long
T4
,
int
T5
,
int
T6
>
friend
void
deserialize
(
hog_image
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
>&
item
,
std
::
istream
&
in
);
private:
template
<
...
...
@@ -430,6 +464,63 @@ namespace dlib
};
// ----------------------------------------------------------------------------------------
template
<
unsigned
long
T1
,
unsigned
long
T2
,
unsigned
long
T3
,
unsigned
long
T4
,
int
T5
,
int
T6
>
void
serialize
(
const
hog_image
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
>&
item
,
std
::
ostream
&
out
)
{
// serialize item.hist_cells
serialize
(
item
.
hist_cells
.
nc
(),
out
);
serialize
(
item
.
hist_cells
.
nr
(),
out
);
item
.
hist_cells
.
reset
();
while
(
item
.
hist_cells
.
move_next
())
serialize
(
item
.
hist_cells
.
element
().
values
,
out
);
item
.
hist_cells
.
reset
();
serialize
(
item
.
num_block_rows
,
out
);
serialize
(
item
.
num_block_cols
,
out
);
}
template
<
unsigned
long
T1
,
unsigned
long
T2
,
unsigned
long
T3
,
unsigned
long
T4
,
int
T5
,
int
T6
>
void
deserialize
(
hog_image
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
>&
item
,
std
::
istream
&
in
)
{
// deserialize item.hist_cells
long
nc
,
nr
;
deserialize
(
nc
,
in
);
deserialize
(
nr
,
in
);
item
.
hist_cells
.
set_size
(
nr
,
nc
);
while
(
item
.
hist_cells
.
move_next
())
deserialize
(
item
.
hist_cells
.
element
().
values
,
in
);
item
.
hist_cells
.
reset
();
deserialize
(
item
.
num_block_rows
,
in
);
deserialize
(
item
.
num_block_cols
,
in
);
}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/image_keypoint/hog_abstract.h
View file @
38b78800
...
...
@@ -120,6 +120,13 @@ namespace dlib
- this object is properly initialized
!*/
void
clear
(
);
/*!
ensures
- this object will have its initial value
!*/
template
<
typename
image_type
>
...
...
@@ -237,6 +244,40 @@ namespace dlib
};
// ----------------------------------------------------------------------------------------
template
<
unsigned
long
T1
,
unsigned
long
T2
,
unsigned
long
T3
,
unsigned
long
T4
,
int
T5
,
int
T6
>
void
serialize
(
const
hog_image
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
>&
item
,
std
::
ostream
&
out
);
/*!
provides serialization support
!*/
template
<
unsigned
long
T1
,
unsigned
long
T2
,
unsigned
long
T3
,
unsigned
long
T4
,
int
T5
,
int
T6
>
void
deserialize
(
hog_image
<
T1
,
T2
,
T3
,
T4
,
T5
,
T6
>&
item
,
std
::
istream
&
in
);
/*!
provides deserialization support
!*/
// ----------------------------------------------------------------------------------------
}
...
...
dlib/test/hog_image.cpp
View file @
38b78800
...
...
@@ -40,7 +40,7 @@ namespace
assign_all_pixels
(
img
,
0
);
hog_image
<
3
,
3
,
1
,
4
,
hog_signed_gradient
,
hog_full_interpolation
>
hog1
;
hog_image
<
3
,
3
,
1
,
4
,
hog_signed_gradient
,
hog_full_interpolation
>
hog1
,
hog1_deserialized
;
hog_image
<
4
,
4
,
2
,
4
,
hog_signed_gradient
,
hog_full_interpolation
>
hog2
;
hog1
.
load
(
img
);
...
...
@@ -87,6 +87,35 @@ namespace
DLIB_TEST
(
hog2
.
image_to_feat_space
(
hog2
.
feat_to_image_space
(
point
(
1
,
1
)))
==
point
(
1
,
1
));
DLIB_TEST
(
hog1
.
image_to_feat_space
(
hog1
.
feat_to_image_space
(
point
(
1
,
2
)))
==
point
(
1
,
2
));
DLIB_TEST
(
hog2
.
image_to_feat_space
(
hog2
.
feat_to_image_space
(
point
(
1
,
2
)))
==
point
(
1
,
2
));
DLIB_TEST
(
hog1_deserialized
.
size
()
!=
hog1
.
size
());
DLIB_TEST
(
hog1_deserialized
.
nr
()
!=
hog1
.
nr
());
DLIB_TEST
(
hog1_deserialized
.
nc
()
!=
hog1
.
nc
());
ostringstream
sout
;
serialize
(
hog1
,
sout
);
istringstream
sin
(
sout
.
str
());
deserialize
(
hog1_deserialized
,
sin
);
DLIB_TEST
(
hog1_deserialized
.
size
()
==
hog1
.
size
());
DLIB_TEST
(
hog1_deserialized
.
nr
()
==
hog1
.
nr
());
DLIB_TEST
(
hog1_deserialized
.
nc
()
==
hog1
.
nc
());
DLIB_TEST
(
hog1_deserialized
(
0
,
2
)
==
hog1
(
0
,
2
));
DLIB_TEST
(
hog1_deserialized
.
get_block_rect
(
1
,
2
)
==
hog1
.
get_block_rect
(
1
,
2
));
DLIB_TEST
(
hog1_deserialized
.
image_to_feat_space
(
hog1_deserialized
.
feat_to_image_space
(
point
(
0
,
0
)))
==
point
(
0
,
0
));
DLIB_TEST
(
hog1_deserialized
.
image_to_feat_space
(
hog1_deserialized
.
feat_to_image_space
(
point
(
1
,
1
)))
==
point
(
1
,
1
));
DLIB_TEST
(
hog1_deserialized
.
image_to_feat_space
(
hog1_deserialized
.
feat_to_image_space
(
point
(
1
,
2
)))
==
point
(
1
,
2
));
DLIB_TEST
(
hog1
.
size
()
>
1
);
DLIB_TEST
(
hog1
.
nr
()
>
1
);
DLIB_TEST
(
hog1
.
nc
()
>
1
);
hog1
.
clear
();
DLIB_TEST
(
hog1
.
size
()
==
0
);
DLIB_TEST
(
hog1
.
nr
()
==
0
);
DLIB_TEST
(
hog1
.
nc
()
==
0
);
}
}
a
;
...
...
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