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
ae73da44
Commit
ae73da44
authored
Apr 21, 2012
by
Davis King
Browse files
Added the toMat() routine for converting from a dlib style image to an
OpenCV cv::Mat image.
parent
bcea0df4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
0 deletions
+69
-0
dlib/opencv.h
dlib/opencv.h
+1
-0
dlib/opencv/to_open_cv.h
dlib/opencv/to_open_cv.h
+37
-0
dlib/opencv/to_open_cv_abstract.h
dlib/opencv/to_open_cv_abstract.h
+31
-0
No files found.
dlib/opencv.h
View file @
ae73da44
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#define DLIB_OPEnCV_HEADER
#define DLIB_OPEnCV_HEADER
#include "opencv/cv_image.h"
#include "opencv/cv_image.h"
#include "opencv/to_open_cv.h"
#endif // DLIB_OPEnCV_HEADER
#endif // DLIB_OPEnCV_HEADER
...
...
dlib/opencv/to_open_cv.h
0 → 100644
View file @
ae73da44
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_TO_OPEN_Cv_H__
#define DLIB_TO_OPEN_Cv_H__
#include "to_open_cv_abstract.h"
#include "../pixel.h"
namespace
dlib
{
template
<
typename
image_type
>
cv
::
Mat
toMat
(
image_type
&
img
)
{
if
(
img
.
size
()
==
0
)
return
cv
::
Mat
();
typedef
typename
image_type
::
type
type
;
if
(
pixel_traits
<
type
>::
num
==
1
)
{
return
cv
::
Mat
(
img
.
nr
(),
img
.
nc
(),
cv
::
DataType
<
type
>::
type
,
&
img
[
0
][
0
],
img
.
width_step
());
}
else
{
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
,
&
img
[
0
][
0
],
img
.
width_step
());
}
}
}
#endif // DLIB_TO_OPEN_Cv_H__
dlib/opencv/to_open_cv_abstract.h
0 → 100644
View file @
ae73da44
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#undef DLIB_TO_OPEN_Cv_ABSTRACT__
#ifdef DLIB_TO_OPEN_Cv_ABSTRACT__
#include "../pixel.h"
namespace
dlib
{
template
<
typename
image_type
>
cv
::
Mat
toMat
(
image_type
&
img
);
/*!
requires
- image_type == an implementation of dlib/array2d/array2d_kernel_abstract.h
- pixel_traits<typename image_type::type> is defined
ensures
- returns an OpenCV Mat object which represents the same image as img. This
is done by setting up the Mat object to point to the same memory as img.
Therefore, the returned Mat object is valid only as long as pointers
to the pixels in img remain valid.
!*/
}
#endif // DLIB_TO_OPEN_Cv_ABSTRACT__
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