G-API: Wrap render functionality to python#20284
Conversation
c90fe6b to
1685290
Compare
|
|
||
|
|
||
| # FIXME: On the c++ side every class is placed in cv2 module. | ||
| cv.gapi.wip.draw.Rect = cv.gapi_wip_draw_Rect |
There was a problem hiding this comment.
@alalek How ugly is it ? Is there another option ?
There was a problem hiding this comment.
Not sure why you need that. There are many other classes from nested namespaces which are located properly.
AFAIK, there is some bug with Python ctors (this is why "create" method is used).
It is better to fix that problem instead of replacing classes with functions.
There was a problem hiding this comment.
Not sure why you need that. There are many other classes from nested namespaces which are located properly.
Could you provide any examples ? Looks like allclassesis placed incv2module.
There was a problem hiding this comment.
looks like it is not supported properly for now.
BTW, cv.gapi_wip_draw_Rect is a function, not a type.
There was a problem hiding this comment.
From generated file:
CVPY_TYPE(gapi_wip_draw_Rect, gapi_wip_draw_Rect, cv::gapi::wip::draw::Rect, Rect, NoBase, pyopencv_cv_gapi_wip_draw_gapi_wip_draw_Rect_Rect)
| template <> | ||
| PyObject* pyopencv_from(const cv::gapi::wip::draw::Prim& prim) | ||
| { | ||
| switch (prim.index()) { |
There was a problem hiding this comment.
I believe it's possible to implement pyopencv_from for generic variant by using visitor, but it's not merged yet.
| bool pyopencv_to(PyObject* obj, cv::gapi::wip::draw::Prim& value, const ArgInfo& info) | ||
| { | ||
| #define TRY_EXTRACT(Prim) \ | ||
| if (PyObject_TypeCheck(obj, reinterpret_cast<PyTypeObject*>(pyopencv_gapi_wip_draw_##Prim##_TypePtr))) \ |
There was a problem hiding this comment.
@alalek Is there any way to implemente it via more high level functions ? pyopencv_to/pyopencv_to_safe aren't suitable there, are they ? Because they set an error in case mismatch.
There was a problem hiding this comment.
Not sure that do you mean here.
"dynamic types" are handled though switches/virtual functions.
If you don't want to follow pyopencv_to/pyopencv_from conventions, then please change names of these functions.
There was a problem hiding this comment.
What do u mean by "dynamic types". Is the cv::variant<Types...> is a dynamic type ?
It seems to me since cv::variant<> has the limited number of possible types it can be wrapped like this:
cv::gapi::wip::draw::Rect rect;
if (pyopencv_to(obj, rect, info))
{
value = rect;
return true;
}
...
if(pyopencv_to(obj, text, info)
{
value = text;
return false;
}
// set error
return false;
But it doesn't work because in case fail first pyopencv_to setup an error.
Is it possible to implement pyopencv_to for variant<> following all conventions somehow else it's done above ?
There was a problem hiding this comment.
Variant implementation always has a tag/kind field which says which underlying object is stored.
There is NO sequence of calls.
There is switch(tag) with ONE call.
So you need to determine what is the "tag" value in that case. Perhaps switching over PyObject_TypeCheck is enough.
There was a problem hiding this comment.
But in this case variant<> is empty, isn't it ?
It seems I can't just go through switch to determinate the type, cuz there is no stored object so far
There was a problem hiding this comment.
I've implemented pyopencv_from like you proposed above
|
|
||
|
|
||
| # FIXME: On the c++ side every class is placed in cv2 module. | ||
| cv.gapi.wip.draw.Rect = cv.gapi_wip_draw_Rect |
There was a problem hiding this comment.
Not sure why you need that. There are many other classes from nested namespaces which are located properly.
AFAIK, there is some bug with Python ctors (this is why "create" method is used).
It is better to fix that problem instead of replacing classes with functions.
| bool pyopencv_to(PyObject* obj, cv::gapi::wip::draw::Prim& value, const ArgInfo& info) | ||
| { | ||
| #define TRY_EXTRACT(Prim) \ | ||
| if (PyObject_TypeCheck(obj, reinterpret_cast<PyTypeObject*>(pyopencv_gapi_wip_draw_##Prim##_TypePtr))) \ |
There was a problem hiding this comment.
Not sure that do you mean here.
"dynamic types" are handled though switches/virtual functions.
If you don't want to follow pyopencv_to/pyopencv_from conventions, then please change names of these functions.
| TRY_EXTRACT(Image) | ||
| TRY_EXTRACT(Poly) | ||
|
|
||
| return false; |
There was a problem hiding this comment.
Python error should be raised with proper message.
|
@alalek @mpashchenkov Could you have a look, please ? |
5fb7744 to
6e17f69
Compare
|
@alalek I answered the comments, could check it one more time, please ? |
|
@alalek CI is green, could you check it one more time, please ? |
| int lt_ = 8, | ||
| bool bottom_left_origin_ = false) : | ||
| GAPI_WRAP Text(const std::string& text_, | ||
| const cv::Point& org_, |
There was a problem hiding this comment.
It makes sense to put modifiers on a separate line:
GAPI_WRAP
Text(const std::string& text_,
(to avoid touching indentation on changes)
| GAPI_WRAP Text() = default; | ||
|
|
||
| /*@{*/ | ||
| std::string text; //!< The text string to be drawn | ||
| cv::Point org; //!< The bottom-left corner of the text string in the image | ||
| int ff; //!< The font type, see #HersheyFonts | ||
| double fs; //!< The font scale factor that is multiplied by the font-specific base size | ||
| cv::Scalar color; //!< The text color | ||
| int thick; //!< The thickness of the lines used to draw a text | ||
| int lt; //!< The line type. See #LineTypes | ||
| bool bottom_left_origin; //!< When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner | ||
| GAPI_PROP std::string text; //!< The text string to be drawn | ||
| GAPI_PROP cv::Point org; //!< The bottom-left corner of the text string in the image | ||
| GAPI_PROP int ff; //!< The font type, see #HersheyFonts |
There was a problem hiding this comment.
If you wrap default ctor, then it makes sense to use RW properties (like CV_PROP_RW) to allow updating of them.
|
|
||
|
|
||
| # FIXME: On the c++ side every class is placed in cv2 module. | ||
| cv.gapi.wip.draw.Rect = cv.gapi_wip_draw_Rect |
There was a problem hiding this comment.
looks like it is not supported properly for now.
BTW, cv.gapi_wip_draw_Rect is a function, not a type.
|
please rebase PR on new master code |
|
@alalek Rebased, CI is green |
| int thick_ = 1, | ||
| int lt_ = 8, | ||
| int shift_ = 0) : | ||
| const cv::Scalar& color_, |
|
@alalek Could you merge it, please ? |
G-API: Wrap render functionality to python * Wrap render Rect prim * Add all primitives and tests * Cover mosaic and image * Handle error in pyopencv_to(Prim) * Move Mosaic and Rect ctors wrappers to shadow file * Use GAPI_PROP_RW * Fix indent
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.
Build configuration