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
30097efb
Commit
30097efb
authored
Dec 22, 2012
by
Davis King
Browse files
Made toMat() work with matrix object in addition to array2d style images.
parent
ea55f97e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
3 deletions
+40
-3
dlib/opencv/to_open_cv.h
dlib/opencv/to_open_cv.h
+38
-2
dlib/opencv/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
the
type
=
CV_MAKETYPE
(
depth
,
channels
);
return
cv
::
Mat
(
img
.
nr
(),
img
.
nc
(),
the
type
,
(
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