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

How to integrate OpenCV with Android Studio

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about how Android Studio integrates OpenCV. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

My environment:

Android Studio Arctic Fox + JDK11 + Gradle 7.0.2 + NDK21 + opencv-4.5.1-android-sdk

Code link:

Build Demo in OpenCV environment

1. Create a Native project

two。 Download OpenCV SDK

OpenCV SDK

3. Create a new libs folder under the cpp directory of Android Studio

Copy the whole OpenCV SDK under the folder "OpenCV-android-sdk\ sdk\ native\ libs" we downloaded to the libs folder just now.

4. Copy the entire include folder under the "OpenCV-android-sdk\ sdk\ native\ jni" path to the cpp folder.

5. Configure build.gradle

6. Configure CMakelists.txt

# the purpose is to let CMake find out where our header file is. Here is include_directories (include) # set the system variable under the cpp/include folder. The goal is to let CMake know where to find our libopencv_java4.so library set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-L ${CMAKE_SOURCE_DIR} / libs/$ {ANDROID_ABI}") target_link_libraries (myopencv opencv_java4 # link libopencv_java4.so, so that this so ${log-lib} will be found in the generated APK)

7. Click build and find the library we introduced in the generated apk

The next thing is that the runtime will report an error.

Java.lang.UnsatisfiedLinkError: dlopen failed: library "libc++_shared.so" not found

The reason is that before NDK18 was compiled by gcc, NDK18 was later compiled by clang, and NDK18 no longer has the library libc++_shared.so, so an error will be reported at run time.

Solution:

Add a sentence to build.gradle

Arguments'- DANDROID_STL=c++_shared'

In this way, the library libc++_shared.so can be obtained remotely

After recompiling, we found that there is libc++_shared.so in apk, and apk can run normally.

Thank you for reading! This is the end of the article on "how to integrate Android Studio with OpenCV". I hope the above content can be of some help to you, so that 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

Development

Wechat

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

12
Report