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
30097efb
Commit
30097efb
authored
Dec 22, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made toMat() work with matrix object in addition to array2d style images.
parent
ea55f97e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
to_open_cv.h
dlib/opencv/to_open_cv.h
+38
-2
to_open_cv_abstract.h
dlib/opencv/to_open_cv_abstract.h
+2
-1
No files found.
dlib/opencv/to_open_cv.h
View file @
30097efb
...
...
@@ -5,9 +5,13 @@
#include "to_open_cv_abstract.h"
#include "../pixel.h"
#include "../matrix/matrix.h"
namespace
dlib
{
// ----------------------------------------------------------------------------------------
template
<
typename
image_type
>
...
...
@@ -27,10 +31,42 @@ namespace dlib
{
int
depth
=
sizeof
(
typename
pixel_traits
<
type
>::
basic_pixel_type
)
*
8
;
int
channels
=
pixel_traits
<
type
>::
num
;
int
type
=
CV_MAKETYPE
(
depth
,
channels
);
return
cv
::
Mat
(
img
.
nr
(),
img
.
nc
(),
type
,
(
void
*
)
&
img
[
0
][
0
],
img
.
width_step
());
int
t
het
ype
=
CV_MAKETYPE
(
depth
,
channels
);
return
cv
::
Mat
(
img
.
nr
(),
img
.
nc
(),
t
het
ype
,
(
void
*
)
&
img
[
0
][
0
],
img
.
width_step
());
}
}
// ----------------------------------------------------------------------------------------
template
<
typename
T
,
long
NR
,
long
NC
,
typename
MM
>
cv
::
Mat
toMat
(
matrix
<
T
,
NR
,
NC
,
MM
>&
img
)
{
if
(
img
.
size
()
==
0
)
return
cv
::
Mat
();
typedef
T
type
;
if
(
pixel_traits
<
type
>::
num
==
1
)
{
return
cv
::
Mat
(
img
.
nr
(),
img
.
nc
(),
cv
::
DataType
<
type
>::
type
,
(
void
*
)
&
img
(
0
,
0
),
img
.
nc
()
*
sizeof
(
type
));
}
else
{
int
depth
=
sizeof
(
typename
pixel_traits
<
type
>::
basic_pixel_type
)
*
8
;
int
channels
=
pixel_traits
<
type
>::
num
;
int
thetype
=
CV_MAKETYPE
(
depth
,
channels
);
return
cv
::
Mat
(
img
.
nr
(),
img
.
nc
(),
thetype
,
(
void
*
)
&
img
(
0
,
0
),
img
.
nc
()
*
sizeof
(
type
));
}
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_TO_OPEN_Cv_H__
...
...
dlib/opencv/to_open_cv_abstract.h
View file @
30097efb
...
...
@@ -15,7 +15,8 @@ namespace dlib
);
/*!
requires
- image_type == an implementation of dlib/array2d/array2d_kernel_abstract.h
- image_type == an implementation of dlib/array2d/array2d_kernel_abstract.h or
a dlib::matrix object which uses a row_major_layout.
- pixel_traits<typename image_type::type> is defined
ensures
- returns an OpenCV Mat object which represents the same image as img. This
...
...
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