OpenCV 4.4 lands with out-of-the-box support for Swift and Objective-C

Giles Payne
3 min readJul 20, 2020

--

In a major boost for iOS developers — the latest version of OpenCV adds out-of-the-box for Swift and Objective-C bringing it onto a par with OpenCV’s existing support for Android development.

OpenCV Android iOS logos
OpenCV ready for prime-time on mobile

OpenCV is widely used by data scientists and computer vision experts around the globe for a wide range of use cases including object detection, object classification, face detection, image quality evaluation, image enhancement, text extraction and much more. While the core library is written in C++ a sizable portion of users especially in the data science community use Python wrappers to access its functionality. A Java wrapper has been around for about a decade and allows for easy access to the APIs from Android apps, however until now iOS developers have had no option but to go all the way down to the C++ layer if they wanted to get access to OpenCV functionality. The problem is that the programming language of choice for iOS developers these days is Swift. While mixing Swift and C++ is possible, a lot of plumbing is required to get the two to play nicely together and this takes a lot of programming effort. With OpenCV 4.4 all of that goes away with simple direct access to OpenCV APIs achievable with just a few lines of code.

Mobile development with OpenCV “Before and After”

The new Swift/Objective-C support is a boost for mobile developers in general. Since nearly all apps need both and Android and iOS versions — the decision to use a particular library often relies on whether it supports Android and iOS. Even if the a library has both iOS and Android support, if the interfaces for each are substantially different (as was the case with previous version of OpenCV) it can prove a major obstacle to adoption. The Swift/Objective-C interfaces added in OpenCV 4.4 are mapped as closely as possible to the existing Java/Android interfaces, meaning the app developers job is greatly simplified. An algorithm that has been implemented on Android can quickly and easily be ported to iOS and vice-versa.

Can we see some documentation please?

The OpenCV Swift/Objective-C wrapper comes with some very classy documentation courtesy of the Jazzy documentation generation tool from Realm. The documentation comes with built-in search that allows you to easy locate OpenCV classes, functions and constants in order to get the correct Swift/Objective-C syntax. Another great feature is the inline rendering of mathematical expresses in LaTeX format which Jazzy renders beautifully with the help of KaTeX.

Documentation highlights: top-left — the search box, bottom-right — inline LaTeX, right —dual declarations

We built it — now what are you going to do with it?

While data-scientist running OpenCV on the desktop often run AI-related CPU heavy workloads there are plenty of uses that OpenCV can be put to on a mobile device. A very common use case is evaluating quality of an image before sending it to a server for further processing; other possibilities include face-morphing, motion detection, image stitching ... the opportunities are limitless … go do your stuff mobile developers … the world will be your …

Praise for OpenCV’s Objective-C/Swift support

“as a long-time OpenCV user, thank-you” - NikoYuwono

“this looks like a legendary feature” - ianboru

“I think Objective-C / Swift support is a big project to further enrich the people of the world” - treastrain

--

--