Skip to content

add test for PR #22253#22594

Merged
asmorkalov merged 2 commits intoopencv:4.xfrom
ZhaoChuyang:pr_test_for_22253
Dec 1, 2022
Merged

add test for PR #22253#22594
asmorkalov merged 2 commits intoopencv:4.xfrom
ZhaoChuyang:pr_test_for_22253

Conversation

@ZhaoChuyang
Copy link
Copy Markdown
Contributor

@ZhaoChuyang ZhaoChuyang commented Oct 2, 2022

Description

This bug happens when try to generate python-bindings for a function which takes cv::Vec as default arguments.
For example, I designed a function randomCrop which takes padding of dtype cv::Vec4i as default argument:

randomCrop(InputArray src, OutputArray dst, const Size& sz, const Vec4i& padding=Vec4i() , bool pad_if_need=false, int fill=0, int padding_mode=BORDER_CONSTANT);

When I trying to generate python-binding for this function, nothing wrong happens.
But when the user use this function in python environment, and they treat padding as default argument so they don't pass value for this argument. They may call this function like this:

# padding is default argument, it should be Vec4i() if we don't pass any value for it
randomCrop(img, np.array([100, 100]))

Then wired thing happens, the python generator calls pyopencv_to on line 63 of cv2_convert.hpp, trying to convert the python object into Vec4i. But this function pyopencv_to omit the case when this argument has default value and user passes no value for it. In this case, the function trying to copy a None object tmp to the target mx, which will raise error in the copyTo procedure.

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

@asmorkalov asmorkalov added this to the 4.7.0 milestone Dec 1, 2022
@asmorkalov asmorkalov merged commit 5696629 into opencv:4.x Dec 1, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
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.

3 participants