zoukankan      html  css  js  c++  java
  • Some thoughts on using Opencv, ceres and Eigen in an Android project and problems I have met.

    It's been some time since I tried to use some third party libraries in a proejct I am currently working on and I'd like to spend some time reviewing what problems I had been faced with and how they were solved.

    To start with, our project requries three third party libraries namely Opencv, ceres and  Eigen . They are used for image , least square  as well as matrix manipulations. In order to use the libraries in Android I need to use NDK, which is a powerfull tool to build libraries for different platforms such as x86, arm and arm64 from sources mainly written in C and C++. Luckily enough , these three libraries can be easily used in an Android device with the help fo NDK.

    Opencv4android is an  opencv library that has supports for Android which you can download from its official website and it is quite easy to use opencv in one project. With a brief scan at its sample project and  its Android.mk file:

    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    
    ifdef OPENCV_ANDROID_SDK
      ifneq ("","$(wildcard $(OPENCV_ANDROID_SDK)/OpenCV.mk)")  // to use opencv , simply include OpenCV.mk where you can find in its root path.
        include ${OPENCV_ANDROID_SDK}/OpenCV.mk 
      else
        include ${OPENCV_ANDROID_SDK}/sdk/native/jni/OpenCV.mk
      endif
    else
      include ../../../sdk/native/jni/OpenCV.mk
    endif
    
    LOCAL_MODULE    := mixed_sample
    LOCAL_SRC_FILES := jni_part.cpp
    LOCAL_LDLIBS +=  -llog -ldl
    
    include $(BUILD_EXECUTABLE)

    Some times I find it useful to include opencv header file path in the mk file . And according to its official websit, try to add LOCAL_PLATFORM := android -15 to resolve errors like "undefined referecens." related to opencv modules.

    Now lets move on to Eigen.

    Eigen is an interesting library that it is made entirely of header files, that's right, no cpp files need to be included in Android.mk file.

    For Ceres, although defautly one can compile it to a static library more easily (simply go into its jni folder and execute ndk-build), we can change its Android.mk and Application.mk file to compile it to a shared_library with some minor changes shown below:

    LOCAL_CFLAGS += -DCERES_BUILDING_SHARED_LIBRARY -DCERES_RESTRICT_SCHUR_SPECIALIZATION
    include $(BUILD_SHARED_LIBRARY)
    //add&change above lines in ceres/jni/Andoird.mk and
    Add LOCAL_LDLIBS := -L$(SYSROOT)/usr/lib -llog in Android.mk

    Now we are done with introducing how to use them with NDK, lets move on to more specific problems I met.

    1. Try to include header paths for each module unless you are sure it is not used;

    2. To include a prebuilt libary, you need to specify a module (start with INCLUDE(CLEAR_VARS) , ends with INCLUDE(BUILD_STATIC_LIBARARY))for each one of prebuilt libraries.

    3. some times I simply couldnt make it work while building static libraries, changing to shared library will help

    4. while using adb shell, we can  set current path as default path , but it expires every time adb shell restarts:

     export LD_LIBRARY_PATH=./

    ... ...

  • 相关阅读:
    利用docker搭建RTMP直播流服务器实现直播
    基于.NET平台的Ocelot网关框架教程汇总
    docker swarm集群搭建及使用Portainer、shipyard
    Swarm 集群并用 Portainer 管理
    如何在Debian 9上安装和使用Docker
    人不成熟的五大特征:立即要回报、不自律、经常被情绪所左右、不愿学习、做事情不靠信念靠人言(你中了几条?)
    使用 xpath helper 提取网页链接
    Python 爬虫js加密破解(四) 360云盘登录password加密
    Python 爬虫js加密破解(三) 百度翻译 sign
    Python 获得最近一个月的每天的日期
  • 原文地址:https://www.cnblogs.com/SongHaoran/p/7207220.html
Copyright © 2011-2022 走看看