opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
joeverbout 0:ea44dc9ed014 16 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 17 //
joeverbout 0:ea44dc9ed014 18 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 19 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 20 //
joeverbout 0:ea44dc9ed014 21 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 22 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 23 //
joeverbout 0:ea44dc9ed014 24 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 25 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 26 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 27 //
joeverbout 0:ea44dc9ed014 28 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 29 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 30 //
joeverbout 0:ea44dc9ed014 31 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 32 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 34 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 35 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 36 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 37 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 38 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 39 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 40 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 41 //
joeverbout 0:ea44dc9ed014 42 //M*/
joeverbout 0:ea44dc9ed014 43
joeverbout 0:ea44dc9ed014 44
joeverbout 0:ea44dc9ed014 45 #ifndef __OPENCV_CORE_EIGEN_HPP__
joeverbout 0:ea44dc9ed014 46 #define __OPENCV_CORE_EIGEN_HPP__
joeverbout 0:ea44dc9ed014 47
joeverbout 0:ea44dc9ed014 48 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 49
joeverbout 0:ea44dc9ed014 50 #if defined _MSC_VER && _MSC_VER >= 1200
joeverbout 0:ea44dc9ed014 51 #pragma warning( disable: 4714 ) //__forceinline is not inlined
joeverbout 0:ea44dc9ed014 52 #pragma warning( disable: 4127 ) //conditional expression is constant
joeverbout 0:ea44dc9ed014 53 #pragma warning( disable: 4244 ) //conversion from '__int64' to 'int', possible loss of data
joeverbout 0:ea44dc9ed014 54 #endif
joeverbout 0:ea44dc9ed014 55
joeverbout 0:ea44dc9ed014 56 namespace cv
joeverbout 0:ea44dc9ed014 57 {
joeverbout 0:ea44dc9ed014 58
joeverbout 0:ea44dc9ed014 59 //! @addtogroup core_eigen
joeverbout 0:ea44dc9ed014 60 //! @{
joeverbout 0:ea44dc9ed014 61
joeverbout 0:ea44dc9ed014 62 template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
joeverbout 0:ea44dc9ed014 63 void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src, Mat& dst )
joeverbout 0:ea44dc9ed014 64 {
joeverbout 0:ea44dc9ed014 65 if( !(src.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 66 {
joeverbout 0:ea44dc9ed014 67 Mat _src(src.cols(), src.rows(), DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 68 (void*)src.data(), src.stride()*sizeof(_Tp));
joeverbout 0:ea44dc9ed014 69 transpose(_src, dst);
joeverbout 0:ea44dc9ed014 70 }
joeverbout 0:ea44dc9ed014 71 else
joeverbout 0:ea44dc9ed014 72 {
joeverbout 0:ea44dc9ed014 73 Mat _src(src.rows(), src.cols(), DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 74 (void*)src.data(), src.stride()*sizeof(_Tp));
joeverbout 0:ea44dc9ed014 75 _src.copyTo(dst);
joeverbout 0:ea44dc9ed014 76 }
joeverbout 0:ea44dc9ed014 77 }
joeverbout 0:ea44dc9ed014 78
joeverbout 0:ea44dc9ed014 79 // Matx case
joeverbout 0:ea44dc9ed014 80 template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
joeverbout 0:ea44dc9ed014 81 void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& src,
joeverbout 0:ea44dc9ed014 82 Matx<_Tp, _rows, _cols>& dst )
joeverbout 0:ea44dc9ed014 83 {
joeverbout 0:ea44dc9ed014 84 if( !(src.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 85 {
joeverbout 0:ea44dc9ed014 86 dst = Matx<_Tp, _cols, _rows>(static_cast<const _Tp*>(src.data())).t();
joeverbout 0:ea44dc9ed014 87 }
joeverbout 0:ea44dc9ed014 88 else
joeverbout 0:ea44dc9ed014 89 {
joeverbout 0:ea44dc9ed014 90 dst = Matx<_Tp, _rows, _cols>(static_cast<const _Tp*>(src.data()));
joeverbout 0:ea44dc9ed014 91 }
joeverbout 0:ea44dc9ed014 92 }
joeverbout 0:ea44dc9ed014 93
joeverbout 0:ea44dc9ed014 94 template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
joeverbout 0:ea44dc9ed014 95 void cv2eigen( const Mat& src,
joeverbout 0:ea44dc9ed014 96 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
joeverbout 0:ea44dc9ed014 97 {
joeverbout 0:ea44dc9ed014 98 CV_DbgAssert(src.rows == _rows && src.cols == _cols);
joeverbout 0:ea44dc9ed014 99 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 100 {
joeverbout 0:ea44dc9ed014 101 const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 102 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 103 if( src.type() == _dst.type() )
joeverbout 0:ea44dc9ed014 104 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 105 else if( src.cols == src.rows )
joeverbout 0:ea44dc9ed014 106 {
joeverbout 0:ea44dc9ed014 107 src.convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 108 transpose(_dst, _dst);
joeverbout 0:ea44dc9ed014 109 }
joeverbout 0:ea44dc9ed014 110 else
joeverbout 0:ea44dc9ed014 111 Mat(src.t()).convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 112 }
joeverbout 0:ea44dc9ed014 113 else
joeverbout 0:ea44dc9ed014 114 {
joeverbout 0:ea44dc9ed014 115 const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 116 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 117 src.convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 118 }
joeverbout 0:ea44dc9ed014 119 }
joeverbout 0:ea44dc9ed014 120
joeverbout 0:ea44dc9ed014 121 // Matx case
joeverbout 0:ea44dc9ed014 122 template<typename _Tp, int _rows, int _cols, int _options, int _maxRows, int _maxCols> static inline
joeverbout 0:ea44dc9ed014 123 void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
joeverbout 0:ea44dc9ed014 124 Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCols>& dst )
joeverbout 0:ea44dc9ed014 125 {
joeverbout 0:ea44dc9ed014 126 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 127 {
joeverbout 0:ea44dc9ed014 128 const Mat _dst(_cols, _rows, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 129 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 130 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 131 }
joeverbout 0:ea44dc9ed014 132 else
joeverbout 0:ea44dc9ed014 133 {
joeverbout 0:ea44dc9ed014 134 const Mat _dst(_rows, _cols, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 135 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 136 Mat(src).copyTo(_dst);
joeverbout 0:ea44dc9ed014 137 }
joeverbout 0:ea44dc9ed014 138 }
joeverbout 0:ea44dc9ed014 139
joeverbout 0:ea44dc9ed014 140 template<typename _Tp> static inline
joeverbout 0:ea44dc9ed014 141 void cv2eigen( const Mat& src,
joeverbout 0:ea44dc9ed014 142 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
joeverbout 0:ea44dc9ed014 143 {
joeverbout 0:ea44dc9ed014 144 dst.resize(src.rows, src.cols);
joeverbout 0:ea44dc9ed014 145 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 146 {
joeverbout 0:ea44dc9ed014 147 const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 148 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 149 if( src.type() == _dst.type() )
joeverbout 0:ea44dc9ed014 150 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 151 else if( src.cols == src.rows )
joeverbout 0:ea44dc9ed014 152 {
joeverbout 0:ea44dc9ed014 153 src.convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 154 transpose(_dst, _dst);
joeverbout 0:ea44dc9ed014 155 }
joeverbout 0:ea44dc9ed014 156 else
joeverbout 0:ea44dc9ed014 157 Mat(src.t()).convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 158 }
joeverbout 0:ea44dc9ed014 159 else
joeverbout 0:ea44dc9ed014 160 {
joeverbout 0:ea44dc9ed014 161 const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 162 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 163 src.convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 164 }
joeverbout 0:ea44dc9ed014 165 }
joeverbout 0:ea44dc9ed014 166
joeverbout 0:ea44dc9ed014 167 // Matx case
joeverbout 0:ea44dc9ed014 168 template<typename _Tp, int _rows, int _cols> static inline
joeverbout 0:ea44dc9ed014 169 void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
joeverbout 0:ea44dc9ed014 170 Eigen::Matrix<_Tp, Eigen::Dynamic, Eigen::Dynamic>& dst )
joeverbout 0:ea44dc9ed014 171 {
joeverbout 0:ea44dc9ed014 172 dst.resize(_rows, _cols);
joeverbout 0:ea44dc9ed014 173 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 174 {
joeverbout 0:ea44dc9ed014 175 const Mat _dst(_cols, _rows, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 176 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 177 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 178 }
joeverbout 0:ea44dc9ed014 179 else
joeverbout 0:ea44dc9ed014 180 {
joeverbout 0:ea44dc9ed014 181 const Mat _dst(_rows, _cols, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 182 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 183 Mat(src).copyTo(_dst);
joeverbout 0:ea44dc9ed014 184 }
joeverbout 0:ea44dc9ed014 185 }
joeverbout 0:ea44dc9ed014 186
joeverbout 0:ea44dc9ed014 187 template<typename _Tp> static inline
joeverbout 0:ea44dc9ed014 188 void cv2eigen( const Mat& src,
joeverbout 0:ea44dc9ed014 189 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
joeverbout 0:ea44dc9ed014 190 {
joeverbout 0:ea44dc9ed014 191 CV_Assert(src.cols == 1);
joeverbout 0:ea44dc9ed014 192 dst.resize(src.rows);
joeverbout 0:ea44dc9ed014 193
joeverbout 0:ea44dc9ed014 194 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 195 {
joeverbout 0:ea44dc9ed014 196 const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 197 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 198 if( src.type() == _dst.type() )
joeverbout 0:ea44dc9ed014 199 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 200 else
joeverbout 0:ea44dc9ed014 201 Mat(src.t()).convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 202 }
joeverbout 0:ea44dc9ed014 203 else
joeverbout 0:ea44dc9ed014 204 {
joeverbout 0:ea44dc9ed014 205 const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 206 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 207 src.convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 208 }
joeverbout 0:ea44dc9ed014 209 }
joeverbout 0:ea44dc9ed014 210
joeverbout 0:ea44dc9ed014 211 // Matx case
joeverbout 0:ea44dc9ed014 212 template<typename _Tp, int _rows> static inline
joeverbout 0:ea44dc9ed014 213 void cv2eigen( const Matx<_Tp, _rows, 1>& src,
joeverbout 0:ea44dc9ed014 214 Eigen::Matrix<_Tp, Eigen::Dynamic, 1>& dst )
joeverbout 0:ea44dc9ed014 215 {
joeverbout 0:ea44dc9ed014 216 dst.resize(_rows);
joeverbout 0:ea44dc9ed014 217
joeverbout 0:ea44dc9ed014 218 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 219 {
joeverbout 0:ea44dc9ed014 220 const Mat _dst(1, _rows, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 221 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 222 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 223 }
joeverbout 0:ea44dc9ed014 224 else
joeverbout 0:ea44dc9ed014 225 {
joeverbout 0:ea44dc9ed014 226 const Mat _dst(_rows, 1, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 227 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 228 src.copyTo(_dst);
joeverbout 0:ea44dc9ed014 229 }
joeverbout 0:ea44dc9ed014 230 }
joeverbout 0:ea44dc9ed014 231
joeverbout 0:ea44dc9ed014 232
joeverbout 0:ea44dc9ed014 233 template<typename _Tp> static inline
joeverbout 0:ea44dc9ed014 234 void cv2eigen( const Mat& src,
joeverbout 0:ea44dc9ed014 235 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
joeverbout 0:ea44dc9ed014 236 {
joeverbout 0:ea44dc9ed014 237 CV_Assert(src.rows == 1);
joeverbout 0:ea44dc9ed014 238 dst.resize(src.cols);
joeverbout 0:ea44dc9ed014 239 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 240 {
joeverbout 0:ea44dc9ed014 241 const Mat _dst(src.cols, src.rows, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 242 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 243 if( src.type() == _dst.type() )
joeverbout 0:ea44dc9ed014 244 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 245 else
joeverbout 0:ea44dc9ed014 246 Mat(src.t()).convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 247 }
joeverbout 0:ea44dc9ed014 248 else
joeverbout 0:ea44dc9ed014 249 {
joeverbout 0:ea44dc9ed014 250 const Mat _dst(src.rows, src.cols, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 251 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 252 src.convertTo(_dst, _dst.type());
joeverbout 0:ea44dc9ed014 253 }
joeverbout 0:ea44dc9ed014 254 }
joeverbout 0:ea44dc9ed014 255
joeverbout 0:ea44dc9ed014 256 //Matx
joeverbout 0:ea44dc9ed014 257 template<typename _Tp, int _cols> static inline
joeverbout 0:ea44dc9ed014 258 void cv2eigen( const Matx<_Tp, 1, _cols>& src,
joeverbout 0:ea44dc9ed014 259 Eigen::Matrix<_Tp, 1, Eigen::Dynamic>& dst )
joeverbout 0:ea44dc9ed014 260 {
joeverbout 0:ea44dc9ed014 261 dst.resize(_cols);
joeverbout 0:ea44dc9ed014 262 if( !(dst.Flags & Eigen::RowMajorBit) )
joeverbout 0:ea44dc9ed014 263 {
joeverbout 0:ea44dc9ed014 264 const Mat _dst(_cols, 1, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 265 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 266 transpose(src, _dst);
joeverbout 0:ea44dc9ed014 267 }
joeverbout 0:ea44dc9ed014 268 else
joeverbout 0:ea44dc9ed014 269 {
joeverbout 0:ea44dc9ed014 270 const Mat _dst(1, _cols, DataType<_Tp>::type,
joeverbout 0:ea44dc9ed014 271 dst.data(), (size_t)(dst.stride()*sizeof(_Tp)));
joeverbout 0:ea44dc9ed014 272 Mat(src).copyTo(_dst);
joeverbout 0:ea44dc9ed014 273 }
joeverbout 0:ea44dc9ed014 274 }
joeverbout 0:ea44dc9ed014 275
joeverbout 0:ea44dc9ed014 276 //! @}
joeverbout 0:ea44dc9ed014 277
joeverbout 0:ea44dc9ed014 278 } // cv
joeverbout 0:ea44dc9ed014 279
joeverbout 0:ea44dc9ed014 280 #endif
joeverbout 0:ea44dc9ed014 281