mirror of https://github.com/davisking/dlib.git
Added the toMat() routine for converting from a dlib style image to an
OpenCV cv::Mat image.
This commit is contained in:
parent
bcea0df438
commit
ae73da4438
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
// 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__
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
// 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__
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue