Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

TolyaTalamanov
Copy link
Contributor

@TolyaTalamanov TolyaTalamanov commented Sep 10, 2022

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

Motivation

Python bindings are available since a long time, but only a few operations (operation::on(...) wrappers) were exposed.
There was a great plan to implement feature in python parser that could automatically detect G-API operation (via GAPI_TYPED_KERNEL macro or so) and expose it into python, but this functionality is more about giving an opportunity to user to implement python kernels for already existing in G-API operations.

This PR is going to expose just operation::on wrappers to python in order to give user everything that is available from c++, because now, for developers who don't build from source and change the code only available a small amount of functionality.
Since a lot of developers use opencv from pip let's expose it once and forever.

Great example of G-API usage: https://github.com/xiong-jie-y/g_api_examples

TODO list:

  • Expose core
  • Expose imgproc
  • Expose video
  • Expose stereo
  • Other stuff (e.g constant initialization for G-Type's & some compiler args)

*/
GAPI_EXPORTS GMat blur(const GMat& src, const Size& ksize, const Point& anchor = Point(-1,-1),
int borderType = BORDER_DEFAULT, const Scalar& borderValue = Scalar(0));
GAPI_EXPORTS_W GMat blur(const GMat& src, const Size& ksize, const Point& anchor = Point(-1,-1),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exception from core operations, just want it to be exposed asap :)

@note Function textual ID is "org.opencv.core.kmeans3D"
*/
GAPI_EXPORTS std::tuple<GOpaque<double>,GArray<int>,GArray<Point3f>>
GAPI_EXPORTS_W std::tuple<GOpaque<double>,GArray<int>,GArray<Point3f>>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense to add test for this one because it touches a lot of existing functionality.

Copy link
Contributor

Choose a reason for hiding this comment

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

kmeans or what?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, add test for kmeans because it returns Point3f which wasn't supported before

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

@TolyaTalamanov
Copy link
Contributor Author

@dmatveev Could you have a look, please?

@asmorkalov asmorkalov added this to the 4.7.0 milestone Sep 13, 2022
Copy link
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

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

We need to do something with all that our type enumerations in all these different headers... Worth a TODO

@note Function textual ID is "org.opencv.core.kmeans3D"
*/
GAPI_EXPORTS std::tuple<GOpaque<double>,GArray<int>,GArray<Point3f>>
GAPI_EXPORTS_W std::tuple<GOpaque<double>,GArray<int>,GArray<Point3f>>
Copy link
Contributor

Choose a reason for hiding this comment

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

kmeans or what?

CV_STRING, // std::string user G-API data
CV_POINT, // cv::Point user G-API data
CV_POINT2F, // cv::Point2f user G-API data
CV_POINT3F, // cv::Point3f user G-API data
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed the below type? See GOpaqueTraits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't exposed it for purpose, because there weren't such cases

Copy link
Contributor

@dmatveev dmatveev Sep 16, 2022

Choose a reason for hiding this comment

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

But it is an inconsistency now, isnt it?

And now its only you who knows the reason for it (ok, and me)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@asmorkalov
Copy link
Contributor

@TolyaTalamanov Friendly reminder.

@TolyaTalamanov TolyaTalamanov changed the title WIP: G-API Expose all core operations to python G-API Expose all core operations to python Oct 29, 2022
@TolyaTalamanov TolyaTalamanov force-pushed the at/expose-all-core-to-python branch from e567339 to 2b601de Compare October 29, 2022 13:24
@TolyaTalamanov TolyaTalamanov force-pushed the at/expose-all-core-to-python branch from 2b601de to f8eca04 Compare October 29, 2022 13:27
CV_STRING, // std::string user G-API data
CV_POINT, // cv::Point user G-API data
CV_POINT2F, // cv::Point2f user G-API data
CV_POINT3F, // cv::Point3f user G-API data
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

self.assertEqual(K, len(centers))


def test_kmeans_3d(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually tests only functionality without accuracy checking with ocv

@TolyaTalamanov
Copy link
Contributor Author

@dmatveev Could you have a look, please?

Copy link
Contributor

@dmatveev dmatveev left a comment

Choose a reason for hiding this comment

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

👍

@TolyaTalamanov
Copy link
Contributor Author

@asmorkalov Can it be merged?

@TolyaTalamanov
Copy link
Contributor Author

@alalek @asmorkalov Could you merge it, please?

@alalek alalek merged commit 2aad039 into opencv:4.x Nov 8, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
…e-to-python

G-API Expose all core operations to python

* Expose all G-API core operations to python

* Fix typo in python gapi types test
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