Merge pull request #10108 from mshabunin:fix-eigen-stride

pull/10066/merge
Alexander Alekhin 7 years ago
commit 017a38a54e
  1. 36
      modules/core/include/opencv2/core/eigen.hpp

@ -65,13 +65,13 @@ void eigen2cv( const Eigen::Matrix<_Tp, _rows, _cols, _options, _maxRows, _maxCo
if( !(src.Flags & Eigen::RowMajorBit) ) if( !(src.Flags & Eigen::RowMajorBit) )
{ {
Mat _src(src.cols(), src.rows(), traits::Type<_Tp>::value, Mat _src(src.cols(), src.rows(), traits::Type<_Tp>::value,
(void*)src.data(), src.stride()*sizeof(_Tp)); (void*)src.data(), src.outerStride()*sizeof(_Tp));
transpose(_src, dst); transpose(_src, dst);
} }
else else
{ {
Mat _src(src.rows(), src.cols(), traits::Type<_Tp>::value, Mat _src(src.rows(), src.cols(), traits::Type<_Tp>::value,
(void*)src.data(), src.stride()*sizeof(_Tp)); (void*)src.data(), src.outerStride()*sizeof(_Tp));
_src.copyTo(dst); _src.copyTo(dst);
} }
} }
@ -99,7 +99,7 @@ void cv2eigen( const Mat& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
if( src.type() == _dst.type() ) if( src.type() == _dst.type() )
transpose(src, _dst); transpose(src, _dst);
else if( src.cols == src.rows ) else if( src.cols == src.rows )
@ -113,7 +113,7 @@ void cv2eigen( const Mat& src,
else else
{ {
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type()); src.convertTo(_dst, _dst.type());
} }
} }
@ -126,13 +126,13 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, const Mat _dst(_cols, _rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
transpose(src, _dst); transpose(src, _dst);
} }
else else
{ {
const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, const Mat _dst(_rows, _cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
Mat(src).copyTo(_dst); Mat(src).copyTo(_dst);
} }
} }
@ -145,7 +145,7 @@ void cv2eigen( const Mat& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
if( src.type() == _dst.type() ) if( src.type() == _dst.type() )
transpose(src, _dst); transpose(src, _dst);
else if( src.cols == src.rows ) else if( src.cols == src.rows )
@ -159,7 +159,7 @@ void cv2eigen( const Mat& src,
else else
{ {
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type()); src.convertTo(_dst, _dst.type());
} }
} }
@ -173,13 +173,13 @@ void cv2eigen( const Matx<_Tp, _rows, _cols>& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(_cols, _rows, traits::Type<_Tp>::value, const Mat _dst(_cols, _rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
transpose(src, _dst); transpose(src, _dst);
} }
else else
{ {
const Mat _dst(_rows, _cols, traits::Type<_Tp>::value, const Mat _dst(_rows, _cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
Mat(src).copyTo(_dst); Mat(src).copyTo(_dst);
} }
} }
@ -194,7 +194,7 @@ void cv2eigen( const Mat& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
if( src.type() == _dst.type() ) if( src.type() == _dst.type() )
transpose(src, _dst); transpose(src, _dst);
else else
@ -203,7 +203,7 @@ void cv2eigen( const Mat& src,
else else
{ {
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type()); src.convertTo(_dst, _dst.type());
} }
} }
@ -218,13 +218,13 @@ void cv2eigen( const Matx<_Tp, _rows, 1>& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(1, _rows, traits::Type<_Tp>::value, const Mat _dst(1, _rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
transpose(src, _dst); transpose(src, _dst);
} }
else else
{ {
const Mat _dst(_rows, 1, traits::Type<_Tp>::value, const Mat _dst(_rows, 1, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
src.copyTo(_dst); src.copyTo(_dst);
} }
} }
@ -239,7 +239,7 @@ void cv2eigen( const Mat& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value, const Mat _dst(src.cols, src.rows, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
if( src.type() == _dst.type() ) if( src.type() == _dst.type() )
transpose(src, _dst); transpose(src, _dst);
else else
@ -248,7 +248,7 @@ void cv2eigen( const Mat& src,
else else
{ {
const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value, const Mat _dst(src.rows, src.cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
src.convertTo(_dst, _dst.type()); src.convertTo(_dst, _dst.type());
} }
} }
@ -262,13 +262,13 @@ void cv2eigen( const Matx<_Tp, 1, _cols>& src,
if( !(dst.Flags & Eigen::RowMajorBit) ) if( !(dst.Flags & Eigen::RowMajorBit) )
{ {
const Mat _dst(_cols, 1, traits::Type<_Tp>::value, const Mat _dst(_cols, 1, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
transpose(src, _dst); transpose(src, _dst);
} }
else else
{ {
const Mat _dst(1, _cols, traits::Type<_Tp>::value, const Mat _dst(1, _cols, traits::Type<_Tp>::value,
dst.data(), (size_t)(dst.stride()*sizeof(_Tp))); dst.data(), (size_t)(dst.outerStride()*sizeof(_Tp)));
Mat(src).copyTo(_dst); Mat(src).copyTo(_dst);
} }
} }

Loading…
Cancel
Save