Merge pull request #22346 from fengyuentau:mat1d_part1

Changes separated from Mat 1D support in core #18594 (#22346)
This commit is contained in:
Yuantao Feng 2022-09-09 17:56:30 +08:00 committed by GitHub
parent 65d66a05dd
commit 9dc844a6e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 5 deletions

View File

@ -168,7 +168,7 @@ static void binary_op( InputArray _src1, InputArray _src2, OutputArray _dst,
if( dims1 <= 2 && dims2 <= 2 && kind1 == kind2 && sz1 == sz2 && type1 == type2 && !haveMask )
{
_dst.create(sz1, type1);
_dst.createSameSize(*psrc1, type1);
CV_OCL_RUN(use_opencl,
ocl_binary_op(*psrc1, *psrc2, _dst, _mask, bitwise, oclop, false))
@ -1225,7 +1225,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
if( kind1 == kind2 && src1.dims <= 2 && src2.dims <= 2 && src1.size() == src2.size() && src1.type() == src2.type() )
{
int cn = src1.channels();
_dst.create(src1.size(), CV_8UC(cn));
_dst.createSameSize(src1, CV_8UC(cn));
Mat dst = _dst.getMat();
Size sz = getContinuousSize2D(src1, src2, dst, src1.channels());
BinaryFuncC cmpFn = getCmpFunc(depth1);

View File

@ -1565,13 +1565,24 @@ void cv::minMaxLoc( InputArray _img, double* minVal, double* maxVal,
{
CV_INSTRUMENT_REGION();
CV_Assert(_img.dims() <= 2);
int dims = _img.dims();
CV_CheckLE(dims, 2, "");
minMaxIdx(_img, minVal, maxVal, (int*)minLoc, (int*)maxLoc, mask);
if( minLoc )
std::swap(minLoc->x, minLoc->y);
{
if (dims == 2)
std::swap(minLoc->x, minLoc->y);
else
minLoc->y = 0;
}
if( maxLoc )
std::swap(maxLoc->x, maxLoc->y);
{
if (dims == 2)
std::swap(maxLoc->x, maxLoc->y);
else
maxLoc->y = 0;
}
}
enum class ReduceMode

View File

@ -2354,6 +2354,96 @@ TEST(Mat, regression_18473)
EXPECT_EQ((int)5, (int)m.at<short>(19, 49, 99));
}
// FITIT: remove DISABLE_ when 1D Mat is supported
TEST(Mat1D, DISABLED_basic)
{
std::vector<int> sizes { 100 };
Mat m1(sizes, CV_8UC1, Scalar::all(5));
m1.at<uchar>(50) = 10;
EXPECT_FALSE(m1.empty());
ASSERT_EQ(1, m1.dims);
ASSERT_EQ(1, m1.size.dims()); // hack map on .rows
EXPECT_EQ(Size(100, 1), m1.size());
{
SCOPED_TRACE("clone");
Mat m = m1.clone();
EXPECT_EQ(1, m.dims);
EXPECT_EQ(Size(100, 1), m.size());
}
{
SCOPED_TRACE("colRange()");
Mat m = m1.colRange(Range(10, 30));
EXPECT_EQ(1, m.dims);
EXPECT_EQ(Size(20, 1), m.size());
}
{
SCOPED_TRACE("reshape(1, 1)");
Mat m = m1.reshape(1, 1);
EXPECT_EQ(1, m.dims);
EXPECT_EQ(Size(100, 1), m.size());
}
{
SCOPED_TRACE("reshape(1, 100)");
Mat m = m1.reshape(1, 100);
EXPECT_EQ(2, m.dims);
EXPECT_EQ(Size(1, 100), m.size());
}
{
SCOPED_TRACE("reshape(1, {1, 100})");
Mat m = m1.reshape(1, {1, 100});
EXPECT_EQ(2, m.dims);
EXPECT_EQ(Size(100, 1), m.size());
}
{
SCOPED_TRACE("copyTo(std::vector<uchar>)");
std::vector<uchar> dst;
m1.copyTo(dst);
EXPECT_EQ(100u, dst.size());
}
{
SCOPED_TRACE("copyTo(row2D)");
Mat m(5, 100, CV_8UC1, Scalar::all(0));
const Mat row2D = m.row(2);
EXPECT_NO_THROW(m1.copyTo(row2D));
}
{
SCOPED_TRACE("convertTo(row2D)");
Mat m(5, 100, CV_32FC1, Scalar::all(0));
const Mat row2D = m.row(2);
EXPECT_NO_THROW(m1.convertTo(row2D, CV_32FC1));
}
{
SCOPED_TRACE("CvMat");
CvMat c_mat = cvMat(m1);
EXPECT_EQ(100, c_mat.cols);
EXPECT_EQ(1, c_mat.rows);
}
{
SCOPED_TRACE("CvMatND");
CvMatND c_mat = cvMatND(m1);
EXPECT_EQ(2, c_mat.dims);
EXPECT_EQ(100, c_mat.dim[0].size);
EXPECT_EQ(1, c_mat.dim[1].size);
}
{
SCOPED_TRACE("minMaxLoc");
Point pt;
minMaxLoc(m1, 0, 0, 0, &pt);
EXPECT_EQ(50, pt.x);
EXPECT_EQ(0, pt.y);
}
}
TEST(Mat, ptrVecni_20044)
{