Skip to content

Support 0d/1d Mat in FileStorage#26420

Merged
asmorkalov merged 2 commits intoopencv:5.xfrom
dkurt:fs_mat_0d_1d
Nov 6, 2024
Merged

Support 0d/1d Mat in FileStorage#26420
asmorkalov merged 2 commits intoopencv:5.xfrom
dkurt:fs_mat_0d_1d

Conversation

@dkurt
Copy link
Copy Markdown
Member

@dkurt dkurt commented Nov 5, 2024

Pull Request Readiness Checklist

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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@dkurt dkurt added this to the 5.0-alpha milestone Nov 5, 2024
@vpisarev
Copy link
Copy Markdown
Contributor

vpisarev commented Nov 5, 2024

@dkurt, this is definitely useful!

I wonder, if you write to FileStorage an empty mat:

fs << "empty-mat" << Mat();

whether it will be done correctly? I mean, 0-dimensional matrix can mean two different things in OpenCV, a scalar or an empty matrix, depending on whether data == nullptr or not (can use Mat::empty() method as well).

@dkurt
Copy link
Copy Markdown
Member Author

dkurt commented Nov 5, 2024

@vpisarev, added a test for empty Mat and required changes to handle it properly.

@asmorkalov asmorkalov self-requested a review November 5, 2024 18:25
@asmorkalov asmorkalov self-assigned this Nov 6, 2024
@asmorkalov asmorkalov merged commit 286f752 into opencv:5.x Nov 6, 2024
@dkurt dkurt deleted the fs_mat_0d_1d branch November 6, 2024 08:41
@dkurt dkurt added the port into 4.x is needed Label for maintainers. Authors of PR can ignore this label Nov 11, 2024
}

typedef testing::TestWithParam<const char*> FileStorage_exact_type;
TEST_P(FileStorage_exact_type, empty_mat)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test raises debug assertion

[ RUN      ] Core_InputOutput/FileStorage_exact_type.empty_mat/0, where GetParam() = ".yml"
unknown file: Failure
C++ exception with description "OpenCV(5.0.0-pre) /work/opencv/modules/core/include/opencv2/core/mat.inl.hpp:1349: error: (-215:Assertion failed) i < dims() in function 'operator[]'
" thrown in the test body.
[  FAILED  ] Core_InputOutput/FileStorage_exact_type.empty_mat/0, where GetParam() = ".yml" (1 ms)

Here:

inline
int& MatSize::operator[](int i)
{
CV_DbgAssert(i < dims());
#ifdef __OPENCV_BUILD
CV_DbgAssert(i >= 0);
#endif
return p[i];
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same on 4.x branch, thanks. I will check

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at #26444

@dkurt dkurt mentioned this pull request Nov 11, 2024
6 tasks
@dkurt dkurt added port/backport done Label for maintainers. Authors of PR can ignore this and removed port into 4.x is needed Label for maintainers. Authors of PR can ignore this labels Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: core feature port/backport done Label for maintainers. Authors of PR can ignore this

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants