8000 Extend the signature of imdecodemulti() by kochanczyk · Pull Request #24405 · opencv/opencv · GitHub
[go: up one dir, main page]

Skip to content

Extend the signature of imdecodemulti() #24405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 30, 2023
Merged

Extend the signature of imdecodemulti() #24405

merged 8 commits into from
Oct 30, 2023

Conversation

kochanczyk
Copy link
Contributor
@kochanczyk kochanczyk commented Oct 14, 2023

(Edited after addressing Reviewers' comments.)

Add an argument to imdecodemulti() to enable optional selection of pages of multi-page images.

Be default, all pages are decoded. If used, the additional argument may specify a continuous selection of pages to decode.

Pull Request Readiness Checklist

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

  • 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
  • I agree to contribute to the project under Apache 2 License.
  • 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

Add an overload of imdecodemulti() to decode a single, selected image from a buffer in memory that holds a multi-page image
@asmorkalov asmorkalov added category: imgcodecs feature pr: needs test New functionality requires minimal tests set labels Oct 17, 2023
@asmorkalov
Copy link
Contributor

@kochanczyk thanks a lot for the PR. Could you add test like this: https://github.com/opencv/opencv/blob/4.x/modules/imgcodecs/test/test_tiff.cpp#L968.

@vpisarev vpisarev self-requested a review October 17, 2023 17:09
@vpisarev
Copy link
Contributor
vpisarev commented Oct 17, 2023

@kochanczyk, thanks for the patch! It looks like a useful addition. I suggest however not to add extra entry, but add an optional const Range& range = Range::all() parameter to the existing function.

Also, please, add a test for this functionality

Copy link
Contributor
@vpisarev vpisarev left a comment

Choose a reason for hiding this comment

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

pls, extend existing function, as described above

…ges of multi-page images

Be default, all pages are decoded. If used, the additional argument may specify a continuous selection of pages to decode.
@kochanczyk
Copy link
Contributor Author
kochanczyk commented Oct 17, 2023

Dear Alex and Vadim, as per your requests, I used cv::Range and provided a separate test. Thank you for your interest and feedback.

@vpisarev Update: It seems that the recommended use of const Range& breaks building with the iOS Framework (ObjC++ bindings for imgcodecs do not compile).

Update: In commit 18894cf I've tried passing the range by value, not by reference, however this did not fix the issue for the iOS. I have no experience with this framework. Are you able to advise how this can be fixed?

@kochanczyk kochanczyk changed the title Add an overload of imdecodemulti() Extend the signature of imdecodemulti() Oct 17, 2023
Comment on lines 1038 to 1056
for (size_t start = 0; start < page_count; start++)
{
for (size_t end = start + 1; end <= page_count; end++)
{
vector<Mat> pages_from_imdecodemulti;
Range const range(start, end);
bool res = imdecodemulti(buf, mode, pages_from_imdecodemulti, range);
ASSERT_TRUE(res == true);
ASSERT_EQ(static_cast<size_t>(range.size()), pages_from_imdecodemulti.size());

for (int i = range.start; i < range.end; i++)
{
EXPECT_PRED_FORMAT2(cvtest::MatComparator(0, 0),
pages_from_imread[i],
pages_from_imdecodemulti[i - range.start]);
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not think that we need all combination here. It's enough to call imdecodemulti once with trange like (1, size-2) to check not default behaviour. Other cases and tiff specific are indirectly tested with imreadmulti.

Copy link
Contributor Author
@kochanczyk kochanczyk Oct 18, 2023

Choose a reason for hiding this comment

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

I have revised the code as requested, but please note that, strictly speaking, the proposed test did not check all combinations, which would be nonsensical, but all contiguous subsequences. If you have a sequence of length n, there are n × (n + 1)/2 ~ O(n2) contiguous subsequences, which for the current n = 6 gives 21.

Also, in test decode_multipage_use_memory_buffer_all_pages, binary file reading is revised to be identical to that in test decode_multipage_use_memory_buffer_selected_pages.
@kochanczyk kochanczyk requested a review from asmorkalov October 19, 2023 10:21
Copy link
Contributor
@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

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

👍

@asmorkalov asmorkalov removed the pr: needs test New functionality requires minimal tests set label Oct 19, 2023
This change fixes building OpenCV under iOS Framework.
@kochanczyk kochanczyk requested a review from vpisarev October 19, 2023 11:45
else
{
CV_Assert( range.start >= 0 );
CV_Assert( range.size() > 0 );
Copy link
Contributor

Choose a reason for hiding this comment

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

CV_CheckGE
CV_CheckGT

@asmorkalov asmorkalov added this to the 4.9.0 milestone Oct 20, 2023
The reverted change (1) did not fix building OpenCV under iOS Framework
(contrary to wishful thinking in the reverted commit message) and additionally
(2) created an opportunity for object slicing.

This reverts commit 18894cf.
@opencv-alalek
Copy link
Contributor

Updated skip list with imreadmulti in ABI/API checker on CI.

@asmorkalov
Copy link
Contributor

The iOS issue is related to Obj-C/Swift bindings issue:

/Users/opencv-cn/GHA-OCV-4/_work/opencv/opencv/ios/build/build-armv7-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/Imgcodecs.mm:124:71: error: reference to type 'const cv::Range' could not bind to an lvalue of type 'Range *__strong _Nonnull'
    bool retVal = cv::imdecodemulti(buf.nativeRef, flags, matsVector, range);
                                                                      ^~~~~
In file included from /Users/opencv-cn/GHA-OCV-4/_work/opencv/opencv/ios/build/build-armv7-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/Imgcodecs.mm:5:
In file included from /Users/opencv-cn/GHA-OCV-4/_work/opencv/opencv/ios/build/build-armv7-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/Imgcodecs.h:8:
/Users/opencv-cn/GHA-OCV-4/_work/opencv/opencv/ios/build/build-armv7-iphoneos/install/include/opencv2/imgcodecs.hpp:342:108: note: passing argument to parameter 'range' here
CV_EXPORTS_W bool imdecodemulti(InputArray buf, int flags, CV_OUT std::vector<Mat>& mats, const cv::Range& range = Range::all());
                                                                                                           ^
1 error generated.

@VadimLevin @komakai could you help with it?

@VadimLevin
Copy link
Contributor

The issue lies on generator side, because Obj-C doesn't support default function arguments.

As a workaround you can create 2 functions:

CV_EXPORTS_W bool imdecodemulti(InputArray buf, int flags, CV_OUT std::vector<Mat>& mats) {
  return imdecodemulti(buf, flags, mats, Range::all());
}

CV_EXPORTS_W bool imdecodemulti(InputArray buf, int flags, CV_OUT std::vector<Mat>& mats,
                                const cv::Range& range);

Or this should be handled on generator side: For each function with default arguments create a trampoline function with and without defaulted argument.

I'm not familiar with Obj-C generator, maybe it is already working that way.

@komakai
Copy link
Contributor
komakai commented Oct 25, 2023

@asmorkalov @VadimLevin
Because the mapping from C++ to Objective-C can never be perfect there are ways to handle situations like this via gen_dict.json file
Looking at the config in
https://github.com/opencv/opencv/blob/4.x/modules/core/misc/objc/gen_dict.json
it appears there is an entry already for cv::Range but it is incomplete
Possibly adding these lines might fix it

            "to_cpp": "%(n)s.nativeRef",
            "from_cpp": "[Range fromNative:%(n)s]"

This is an attempt to fix a building issue under iOS caused by a recently added default-valued argument in imdecodemulti().
@@ -167,7 +167,9 @@
"from_cpp": "[Point3i fromNative:%(n)s]"
},
"Range": {
"objc_type": "Range*"
"objc_type": "Range*",
"to_cpp": "%(n)s.nativeRef",
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good - let me know if that works OK - if it doesn't then I'll take a closer look

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komakai This change unfortunately still does not fix the issue:

/Users/opencv-cn/GHA-OCV-1/_work/opencv/opencv/ios/build/build-armv7-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/Imgcodecs.mm:124:77: error: property 'nativeRef' not found on object of type 'Range *'
    bool retVal = cv::imdecodemulti(buf.nativeRef, flags, matsVector, range.nativeRef);
                                                                            ^
1 error generated.

https://github.com/opencv/opencv/actions/runs/6644615646/job/18069638575?pr=24405#step:7:7279

Copy link
Contributor
@komakai komakai Oct 26, 2023

Choose a reason for hiding this comment

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

@kochanczyk OK - let me take a closer look

@asmorkalov
Copy link
Contributor

iOS build:

/Users/opencv-cn/GHA-OCV-1/_work/opencv/opencv/ios/build/build-armv7-iphoneos/modules/objc_bindings_generator/ios/gen/objc/imgcodecs/Imgcodecs.mm:124:77: error: property 'nativeRef' not found on object of type 'Range *'
    bool retVal = cv::imdecodemulti(buf.nativeRef, flags, matsVector, range.nativeRef);
                                                                            ^

@komakai komakai mentioned this pull request Oct 26, 2023
3 tasks
@komakai
Copy link
Contributor
komakai commented Oct 26, 2023

@kochanczyk @asmorkalov Can you try with PR #24454 ? That should solve it

asmorkalov pushed a commit that referenced this pull request Oct 27, 2023
Refactor ObjectiveC Range class #24454

### Pull Request Readiness Checklist

- [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

Fix for build issue in #24405
@asmorkalov
Copy link
Contributor

@komakai Thanks a lot for the quick solution. The related PR has been merged.
@kochanczyk Could you rebase your branch on top of current 4.x to include the patch.

@asmorkalov asmorkalov merged commit e9e6b1e into opencv:4.x Oct 30, 2023
@kochanczyk
Copy link
Contributor Author

Dear Giles, Alex, and Vadim, thank you very much for all your assistance! I am happy to see the pull request merged.

@asmorkalov asmorkalov mentioned this pull request Nov 3, 2023
IskXCr pushed a commit to Haosonn/opencv that referenced this pull request Dec 20, 2023
Refactor ObjectiveC Range class opencv#24454

### Pull Request Readiness Checklist

- [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

Fix for build issue in opencv#24405
IskXCr pushed a commit to Haosonn/opencv that referenced this pull request Dec 20, 2023
Extend the signature of imdecodemulti() opencv#24405

(Edited after addressing Reviewers' comments.)

Add an argument to `imdecodemulti()` to enable optional selection of pages of multi-page images.

Be default, all pages are decoded. If used, the additional argument may specify a continuous selection of pages to decode.


### Pull Request Readiness Checklist

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

- [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] I agree to contribute to the project under Apache 2 License.
- [X] The PR is proposed to the proper branch
- [ ] 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
@opencv-alalek opencv-alalek removed their request for review December 26, 2023 20:45
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Refactor ObjectiveC Range class opencv#24454

### Pull Request Readiness Checklist

- [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

Fix for build issue in opencv#24405
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Extend the signature of imdecodemulti() opencv#24405

(Edited after addressing Reviewers' comments.)

Add an argument to `imdecodemulti()` to enable optional selection of pages of multi-page images.

Be default, all pages are decoded. If used, the additional argument may specify a continuous selection of pages to decode.


### Pull Request Readiness Checklist

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

- [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] I agree to contribute to the project under Apache 2 License.
- [X] The PR is proposed to the proper branch
- [ ] 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Refactor ObjectiveC Range class opencv#24454

### Pull Request Readiness Checklist

- [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

Fix for build issue in opencv#24405
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Extend the signature of imdecodemulti() opencv#24405

(Edited after addressing Reviewers' comments.)

Add an argument to `imdecodemulti()` to enable optional selection of pages of multi-page images.

Be default, all pages are decoded. If used, the additional argument may specify a continuous selection of pages to decode.


### Pull Request Readiness Checklist

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

- [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] I agree to contribute to the project under Apache 2 License.
- [X] The PR is proposed to the proper branch
- [ ] 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0