Skip to content

pass 3d arrays from py to cpp#20462

Closed
spazewalker wants to merge 1 commit intoopencv:masterfrom
spazewalker:passing-3d
Closed

pass 3d arrays from py to cpp#20462
spazewalker wants to merge 1 commit intoopencv:masterfrom
spazewalker:passing-3d

Conversation

@spazewalker
Copy link
Copy Markdown
Contributor

@spazewalker spazewalker commented Jul 26, 2021

addressing #19091

Currently OpenCV Python bindings "automatically" converts 3D NumPy arrays into 2D cv::Mat with wrapping last dimension onto number of channels (to simulate Image with colors)

We don't need to treat array passed from dnn::net::setInput() as an image. isImage in ArgInfo class does that in this solution.

relates #17272
relates #19001
probably relates #18413 #17456

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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

@spazewalker spazewalker changed the title added ability to pass 3d arrays from py to cpp pass 3d arrays from py to cpp Jul 26, 2021
@l-bat l-bat requested a review from alalek July 27, 2021 07:59
@alalek alalek mentioned this pull request Aug 2, 2021
6 tasks
# Do not treat blob as an image while passing
# from python to cpp if passed from setInput()
if name=='setInput' and a[1]=='blob':
ainfo.isImage=False
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In general, this approach is a breaking change of existed API.

@l-bat Could you try to apply workaround similar to #20480? Something like:

input = np.expand_dims(input, axis=2)  # Workaround for: https://github.com/opencv/opencv/issues/19091

with comment with reference on the issue #19091.

@VadimLevin
Copy link
Copy Markdown
Contributor

Just a small question:
Is a custom binding for a single function variant a better approach than trying to cover a case for this function in a general place?

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.

4 participants