As mentioned in earlier answers, Python is slower than C ++ or C. Python is built for its simplicity, portability and, moreover, for creativity, when users only need to worry about their algorithm and not about programming problems.
But here, in OpenCV, there is something else. Python-OpenCV is just a wrapper around C / C ++ source code. It is commonly used to combine the best features of both languages, C / C ++ performance and Python simplicity .
Therefore, when you call a function in OpenCV from Python, what is actually being executed is the source of C / C ++. Thus, there will not be much difference in performance (I remember, I read somewhere that the penalty for performance is 1%, I donβt remember where. A rough estimate with some basic functions in OpenCV shows the worst case penalty <4% , t. e. penalty = [maximum time taken in Python - minimum time taken in C++]/minimum time taken in C++ ).
The problem occurs when your code has many native python codes. For example, if you create your own functions that are not available in OpenCV, things get worse. Such codes run in Python, which significantly reduces performance.
But the new OpenCV-Python interface has full Numpy support. Numpy is a package for scientific computing in Python. It is also a wrapper around native C code. It is a highly optimized library that supports a wide range of matrix operations, very suitable for image processing. Therefore, if you can properly combine OpenCV and Numpy functions, you will get very fast code.
Remember that always try to avoid loops and iterations in Python. Instead, use the array controls available in Numpy (and OpenCV). Simply adding two numpy arrays using C = A+B is much faster than using double loops.
For example, you can check out these articles:
Abid Rahman K Nov 17 '12 at 18:12 2012-11-17 18:12
source share