AdaCV - OpenCV but Ada

Hi everyone,

I’ve been a long time lurker on the Ada subreddit and was directed here by Lucretia to share my plan/idea. After a few years in Python and short, unhappy tread through the chaos of C++, I’m learning Ada, while I’m still new to the language, I have a project idea. I want to make sure I don’t reinvent the wheel and that I engage with anyone else who is interested.

Are you familiar with OpenCV? If not, it’s a very good computer vision library in C++ and Python.

Well I have a several years experience with it in both C++ and Python (and the science/math directly). My interpretation is that, while the basics can be easy to use, the more complicated functions (Stereo Calibration, triangulation, really anything with photogrammetry) are nuanced and somewhat unforgiving. A lot of it is driven by poor examples and the poor documentation on what you’re actually getting. For example, it doesn’t talk about what units is a particular return value is in? Distance units or a some normalized unit? What’s expected as the input? A vector of vectors of a custom cv::Point2f two dimension float type. Stack overflow is filled with questions where people don’t get much help and their answers are met more with theory photogrammetry and I never see actual usage help or answers. It’s just like the documentation: theory heavy, usage thin, typing vague. A more… user friendly library with thorough usage documentation would be very popular if it was genuinely easy to use.

I’m sure you see where this is going but please let me finish:

Ada is the language of reliability and safety. Look at the popular and booming Tech industries, two relevant highlights are Autonomous Vehicles and Augmented Reality. Both use imaging processing and photogrammetric techniques. If an ADA based package or library that was easily usable and accurate, while having the reliability and safety of ADA, it could bring a lot of new people, companies, and industries to the language.

So anyways, the idea is AdaCV. A potentially slimmer but more easily usable and user friendly OpenCV in Ada.

Anyone working on that? Anyone finished it? Thoughts? Objections?

1 Like

How are you thinking of proceeding? a thin client to a thick client, or a product rebuilt from the ground up?

Personally, I want to use as little of OpenCV as possible. The algorithms that it uses are well published techniques and are in many papers and textbooks. I don’t know of anything really proprietary or special. They just already wrote the function so why not just rewrite it in Ada and make it better, you know?

As a regular user of these techniques, there has been many a time when I’ve needed to write my own method using the same algorithm because OpenCV’s prepackaged functions are too ambiguous or require inputs that aren’t actually necessary for the function to proceed. A basic example is the cv::stereoCalibrate function. It requires a std::vector<std::vector< cv::Point2f>>. That’s intended so you can have 2D points in an image for multiple images. However, that means you can’t do any calibration validations on a single image pair without duplicating the same image and having std::vector filled with copies of the same std::vector< cv::Point2f>

edit: Formatting and brackets. Fixed ambiguity in statement.

To start with, the appearance of an algorithm in a published paper does not mean it is straightforward to implement it at all, let alone implement it efficiently. I have a bit of :sob: experience with that… :grin:

Oh you’re right about that. In this case, I’m well versed in these topics and algorithms, having done a lot of it manually before.

OpenCV is painful to work with in some regards. Specifically the 3D calibration and pose estimation portions. I haven’t used the entire library but the portions I have used vary a lot. Some parts are amazing. Others are really painful.

I think there’s a better ways of implementing the image processing related stuff.

Their library grows and updates very quickly. The portion on machine learning, neural nets, and AI are where they focus. I don’t see updates or changes being made to the image processing portions of the library. In my opinion, they need QOL updates along with new functions that are simple but missing.

Some types like cv::Mat are so overloaded the types are really weakly enforced. cv::Mat will accept almost any type. You can enforce some types using things like cv::Mat_< float> but that breaks some things like matrix multiplication. There’s a lot of type casting required.

One of worst things about the library is the typing but I feel that way about c++ in general

Edit: Let me clarify. I don’t want to rewrite the whole thing. Just specific portions, like the image processing basics, detecting some stuff in images, and some photogrammetry portions

If you’re going to implement image processing algorithms in Ada, take a look at the orka library. It already has bindings and types defined for many hardware accelerated vector operations. I think it would be best to build atop that work.

It sounds to me as though you should create your library as a OpenCV-like library that you have the freedom to simply bind to (be it thick, thin, or a combination of) and even rewrite portions of it if you feel it provides enough benefit (eg easier to use and less error prone, better performance, etc). Who knows, maybe it will evolve to a point to where it really makes sense to break free from OpenCV and gut the underlying implementation for a fully Ada one.