提交 088535fa 编写于 作者: R Roman Donchenko 提交者: OpenCV Buildbot

Merge pull request #2159 from SpecLad:1xN

......@@ -232,10 +232,7 @@ void Mat::copyTo( OutputArray _dst ) const
const uchar* sptr = data;
uchar* dptr = dst.data;
// to handle the copying 1xn matrix => nx1 std vector.
Size sz = size() == dst.size() ?
getContinuousSize(*this, dst) :
getContinuousSize(*this);
Size sz = getContinuousSize(*this, dst);
size_t len = sz.width*elemSize();
for( ; sz.height--; sptr += step, dptr += dst.step )
......@@ -286,6 +283,7 @@ void Mat::copyTo( OutputArray _dst, InputArray _mask ) const
if( dims <= 2 )
{
CV_Assert( size() == mask.size() );
Size sz = getContinuousSize(*this, dst, mask, mcn);
copymask(data, step, mask.data, mask.step, dst.data, dst.step, sz, &esz);
return;
......
......@@ -129,14 +129,12 @@ template<typename T> struct OpMax
inline Size getContinuousSize( const Mat& m1, int widthScale=1 )
{
CV_Assert(m1.dims <= 2);
return m1.isContinuous() ? Size(m1.cols*m1.rows*widthScale, 1) :
Size(m1.cols*widthScale, m1.rows);
}
inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
{
CV_Assert(m1.dims <= 2 && m1.size() == m2.size());
return (m1.flags & m2.flags & Mat::CONTINUOUS_FLAG) != 0 ?
Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
}
......@@ -144,7 +142,6 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2, int widthScale=1 )
inline Size getContinuousSize( const Mat& m1, const Mat& m2,
const Mat& m3, int widthScale=1 )
{
CV_Assert(m1.dims <= 2 && m1.size() == m2.size() && m1.size() == m3.size());
return (m1.flags & m2.flags & m3.flags & Mat::CONTINUOUS_FLAG) != 0 ?
Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
}
......@@ -153,7 +150,6 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2,
const Mat& m3, const Mat& m4,
int widthScale=1 )
{
CV_Assert(m1.dims <= 2 && m1.size() == m2.size() && m1.size() == m3.size() && m1.size() == m4.size());
return (m1.flags & m2.flags & m3.flags & m4.flags & Mat::CONTINUOUS_FLAG) != 0 ?
Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
}
......@@ -162,7 +158,6 @@ inline Size getContinuousSize( const Mat& m1, const Mat& m2,
const Mat& m3, const Mat& m4,
const Mat& m5, int widthScale=1 )
{
CV_Assert(m1.dims <= 2 && m1.size() == m2.size() && m1.size() == m3.size() && m1.size() == m4.size() && m1.size() == m5.size());
return (m1.flags & m2.flags & m3.flags & m4.flags & m5.flags & Mat::CONTINUOUS_FLAG) != 0 ?
Size(m1.cols*m1.rows*widthScale, 1) : Size(m1.cols*widthScale, m1.rows);
}
......
......@@ -897,3 +897,24 @@ TEST(Core_Mat, reshape_1942)
);
ASSERT_EQ(1, cn);
}
TEST(Core_Mat, copyNx1ToVector)
{
cv::Mat_<uchar> src(5, 1);
cv::Mat_<uchar> ref_dst8;
cv::Mat_<ushort> ref_dst16;
std::vector<uchar> dst8;
std::vector<ushort> dst16;
src << 1, 2, 3, 4, 5;
src.copyTo(ref_dst8);
src.copyTo(dst8);
ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst8, cv::Mat_<uchar>(dst8));
src.convertTo(ref_dst16, CV_16U);
src.convertTo(dst16, CV_16U);
ASSERT_PRED_FORMAT2(cvtest::MatComparator(0, 0), ref_dst16, cv::Mat_<ushort>(dst16));
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册