Home Blogging Using C++ or Python for OpenCV Programs

Using C++ or Python for OpenCV Programs

by Jack Simpson

When I first started learning OpenCV, I was working exclusively with Python. While I am still a huge fan of the language, today all of my OpenCV programs are written in C++. Why?

  1. Some of the deeper functionality of OpenCV has not been completely ported to Python (although hopefully the release of OpenCV 3.0 will fix most of these issues).
  2. Most in-depth textbooks on image processing and computer vision that cover OpenCV use C++ as their primary language. It was therefore easier to learn from these resources by adopting the language.
  3. A lot of the computer vision techniques I use (SIFT, machine learning, etc), are better documented in C++.
  4. Passing images back and forth between NumPy arrays has overhead that C++ doesn’t have to worry about.
  5. As has been suggested to me by Carl Bell, Python struggles to perform well with overloaded functions.

I am absolutely certain that without the Python bindings for OpenCV (forcing me to learn and use C++) , I would have found the barrier for entry to the field of image processing far steeper. Python and OpenCV (and the online tutorials which were available) enabled me to learn very rapidly. If you’re just getting started in the field of image processing or computer vision, I cannot recommend them enough. Python lists, and the way images are read into NumPy arrays, makes it incredibly straight-forward to build useful tools. Python is also incredibly useful as a prototyping language, when you want to investigate how feasible an idea is, without investing too much time.

However, as you become more familiar with the field, I would advise you to challenge yourself to start using C++ and OpenCV. While things will definitely be a bit more difficult (at least initially), it is an investment worth making. Aside from a performance boost, you’ll be able to draw on code and tutorials written for Python and C++, which I have  found hugely beneficial whilst trying to understand some of the more niche functionality present in the imaging library. I have also found that my switch to C++ gave me a greater appreciation and understanding of  what OpenCV is doing under the hood. Finally, for those worried about the complexity that a language like C++ might add, don’t worry! While it is a bit more difficult than Python, C++ OpenCV has automatic memory management built in, and the matrix data structure for images is incredibly straightforward.

Sign up to my newsletter

Sign up to receive the latest articles straight to your inbox

You may also like

Leave a Comment