I want to convert keypoints in C++ to python [closed]

asked 2018-11-15 07:48:47 -0500

updated 2018-11-15 07:53:07 -0500

berak gravatar image

Hi,

Recently, I implemented a new method about detecting keypoints in C++. (the method is not included in OpenCV library yet) Then I want to evaluate the keypoint results in python. So I need to write a python wrapper to convert the keypoints in C++ to Keypoints in python.

Specifically: I performed

vector<KeyPoint> kps1 = NewAlgorithm_KeypointDetector(XXX); //in C++

and then I want to transfer the keypoint result to python.

I searched many materials, including using CV_WRAP, but I don't know how to use it. Or I checked cv2.cpp file, there is pyopencv_from() and pyopencv_to() function, but I am not able to directly call them to do the python wrapper. Im using Boost.python currently, so how should I deal with it?

Thanks in advance.

Best regards, Weibo Qiu.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-11 13:03:19.279799

Comments

what is XXX ?

are you able to build the cv2 bindings locally ?

it's probably far easier, if you put your function inside the opencv modules (or maybe add a new one) and build it along with the other opencv code

berak gravatar imageberak ( 2018-11-15 07:55:07 -0500 )edit

XXX are just some parameters. The function returns result as vector <keypoint> cv2 bindings building is successful, I have python_binding_generator folder.

But what do you mean "put your function inside the opencv modules" ? which opencv module?

Weibo Qiu gravatar imageWeibo Qiu ( 2018-11-15 08:36:39 -0500 )edit

nonetheless, please specify your XXX parameters exactly.

then, we can try to help you to add your function e.g. to the features2d module, so you can use it in the same way as the builtin function.

berak gravatar imageberak ( 2018-11-15 08:56:27 -0500 )edit

I also found a function "static PyObject pyopencv_cv_KeyPoint_convert(PyObject* , PyObject* args, PyObject* kw)*" in pyopencv_generated_funcs.h file . Can I use it directly to convert?

Weibo Qiu gravatar imageWeibo Qiu ( 2018-11-15 08:56:40 -0500 )edit

Hi berak,

Thanks for your reply. But this algorithm has not been published yet and has some credential issue. So there is no easier way to convert keypoints from c++ to python?

Weibo Qiu gravatar imageWeibo Qiu ( 2018-11-15 08:58:54 -0500 )edit

imho, you're trying this from the wrong end. vector<KeyPoint> as well as KeyPoint::convert() are already perfectly covered from the existing cv2 functionality, there is nothing you have to do here.

it's only a problem, if you try to use Boost for wrapping, because then, you have to start from scratch (so don't do that !)

berak gravatar imageberak ( 2018-11-15 09:01:01 -0500 )edit

But I also read how to extend new modules to Python (link text)

Is it possible to use CV_WRAP to extend my NewAlgorithm_KeypointDetector() function ? So that the results keypoints can be wrappered to python.

Weibo Qiu gravatar imageWeibo Qiu ( 2018-11-15 09:05:51 -0500 )edit

CV_EXPORTS, not CV_WRAP. (and that's exactly what i'm trying to push you to do all the time... ;)

but again, tell us, what XXX is exactly, and we can give you the correct syntax ...

berak gravatar imageberak ( 2018-11-15 09:08:02 -0500 )edit

Hi berak,

I'll check it tomorrow and see if it is feasible to reveal the NewAlgorithm_KeypointDetector() function. Thanks for your help!

Weibo Qiu gravatar imageWeibo Qiu ( 2018-11-15 11:19:26 -0500 )edit

lol, you don't have to reveal your function only the signature of it.

berak gravatar imageberak ( 2018-11-15 11:30:29 -0500 )edit