Ask Your Question
0

How to look at imported Python cv2 code?

asked 2014-06-12 10:01:21 -0600

updated 2014-06-12 10:35:22 -0600

Hello there!

A friend and I are trying to understand the "black boxes" of cv2's methods but can't seem to find the python code that defines these functions/methods. Is there a straightforward way to look at this code or is some magic happening with the c++ source files and parsing or something else entirely? Any information about this would be greatly appreciated. Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-06-12 12:07:06 -0600

Abid Rahman K gravatar image

Python cv2 module is a wrapper around original C++ code. ie those functions are not implemented in Python, but implemented in C++. Then there is "bridge" code which helps you to call these functions from Python. So to find a function, you need to search in origin C++ codes.

For example, you need to know how cv2.equalizeHist() is working. You go directly where it is implemented in C++ (ie opencv/modules/imgproc/src/histogram.cpp).

So how they are called from Python? go to opencv2/modules/python/src2/. There are some header parser (hdr_parser.py) which parse header files and some bindings generator (gen2.py) which generates the "bridge" code. Now with the help of cv2.cpp (contains the data conversion from Python <--> C++), cv2 modules is created.

Hope it helps...

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-06-12 10:01:21 -0600

Seen: 229 times

Last updated: Jun 12 '14