Skip to content

[G-API] Wrap GArray#18762

Merged
alalek merged 7 commits intoopencv:masterfrom
TolyaTalamanov:at/support-garray
Nov 27, 2020
Merged

[G-API] Wrap GArray#18762
alalek merged 7 commits intoopencv:masterfrom
TolyaTalamanov:at/support-garray

Conversation

@TolyaTalamanov
Copy link
Copy Markdown
Contributor

@TolyaTalamanov TolyaTalamanov commented Nov 9, 2020

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

Overview

Changes

  • Added struct GTypeInfo which stores GShape & GKind.
  • Implemented function collectInfo which collect GTypeInfo from input/output node handles in the ade::Graph, such kind of information are needed to:
    • Properly allocate outputs ( Python GComputation.apply() doesn't take output args, so need to allocate their inside)
    • Properly extract inputs ( Need to know how to represent values coming from python. Example: If we have tuple contains 4 values and can be represented as cv::Scalar or cv::Rect)
  • Added CV_POINT2F to GKind to handle GArray<cv::Point2f>
  • Wrapped GGoodFeatures operation
  • Wrapped GArray<cv::Point2f> as GArrayP2f into python (GArray is supported only for output)

Implementation details

GArray is a template class, so it can't be wrapped to python as is. The solution is wrap all instances corresponding in GKind. Now only instance for GArray<cv::Point2f> (cv::GShape::CV_POINT2F) is wrapped. For this, need to create using on GArraycv::Point2f`:

using GArrayP2f = cv::GArray<cv::Point2f>

and put this:

class GAPI_EXPORTS_W_SIMPLE GArrayP2f { };

to shadow_gapi.hpp to force python generate code for this instance.
Such principle will be used for wrapping other GArray & GOpaque types.

Kind cv::GKind::CV_UNKNOWN isn't planned to be supported, yet

Build configuration

force_builders=Custom,Custom Win,Custom Mac
build_gapi_standalone:Linux x64=ade-0.1.1f
build_gapi_standalone:Win64=ade-0.1.1f
build_gapi_standalone:Mac=ade-0.1.1f
build_gapi_standalone:Linux x64 Debug=ade-0.1.1f

Xbuild_image:Custom=centos:7
Xbuildworker:Custom=linux-1
build_gapi_standalone:Custom=ade-0.1.1f

build_image:Custom=ubuntu-openvino-2020.3.0:16.04
build_image:Custom Win=openvino-2020.3.0
build_image:Custom Mac=openvino-2020.3.0

test_modules:Custom=gapi
test_modules:Custom Win=gapi
test_modules:Custom Mac=gapi

buildworker:Custom=linux-1
# disabled due high memory usage: test_opencl:Custom=ON
test_opencl:Custom=OFF
test_bigdata:Custom=1
test_filter:Custom=*

@TolyaTalamanov TolyaTalamanov changed the title [G-API] Wrap GArray part 1 [G-API] Wrap GArray Nov 10, 2020
@asmorkalov
Copy link
Copy Markdown
Contributor

@TolyaTalamanov The PR still does not pass pre-commit checks. Please take a look on CI.

@TolyaTalamanov TolyaTalamanov force-pushed the at/support-garray branch 5 times, most recently from 3a6c459 to 48e3d24 Compare November 23, 2020 10:30
@TolyaTalamanov TolyaTalamanov force-pushed the at/support-garray branch 2 times, most recently from ae2fdaa to e3fdd97 Compare November 23, 2020 12:59
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dkurt Could you have a look, please ?

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dkurt

@asmorkalov asmorkalov requested a review from dkurt November 25, 2020 09:22
@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@smirnov-alexey

cv.gapi.core.cpu.kernels(),
cv.gapi.core.fluid.kernels()
# cv.gapi.core.plaidml.kernels()
]
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.

indentation is strange here (use 4 spaces)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

def test_good_features_to_track(self):
# TODO: Extend to use any type and size here
sz = (720, 1280)
in1 = np.random.randint(0, 100, sz).astype(np.uint8)
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.

np.random

  • input is not determined (no way to reproduce failed test) - we don't want sporadic failures.
  • it is better to use some image instead (or draw it)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

# OpenCV - (num_points, 1, 2)
# G-API - (num_points, 2)
# Comparison
self.assertEqual(0.0, cv.norm(expected.flatten(), actual.flatten(), cv.NORM_INF))
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.

for pkg in pkgs

Consider providing clear messages about failures: add information about used "pkg".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

ccomp.start()

# Assert
while cap.isOpened():
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.

Please limit the number of processed frames.
We really don't need to process all 100 frames here.

/cc @dmatveev This note is actual for other tests too, including C++

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@alalek @dkurt @smirnov-alexey Could you have a look ?

{
switch (info.kind)
{
case cv::detail::OpaqueKind::CV_POINT2F:
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm going to use HostCtor to avoid switch here in next PR

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.

Good point

Copy link
Copy Markdown
Contributor Author

@TolyaTalamanov TolyaTalamanov Nov 26, 2020

Choose a reason for hiding this comment

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

It has been already implemented in PR: #18900

@TolyaTalamanov
Copy link
Copy Markdown
Contributor Author

@dmatveev Could you have a look ?

@alalek alalek merged commit 7521f20 into opencv:master Nov 27, 2020
@alalek alalek mentioned this pull request Nov 27, 2020
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
[G-API] Wrap GArray

* Wrap GArray for output

* Collect in/out info in graph

* Add imgproc tests

* Add cv::Point2f

* Update test_gapi_imgproc.py

* Fix comments to review
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.

5 participants