00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 #ifndef __OPENCV_EIGEN_HPP__
00044 #define __OPENCV_EIGEN_HPP__
00045 
00046 #ifdef __cplusplus
00047 
00048 #include "cxcore.h"
00049 #include <Eigen/Core>
00050 
00051 namespace cv
00052 {
00053 
00054 template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
00055 void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src,
00056                Mat& dst, bool _copyData=true )
00057 {
00058     Mat _src(src.rows(), src.cols(), DataType<_Tp>::type,
00059           (void*)src.data(), (size_t)(src.stride()*sizeof(_Tp)));
00060     if( !_copyData )
00061         dst = _src;
00062         else
00063                 _src.copyTo(dst);
00064 }
00065     
00066 template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols>
00067 void cv2eigen( const Mat& src,
00068                Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
00069 {
00070     CV_Assert(src.rows == _rows && src.cols == _cols);
00071     Mat _dst(_rows, _cols, DataType<_Tp>::type,
00072              dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
00073     src.convertTo(_dst, _dst.type());
00074     CV_Assert(_dst.data == (uchar*)dst.data());
00075 }
00076 
00077 template<typename _Tp>
00078 void cv2eigen( const Mat& src,
00079                Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
00080 {
00081     dst.resize(src.rows, src.cols);
00082     Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
00083              dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
00084     src.convertTo(_dst, _dst.type());
00085     CV_Assert(_dst.data == (uchar*)dst.data());
00086 }
00087 
00088     
00089 template<typename _Tp>
00090 void cv2eigen( const Mat& src,
00091                Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
00092 {
00093     CV_Assert(src.cols == 1);
00094     dst.resize(src.rows);
00095     Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
00096              dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
00097     src.convertTo(_dst, _dst.type());
00098     CV_Assert(_dst.data == (uchar*)dst.data());
00099 }
00100 
00101 
00102 template<typename _Tp>
00103 void cv2eigen( const Mat& src,
00104                Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
00105 {
00106     CV_Assert(src.rows == 1);
00107     dst.resize(src.cols);
00108     Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
00109              (void*)dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
00110     src.convertTo(_dst, _dst.type());
00111     CV_Assert(_dst.data == (uchar*)dst.data());
00112 }                     
00113               
00114 }
00115 
00116 #endif
00117 
00118 #endif
00119