Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the principle of OpenCV and Android SDK environment

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail about the principle of OpenCV and Android SDK environment, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

Introduction to OpenCV

OpenCV is a cross-platform computer vision library released under the BSD license (open source) that can run on Linux, Windows, Android, and Mac OS operating systems. It is lightweight and efficient-it consists of a series of C functions and a small number of C++ classes, provides interfaces to Python, Ruby, MATLAB and other languages, and implements many general algorithms in image processing and computer vision. The goal is to build an easy-to-use computer vision framework to help developers design more complex computer vision-related applications more easily.

Opencv contains more than 500 functions, covering such as factory product inspection, medical imaging, information security, user interface, camera calibration, stereo vision and robots, as described below. Opencv uses the loose BSD open source protocol, which allows commercial products to be generated without having to develop source code while complying with the protocol.

Download address

Https://sourceforge.net/projects/opencvlibrary/files/?source=navbar

After entering this address, the page we come to can see the branches on different platforms.

Because Android is more convenient to use, we may use a little more for the image processing of mobile phone APP. Let's first learn the opencv development of Android, and then learn under windows when it is mature. Let's click on the opencv_android folder to go in.

Directly express makeup and choose the latest version 3.3.1 to download.

After downloading

The red box is the sdk we downloaded, and the blue box is the decompressed folder.

Android Import OpenCV

Open Android Studio and create a new project named OpenCVDemo. I used a minimum API of 18 when I created it, and then select an empty Activity. The interface after creation is as follows:

Start importing OpenCV

Click File-New-Import Module in the upper left corner

Then click Select path to find the OpenCV-android-sdk\ skd\ java that we just downloaded and decompressed.

Click next, select all by default, and then click Finish

After the completion of the interface, here is the imported report, you can see what you have imported, we can close it without looking at it.

In the Module of my left OpenCV, you can see that there is an error at the bottom of the picture above, indicating that I do not have Android-14 sdk installed.

We click on the link to download and install directly.

After loading successfully, there is also an OpenCVLibrary331 module on the left.

Configuration changes that need to be made

Click on build.gradle (Module:app) and build.gradle (Module:openCVLibrary331) and we can see that the version numbers of the two are not the same.

Build.gradle (Module:app)

Build.gradle (Module:openCVLibrary331)

For these two differences, we change build.gradle (Module:openCVLibrary331) to be consistent with build.gradle (Module:app), and the results are as follows:

After regenerating, we select app on the left, right-click to find Open Module Setting or press F4

Select Dependencies

Click the + sign on the right to select Module dependency

Point OK

Then we found native\ Libs under sdk in the downloaded OpenCV-android-sdk.

All of this is copied to app\ libs in the program directory.

Then add compile fileTree (dir: "$buildDir/native-libs", include:'native-libs.jar') to dependencies in build.gradle (Module:app)

We made this rack native-libs 's name.

Then add these two paragraphs under dependencies.

Task nativeLibsToJar (type: Jar, description:'Create a Jar of nativeLibs') {

DestinationDir file ("$buildDir/native-libs")

BaseName 'native-libs'

From fileTree (dir:'libs',include:'* * / * .so')

Into 'lib/'

}

Tasks.withType (JavaCompile) {

CompileTask-> compileTask.dependsOn (nativeLibsToJar)

Then we Build-Make Project on the above to generate

Will be in

Generate a folder that will exist below

Our own definition of jar

It is very unfriendly to generate jar so that we do not need to install the apk of OpenCV_Manager after we call OpenCV.

In this way, the environment is complete, but the compiled APK has 82m because there are too many things loaded. After studying it, we will recompile and compress the unnecessary libraries.

About the principle of OpenCV and Android SDK environment is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report