root / branches / test / PS3Capture / Include / opencv2 / core / eigen.hpp @ 6

View | Annotate | Download (6.5 KB)

1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
//  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
//  By downloading, copying, installing or using the software you agree to this license.
6
//  If you do not agree to this license, do not download, install,
7
//  copy or use the software.
8
//
9
//
10
//                          License Agreement
11
//                For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
//   * Redistribution's of source code must retain the above copyright notice,
21
//     this list of conditions and the following disclaimer.
22
//
23
//   * Redistribution's in binary form must reproduce the above copyright notice,
24
//     this list of conditions and the following disclaimer in the documentation
25
//     and/or other materials provided with the distribution.
26
//
27
//   * The name of the copyright holders may not be used to endorse or promote products
28
//     derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
43
#ifndef __OPENCV_CORE_EIGEN_HPP__
44
#define __OPENCV_CORE_EIGEN_HPP__
45
46
#ifdef __cplusplus
47
48
#include "cxcore.h"
49
50
namespace cv
51
{
52
53
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
54
void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst )
55
{
56
    if( !(src.Flags & Eigen::RowMajorBit) )
57
    {
58
        Mat _src(src.cols(), src.rows(), DataType<_Tp>::type,
59
              (void*)src.data(), src.stride()*sizeof(_Tp));
60
        transpose(_src, dst);
61
    }
62
    else
63
    {
64
        Mat _src(src.rows(), src.cols(), DataType<_Tp>::type,
65
                 (void*)src.data(), src.stride()*sizeof(_Tp));
66
        _src.copyTo(dst);
67
    }
68
}
69
    
70
template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
71
void cv2eigen( const Mat& src,
72
               Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
73
{
74
    CV_DbgAssert(src.rows == _rows && src.cols == _cols);
75
    if( !(dst.Flags & Eigen::RowMajorBit) )
76
    {
77
        Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
78
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
79
        if( src.type() == _dst.type() )
80
            transpose(src, _dst);
81
        else if( src.cols == src.rows )
82
        {
83
            src.convertTo(_dst, _dst.type());
84
            transpose(_dst, _dst);
85
        }
86
        else
87
            Mat(src.t()).convertTo(_dst, _dst.type());
88
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
89
    }
90
    else
91
    {
92
        Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
93
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
94
        src.convertTo(_dst, _dst.type());
95
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
96
    }
97
}
98
99
template<typename _Tp>
100
void cv2eigen( const Mat& src,
101
               Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
102
{
103
    dst.resize(src.rows, src.cols);
104
    if( !(dst.Flags & Eigen::RowMajorBit) )
105
    {
106
        Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
107
             dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
108
        if( src.type() == _dst.type() )
109
            transpose(src, _dst);
110
        else if( src.cols == src.rows )
111
        {
112
            src.convertTo(_dst, _dst.type());
113
            transpose(_dst, _dst);
114
        }
115
        else
116
            Mat(src.t()).convertTo(_dst, _dst.type());
117
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
118
    }
119
    else
120
    {
121
        Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
122
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
123
        src.convertTo(_dst, _dst.type());
124
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
125
    }
126
}
127
128
    
129
template<typename _Tp>
130
void cv2eigen( const Mat& src,
131
               Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
132
{
133
    CV_Assert(src.cols == 1);
134
    dst.resize(src.rows);
135
    
136
    if( !(dst.Flags & Eigen::RowMajorBit) )
137
    {
138
        Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
139
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
140
        if( src.type() == _dst.type() )
141
            transpose(src, _dst);
142
        else
143
            Mat(src.t()).convertTo(_dst, _dst.type());
144
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
145
    }
146
    else
147
    {
148
        Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
149
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
150
        src.convertTo(_dst, _dst.type());
151
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
152
    }
153
}
154
155
156
template<typename _Tp>
157
void cv2eigen( const Mat& src,
158
               Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
159
{
160
    CV_Assert(src.rows == 1);
161
    dst.resize(src.cols);
162
    if( !(dst.Flags & Eigen::RowMajorBit) )
163
    {
164
        Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
165
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
166
        if( src.type() == _dst.type() )
167
            transpose(src, _dst);
168
        else
169
            Mat(src.t()).convertTo(_dst, _dst.type());
170
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
171
    }
172
    else
173
    {
174
        Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
175
                 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
176
        src.convertTo(_dst, _dst.type());
177
        CV_DbgAssert(_dst.data == (uchar*)dst.data());
178
    }
179
}                     
180
              
181
}
182
183
#endif
184
185
#endif
186