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
d8fe4355
Commit
d8fe4355
authored
Jun 23, 2016
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added input_rgb_image_sized.
parent
dc778081
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
0 deletions
+169
-0
input.h
dlib/dnn/input.h
+150
-0
input_abstract.h
dlib/dnn/input_abstract.h
+19
-0
No files found.
dlib/dnn/input.h
View file @
d8fe4355
...
...
@@ -7,6 +7,7 @@
#include "../matrix.h"
#include "../array2d.h"
#include "../pixel.h"
#include <sstream>
namespace
dlib
...
...
@@ -24,6 +25,9 @@ namespace dlib
// ----------------------------------------------------------------------------------------
template
<
size_t
NR
,
size_t
NC
=
NR
>
class
input_rgb_image_sized
;
class
input_rgb_image
{
public
:
...
...
@@ -45,6 +49,11 @@ namespace dlib
)
:
avg_red
(
avg_red_
),
avg_green
(
avg_green_
),
avg_blue
(
avg_blue_
)
{}
template
<
size_t
NR
,
size_t
NC
>
inline
input_rgb_image
(
const
input_rgb_image_sized
<
NR
,
NC
>&
item
);
float
get_avg_red
()
const
{
return
avg_red
;
}
float
get_avg_green
()
const
{
return
avg_green
;
}
float
get_avg_blue
()
const
{
return
avg_blue
;
}
...
...
@@ -136,6 +145,147 @@ namespace dlib
float
avg_blue
;
};
// ----------------------------------------------------------------------------------------
template
<
size_t
NR
,
size_t
NC
>
class
input_rgb_image_sized
{
public
:
static_assert
(
NR
!=
0
&&
NC
!=
0
,
"The input image can't be empty."
);
typedef
matrix
<
rgb_pixel
>
input_type
;
const
static
unsigned
int
sample_expansion_factor
=
1
;
input_rgb_image_sized
(
)
:
avg_red
(
122
.
782
),
avg_green
(
117
.
001
),
avg_blue
(
104
.
298
)
{
}
input_rgb_image_sized
(
const
input_rgb_image
&
item
)
:
avg_red
(
item
.
get_avg_red
()),
avg_green
(
item
.
get_avg_green
()),
avg_blue
(
item
.
get_avg_blue
())
{}
input_rgb_image_sized
(
float
avg_red_
,
float
avg_green_
,
float
avg_blue_
)
:
avg_red
(
avg_red_
),
avg_green
(
avg_green_
),
avg_blue
(
avg_blue_
)
{}
float
get_avg_red
()
const
{
return
avg_red
;
}
float
get_avg_green
()
const
{
return
avg_green
;
}
float
get_avg_blue
()
const
{
return
avg_blue
;
}
template
<
typename
input_iterator
>
void
to_tensor
(
input_iterator
ibegin
,
input_iterator
iend
,
resizable_tensor
&
data
)
const
{
DLIB_CASSERT
(
std
::
distance
(
ibegin
,
iend
)
>
0
,
""
);
// make sure all input images have the correct size
for
(
auto
i
=
ibegin
;
i
!=
iend
;
++
i
)
{
DLIB_CASSERT
(
i
->
nr
()
==
NR
&&
i
->
nc
()
==
NC
,
"
\t
input_rgb_image_sized::to_tensor()"
<<
"
\n\t
All input images must have "
<<
NR
<<
" rows and "
<<
NC
<<
" columns, but we got one with "
<<
i
->
nr
()
<<
" rows and "
<<
i
->
nc
()
<<
" columns."
);
}
// initialize data to the right size to contain the stuff in the iterator range.
data
.
set_size
(
std
::
distance
(
ibegin
,
iend
),
3
,
NR
,
NC
);
const
size_t
offset
=
NR
*
NC
;
auto
ptr
=
data
.
host
();
for
(
auto
i
=
ibegin
;
i
!=
iend
;
++
i
)
{
for
(
long
r
=
0
;
r
<
NR
;
++
r
)
{
for
(
long
c
=
0
;
c
<
NC
;
++
c
)
{
rgb_pixel
temp
=
(
*
i
)(
r
,
c
);
auto
p
=
ptr
++
;
*
p
=
(
temp
.
red
-
avg_red
)
/
256
.
0
;
p
+=
offset
;
*
p
=
(
temp
.
green
-
avg_green
)
/
256
.
0
;
p
+=
offset
;
*
p
=
(
temp
.
blue
-
avg_blue
)
/
256
.
0
;
p
+=
offset
;
}
}
ptr
+=
offset
*
(
data
.
k
()
-
1
);
}
}
friend
void
serialize
(
const
input_rgb_image_sized
&
item
,
std
::
ostream
&
out
)
{
serialize
(
"input_rgb_image_sized"
,
out
);
serialize
(
item
.
avg_red
,
out
);
serialize
(
item
.
avg_green
,
out
);
serialize
(
item
.
avg_blue
,
out
);
serialize
(
NR
,
out
);
serialize
(
NC
,
out
);
}
friend
void
deserialize
(
input_rgb_image_sized
&
item
,
std
::
istream
&
in
)
{
std
::
string
version
;
deserialize
(
version
,
in
);
if
(
version
!=
"input_rgb_image_sized"
)
throw
serialization_error
(
"Unexpected version found while deserializing dlib::input_rgb_image_sized."
);
deserialize
(
item
.
avg_red
,
in
);
deserialize
(
item
.
avg_green
,
in
);
deserialize
(
item
.
avg_blue
,
in
);
size_t
nr
,
nc
;
deserialize
(
nr
,
in
);
deserialize
(
nc
,
in
);
if
(
nr
!=
NR
||
nc
!=
NC
)
{
std
::
ostringstream
sout
;
sout
<<
"Wrong image dimensions found while deserializing dlib::input_rgb_image_sized.
\n
"
;
sout
<<
"Expected "
<<
NR
<<
" rows and "
<<
NC
<<
" columns, but found "
<<
nr
<<
" rows and "
<<
nc
<<
" columns."
;
throw
serialization_error
(
sout
.
str
());
}
}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
input_rgb_image_sized
&
item
)
{
out
<<
"input_rgb_image_sized("
<<
item
.
avg_red
<<
","
<<
item
.
avg_green
<<
","
<<
item
.
avg_blue
<<
") nr="
<<
NR
<<
" nc="
<<
NC
;
return
out
;
}
friend
void
to_xml
(
const
input_rgb_image_sized
&
item
,
std
::
ostream
&
out
)
{
out
<<
"<input_rgb_image_sized r='"
<<
item
.
avg_red
<<
"' g='"
<<
item
.
avg_green
<<
"' b='"
<<
item
.
avg_blue
<<
"' nr='"
<<
NR
<<
"' nc='"
<<
NC
<<
"'/>"
;
}
private
:
float
avg_red
;
float
avg_green
;
float
avg_blue
;
};
// ----------------------------------------------------------------------------------------
template
<
size_t
NR
,
size_t
NC
>
input_rgb_image
::
input_rgb_image
(
const
input_rgb_image_sized
<
NR
,
NC
>&
item
)
:
avg_red
(
item
.
get_avg_red
()),
avg_green
(
item
.
get_avg_green
()),
avg_blue
(
item
.
get_avg_blue
())
{}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
long
NR
,
long
NC
,
typename
MM
,
typename
L
>
...
...
dlib/dnn/input_abstract.h
View file @
d8fe4355
...
...
@@ -235,6 +235,25 @@ namespace dlib
!*/
};
// ----------------------------------------------------------------------------------------
template
<
size_t
NR
,
size_t
NC
=
NR
>
class
input_rgb_image_sized
{
/*!
WHAT THIS OBJECT REPRESENTS
This layer has an interface and behavior identical to input_rgb_image
except that it requires input images to have NR rows and NC columns. This
is checked by a DLIB_CASSERT inside to_tensor().
You can also convert between input_rgb_image and input_rgb_image_sized by
copy construction or assignment.
!*/
};
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_DNn_INPUT_ABSTRACT_H_
...
...
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