C++ vs Python for Vision

Those of you who run OpenCV written in C++, do you think the speed improvements are worth using Python in OpenCV. I know python’s bindings are in OpenCV…

But code like sending over sockets, processing arrays and such should be slower in python.

Only reason I am hesitant about C++ is settuing up a corss compiler/debugging it is a pain

What target platform? The WPILib team maintains cross-compilers for the Raspberry Pi and aarch64 (e.g. Jetson Nano) in addition to the RoboRIO.

Sorry. Raspberry Pi as the target platform… I haven’t seen one though…

We point to it from the Raspberry Pi FRCVision image C++ example’s README, but here’s a direct link to the Raspbian cross-compiler we build. I highly recommend you take a look at FRCVision if you haven’t yet.

AH. Thank you! Do you think it would be worth dealing with C++ over Python? I can’t tell if it would really matter… speed wise

Probably doesn’t make much difference, particularly if you use numpy instead of doing all the loops in pure Python, as then basically all the heavy lifting is in C++ anyway. The Raspberry Pi 3 and 4 especially are pretty fast.

Only thing I am thinking about is if we use network sockets to communicate… how fast those network interfaces are in python versus c++

How much data are you sending? In Python the under-the-hood stuff is still C++, except for the current version of pynetworktables, which currently is written in Python (but they’re looking at switching it to use the C++ library as well).

Ideally under 50 bytes per message. I’m probably over optimizing… I just feel guilty not using C++

If you’re familiar with C++ and want to use it, go for it :slight_smile:

I’m personally a python man. I find it easier to work with as far as open CV is concerned.

The image processing code is essentially the same speed in Python and C/C++ (as long as you are a little bit careful). That is because all the major processing should be done by the OpenCV code, which is all in C++.

The networking code in Python is also mostly in C, I believe. Irrespective, sending 50 bytes everyone 10s of milliseconds will not tax Python code and you would be hard pressed to see the difference.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.