Merge pull request #25945 from vrabaud:02_fix

Fix size() for 0d matrix #25945

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
pull/25972/head
Vincent Rabaud 6 months ago committed by GitHub
parent 908c59ae25
commit ae4c67e3a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      modules/core/include/opencv2/core/mat.inl.hpp
  2. 7
      modules/core/include/opencv2/core/types.hpp
  3. 10
      modules/core/test/test_mat.cpp

@ -1275,7 +1275,7 @@ Size MatSize::operator()() const
{
int d = dims();
CV_DbgAssert(d <= 2);
return d == 2 ? Size(p[1], p[0]) : Size(p[0], 1);
return d == 2 ? Size(p[1], p[0]) : d == 1 ? Size(p[0], 1) : Size(0, 0);
}
inline

@ -320,10 +320,13 @@ struct Type< Point3_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 3) }
/** @brief Template class for specifying the size of an image or rectangle.
The class includes two members called width and height. The structure can be converted to and from
the old OpenCV structures CvSize and CvSize2D32f . The same set of arithmetic and comparison
The class includes two members called width and height. The same set of arithmetic and comparison
operations as for Point_ is available.
For a 1d matrix, the size is (width, 1) and for a 0d matrix, it is (1, 1).
For an empty matrix, it is (0, 0).
OpenCV defines the following Size_\<\> aliases:
@code
typedef Size_<int> Size2i;

@ -2414,7 +2414,15 @@ TEST(Mat, regression_18473)
EXPECT_EQ((int)5, (int)m.at<short>(19, 49, 99));
}
// FITIT: remove DISABLE_ when 1D Mat is supported
TEST(Mat0D, basic)
{
Mat1b m1, m2(0, nullptr);
ASSERT_EQ(0, m1.size().width);
ASSERT_EQ(0, m1.size().height);
ASSERT_EQ(1, m2.size().width);
ASSERT_EQ(1, m2.size().height);
}
TEST(Mat1D, basic)
{
std::vector<int> sizes { 100 };

Loading…
Cancel
Save