Can you avoid C++ in Computer Vision?

computer vision Jan 27, 2020

C++ for Computer Vision in autonomous robots

Recently, I was asked by someone who had been looking for a self-driving car job why is C++ even mentioned and why is it required for Computer Vision Engineer jobs. The question is legit.

We know self-driving cars are coded in C++ rather than Python, but why even Computer Vision, which seems to be a huge Python thing with a lot of Machine Learning , also in C++?


đŸ“© Before we dive in C++, I invite you to join the mailing list ! This is the most efficient way to understand autonomous tech in depth and join the industry faster than anyone else.


Maybe you know the answer already, C++ is better for embedded programs because of its speed. So we are going to look at whether you can avoid this language or not.

Also, we’ll look at how to use C++ and Python for Computer Vision.

OpenCV is a C++ library

Maybe you didn’t know. Now you do. OpenCV is a C++ library, not a Python one.

It means that every time you’re using OpenCV in Python, you’re actually using a wrapping.

OpenCV is the main library people use for Computer Vision. It has become a standard that is a must-learn.

With OpenCV, you can do most of the needed things for Computer Vision tasks.

  • You can read images in a matrix of pixels.
  • You can resize these images, transform them, change their colors, 

  • You can also perform tasks like contour finding, edge detection, gaussian blurring, or others

  • Finally, you can use neural network algorithms such as YOLO in a single line of code.

OpenCV is a must-use. The library is free, contains tutorials, and is rather easy to use.

Here are some examples.

Plate recognition
Hand-Gesture recognition

Parking lot segmentation
Image space

Since OpenCV is originally coded in C++, all the OpenCV functions are available in C++.

Python is a very easy solution for rapid prototyping.

When working with embedded programs, people generally go for C++.

If there are no algorithm availability restrictions, why use the lease performant one of the two?

We still might think of Machine Learning , there is a ton of Machine Learning we’d like to use. And Machine Learning is better in Python, right?

Tensorflow is a C++ Library

If you thought Tensorflow was a Python library, you could not be more wrong.

  • Tensorflow is actually a C++ and CUDA (Nvidia’s GPU language) library.
  • Tensorflow is still the most popular framework for Deep Learning tasks.
  • This library allows for performant matrix computations as well as GPU optimizations.

How is most of Tensorflow’s library coded in C++ without NumPy?

If you already started to learn Machine Learning and Neural Networks, you might have done an exercise where you have to create a neural network library from scratch with NumPy.

NumPy is the tool to use when we want to multiply matrices and perform forward and backward propagation.

The equivalent in C++ is called Eigen.

It’s a powerful library that helps with computations, and that can replace NumPy in the process of creating a Tensorflow.

When you are calling a ‘sess.run()‘ (function to run the neural network) in Python with Tensorflow, the operations are executed in C++. Most of them are not even translated into Python. What you get in Python is the end result.

But Deep Learning also has algorithms like YOLO (You Only Look Once) that can perform object detection in no time with Python.

Let me tell you something once again.

YOLO is a C++ framework

Don’t shoot yourself, but it’s true.

YOLO is written in C and C++. It was created this way to be performant.

In fact, when you go to darknet’s website, you’ll see that it looks more like C than Python.

If you don’t know YOLO, here is a picture that sums up what it outputs.

If everything is coded in C++, why is Python the top language?

Can you avoid C++ in self-driving cars?

Python is the most popular language for Machine Learning. It is the most comfortable language to work with.

Tensorflow and others choose Python as their first supported language after coding their C++ library.

Most Machine Learning practitioners learn with the Python version without even realizing that they are using C++ based libraries.

Now, the big question is can we avoid C++ for self-driving cars?

According to my experience, the chances are not very high.

You might see C++/Python on the job requirement page, but chances are the company will work in C++.

Sometimes, the company is not working on critical things and might not require as much performance.

I once had an interview for Parrot, a French drone company.

They wanted me to develop Computer Vision for their drones to start proposing Follow-me features.

The job was in Python! Great! I could avoid C++ and come “unprepared” to the interview.

But the technical interview was in C++! Why? I still don’t have the answer and I’ll probably never know since I didn’t prepare C++ and didn’t get the job.

Yes, at the time, I was working in a self-driving car company and didn’t work with C++ every day.

Is this possible? Yes, I did this.

In the company that I was in, most engineers worked with C++. However, I was one of the only resources in Computer Vision, and no one told me that I had to use C++; so I went with Python and boosters.

It worked very well and was very easy to integrate with ROS (Robotic OS).

Generally, C++ will be a requirement if you want to work on self-driving cars, no matter what task you’ll have.

If you’re lucky or find a company whose performance is not that important, you may work with Python.

My advice? If you are to be a Computer Vision Engineer, be a Computer Vision Engineer no matter what language you have to use.

Some day, you might have to work with Swift to code Computer Vision for an Apple app.

The job will be the same, the language will evolve.

Want to learn more about the topic? Discover my C++ interview with Udacity to promote their C++ nanodegree program.

đŸ“© And if you want to go further, I invite you to join the daily emails where you’ll learn more about Computer Vision and Autonomous Vehicle.

Tags

Mindmap

Interested in Autonomous Systems? Download the Self-Driving Car Engineer Mindmap

The Self-Driving Car Engineer Mindmap is a video + PDF mindmap showing you the main areas of self-driving cars, and giving you a path to build a career as a self-driving car engineer.