1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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_Hh_
#define DLIB_TO_OPEN_Cv_Hh_
#include "to_open_cv_abstract.h"
#include "../pixel.h"
#include "../matrix/matrix.h"
namespace dlib
{
// ----------------------------------------------------------------------------------------
template <
typename image_type
>
cv::Mat toMat (
image_type& img
)
{
if (image_size(img) == 0)
return cv::Mat();
typedef typename image_traits<image_type>::pixel_type type;
if (pixel_traits<type>::num == 1)
{
return cv::Mat(num_rows(img), num_columns(img), cv::DataType<type>::type, image_data(img), width_step(img));
}
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(num_rows(img), num_columns(img), thetype, image_data(img), width_step(img));
}
}
// ----------------------------------------------------------------------------------------
}
#endif // DLIB_TO_OPEN_Cv_Hh_