Ask Your Question
0

How does OpenCV support for Python?

asked 2018-08-03 02:20:07 -0600

Chandra Sekar gravatar image

I know OpenCV supports python language for the users to access their modules.

But my question is how do they do, like

For Ex: They have open() API in the VideoCapture class which can be accessed either in c++ or python, but they have written the source code only in the c++ language. How do they do this conversion and where they were doing this conversion?

My question is how do they create in c++ and can give the support in python?

Thanks in Advance for the answer..

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2018-08-03 02:36:00 -0600

berak gravatar image

there are some python scripts, that parses the c++ api headers and generates (C) python binding code from those.

have a look here for more explanation

edit flag offensive delete link more

Comments

Thanks for this. If i wanted to add a new API in c++ in Videoio Module, say for example get() method with different number of parameters. What are the changes do i have to make in the modules/python/src2 path?

Chandra Sekar gravatar imageChandra Sekar ( 2018-08-03 03:11:55 -0600 )edit
1

you don't change anything in the python scripts.

please have a look at the tutorial again, all you have to do is add CV_EXPORTS_W or CV_WRAP tags to the c++ api headers.

berak gravatar imageberak ( 2018-08-03 03:14:19 -0600 )edit

Thanks, but i have added the CV_WRAP before my new API, but still while building OpenCV including python, but it shows me a warning like this

modules/python/src2/cv2.cpp:206:6: warning: ‘bool pyopencv_to(PyObject*, T&, const char*) [with T = long int]’ used but never defined
 bool pyopencv_to(PyObject* obj, T& p, const char* name = "<unknown>");

and also while importing cv2, i come up with the problem like undefined reference to ImportError: /usr/local/lib/python3.5/site-packages/cv2.cpython-35m-x86_64-linux-gnu.so: undefined symbol: _Z11pyopencv_toIlEbP7_objectRT_PKc

How to solve this one? Do you have any idea on this?

Chandra Sekar gravatar imageChandra Sekar ( 2018-08-03 03:31:25 -0600 )edit
1

there are pyopencv_from() and pyopencv_to() pairs here(e.g. for double)

but no such thing for long int. can you use a normal int instead ?

also, seing the c++ signature, you want to wrap, will be useful.

berak gravatar imageberak ( 2018-08-03 03:47:23 -0600 )edit
2

Super berak, Thanks for the help. The problem is solved. long int was the problem. Changing it to normal int does the trick.

Chandra Sekar gravatar imageChandra Sekar ( 2018-08-03 05:25:05 -0600 )edit

Question Tools

Stats

Asked: 2018-08-03 02:20:07 -0600

Seen: 282 times

Last updated: Aug 03 '18