Our team of experts is ready to answer!
You can contact us directly
Telegram iconFacebook messenger iconWhatApp icon
Fill in the form below and you will receive an answer within 2 working days.
Or fill in the form below and you will receive an answer within 2 working days.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Reading Time
5 Minutes
Alexander Smorkalov
Software Developer at OpenCV.ai
OpenCV 4.9.0 Launch: Enhanced Android Support and ARM Device Performance

OpenCV For Android Distribution

The OpenCV.ai team, creators of the essential OpenCV library for computer vision, has launched version 4.9.0 in partnership with ARM Holdings. This update is a big step for Android developers, simplifying how OpenCV is used in Android apps and boosting performance on ARM devices.
April 11, 2024

Easier access to OpenCV for Android through Maven Central

In December, we released OpenCV 4.9.0. As part of that release, we made Android builds available through the Maven Central repository for the first time. This work is supported by Arm company, the authors of the computer architecture on which Android and the world’s smartphones are built.

OpenCV is the open-source library for developing and deploying computer vision (CV) workloads. Its availability for Android will make it easier to develop and maintain CV applications for Android systems, lowering the barrier of entry for developers to build high-quality CV algorithms for supporting AI and image processing algorithms.

Managing your application’s OpenCV dependency through Maven Central is simple, with support built into Android Studio and many other tools. Doing so also enables you to easily keep up to date with bug fixes, new features, and performance improvements as new versions of OpenCV are released. The OpenCV team maintains source compatibility for releases, and the update is safe. Using Maven Central also ensures that you get a build of OpenCV configured correctly for performance and for using the correct dependencies.

We are working with Arm on continuous improvements to OpenCV’s performance across the broad reach of Arm-based devices, from sensors to servers and supercomputers. This includes leveraging improvements from algorithmic changes or using new Arm CPU features.

We will update Maven Central with the latest versions of OpenCV as they are released and continue to update our support for Android, ensuring that developers can integrate OpenCV into their workflows alongside other Android functionality.

We would like to thank Arm for supporting this work.

Using OpenCV in your Android application

To start working with OpenCV, you do not need to download the SDK. Just create a new Application in Android Studio (or open an existing one), open your application’s build.gradle of your application where the “android” section is located, and add OpenCV to the dependencies section of the global scope like this:


apply plugin: 'com.android.application'
android {
   namespace 'org.opencv.samples.puzzle15'
   compileSdkVersion 31
   defaultConfig {
       applicationId "org.opencv.samples.puzzle15"
       minSdkVersion 21
       targetSdkVersion 31
       versionCode 301
       versionName "3.01"
   }
   // … more options here
}                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                        
dependencies {                                                                                                                                                                                                                                                                 
       implementation 'org.opencv:opencv:4.9.0'                                                                                                                                                                                                                               
   }                                                                                                                                                                                                                                                                          
}

The OpenCV package will be downloaded and linked automatically by Gradle during the application build. Native libraries are also added to APK automatically. You just need to add a run-time call to load the OpenCV native part before the first library usage like this:


@Override                                                                                                                                                                                                                                                                  
   public void onCreate(Bundle savedInstanceState) {                                                                                                                                                                                                                          
       super.onCreate(savedInstanceState);                                                                                                                                                                                                                                    
       if (OpenCVLoader.initLocal()) {                                                                                                                                                                                                                                        
           Log.i(TAG, "OpenCV loaded successfully");                                                                                                                                                                                                                          
       } else {                                                                                                                                                                                                                                                               
           Log.e(TAG, "OpenCV initialization failed!");                                                                                                                                                                                                                       
           (Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();                                                                                                                                                                                 
           return;                                                                                                                                                                                                                                                            
       }                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                              
       // application initialization logic                                                                                                                                                                                                                                         
   }

It is also possible to use OpenCV with your native code libraries in your Android application. The OpenCV AAR package includes a prefab part and allows developers to develop native parts for Android, too. The OpenCV tutorial Tutorial2-mixed processing provides an example of this.

In summary, as well as the normal Gradle steps outlined above, you must update your native code to link against the OpenCV libraries. In CMake, this can be done as follows:


find_package(OpenCV REQUIRED COMPONENTS OpenCV::opencv_java4)                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                              
file(GLOB srcs *.cpp *.c)                                                                                                                                                                                                                                                      
file(GLOB hdrs *.hpp *.h)                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                              
add_library(${target} SHARED …)
target_link_libraries(${target} OpenCV::opencv_java4)

We look forward to seeing what you achieve with OpenCV

Finally, as a reminder, the OpenCV package is available here:

https://central.sonatype.com/artifact/org.opencv/opencv.

OpenCV is an open-source project distributed with Apache 2.0 license. Feel free to contribute on GitHub!

I’m not a developer; what could I do? Donations are welcome!

If you need custom development and consulting in computer vision, feel free to leave a request at opencv.ai

Let's discuss your project

Book a complimentary consultation

Read also

October 17, 2024

Ethics in artificial intelligence and computer vision

Smart machines are making decisions in people's life death and taxes, — and let's be honest, they don't always do it well or transparently
October 4, 2024

Artificial intelligence and computer vision in education

How smart machines make learning easier and cheating harder
September 27, 2024

Robotics and agriculture

Let's explore how AI for agriculture improving the lives of animals, plants, and humans alike