ORBSLAM2 android学习

主要编译参考Abner_Chen的博文:

ORB_SLAM2移植到Android,完整配置+填各种自己遇到的坑

编译过程:

1.关于设置ndk路径的问题,有时候会提示当前路径不对

在C:\ndk\android-ndk-r13b下新建一个文件ndk-build 然后就可以了

2.jni中Android.mk中加入libopencv_java.so,并且改变opencv.mk的路径,注意有一行是include的路径。

LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)   
LOCAL_MODULE    := opencv_java
LOCAL_SRC_FILES := libopencv_java.so
include $(PREBUILT_SHARED_LIBRARY)

#############DLib妯″潡##################

include $(CLEAR_VARS)
MAINDIR:= $(LOCAL_PATH)
include $(MAINDIR)/Thirdparty/clapack/Android.mk
LOCAL_PATH := $(MAINDIR)

include $(CLEAR_VARS)
MAINDIR:= $(LOCAL_PATH)
LOCAL_MODULE:= lapack
LOCAL_SHORT_COMMANDS := true
LOCAL_STATIC_LIBRARIES := tmglib clapack blas f2c

LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_EXPORT_LDLIBS := $(LOCAL_LDLIBS)
LOCAL_PATH := $(MAINDIR)
include $(BUILD_SHARED_LIBRARY)
######################################

#############DLib妯″潡##################
include $(CLEAR_VARS)
MAIN_DIR:=$(LOCAL_PATH)
OPENCV_LIB_TYPE:=STATIC
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")  
#try to load OpenCV.mk from default install location  
include C:/OpenCVForAndroid/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
else  
include $(OPENCV_MK_PATH)  
endif 
LOCAL_PATH:=$(MAIN_DIR)
LOCAL_MODULE:=DLib

####################婧愭枃浠堕儴鍒�######################################
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/DLib/include/DUtils
FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/DBoW2/DLib/src/DUtils/*.cpp)
LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)

#LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/DLib/include/DUtilsCV
#FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/DBoW2/DLib/src/DUtilsCV/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/DLib/include/DVision
#FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/DBoW2/DLib/src/DVision/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)

################BOOST#####################閮ㄥ垎
BOOST_VERSION      := 1_49
PROJECT_ROOT       := $(LOCAL_PATH)
BOOST_INCLUDE_PATH := $(PROJECT_ROOT)/Thirdparty/Boost/include/boost-1_49
BOOST_LIB_PATH     := $(PROJECT_ROOT)/Thirdparty/Boost/lib
LOCAL_C_INCLUDES+= $(BOOST_INCLUDE_PATH) 
LOCAL_LDLIBS    := -llog
# The order of these libraries is often important.
LOCAL_LDLIBS += -L$(BOOST_LIB_PATH)     
LOCAL_LDLIBS    +=-lz -llog -landroid -lEGL -lGLESv1_CM
LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions
LOCAL_CPPFLAGS += -D__cplusplus=201103L

#LOCAL_EXPORT_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/DLib/include/DUtils
#LOCAL_EXPORT_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/DLib/include/DUtilsCV
LOCAL_EXPORT_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/DLib/include
LOCAL_EXPORT_C_INCLUDES+=$(BOOST_INCLUDE_PATH)
LOCAL_EXPORT_C_INCLUDES+=C:/OpenCVForAndroid/OpenCV-2.4.9-android-sdk/sdk/native/jni/include
LOCAL_PATH:=$(MAIN_DIR)
include $(BUILD_SHARED_LIBRARY)
###############################################################

##############DBoW2妯″潡#########################################
include $(CLEAR_VARS)
MAIN_DIR:=$(LOCAL_PATH)

OPENCV_LIB_TYPE:=STATIC
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")  
#try to load OpenCV.mk from default install location  
include C:/OpenCVForAndroid/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
else  
include $(OPENCV_MK_PATH)  
endif 
LOCAL_PATH:=$(MAIN_DIR)

LOCAL_MODULE:=DBoW2
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/include/DBoW2
FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/DBoW2/src/*.cpp)
LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_SHARED_LIBRARIES+=DLib
LOCAL_EXPORT_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/DBoW2/include
LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions
LOCAL_CPPFLAGS += -D__cplusplus=201103L
LOCAL_PATH:=$(MAIN_DIR)
include $(BUILD_SHARED_LIBRARY)
###############################################################


###################G2O妯″潡##################################
include $(CLEAR_VARS)
MAIN_DIR:=$(LOCAL_PATH)
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/g2o/g2o/core
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/g2o/g2o/stuff
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/g2o/g2o/solvers
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/g2o/g2o/types
FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/g2o/g2o/core/*.cpp)
LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)

FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/g2o/g2o/solvers/*.cpp)
LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)

FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/g2o/g2o/stuff/*.cpp)
LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)

FILE_LIST:=$(wildcard $(LOCAL_PATH)/Thirdparty/g2o/g2o/types/*.cpp)
LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)

LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/eigen3
LOCAL_SHARED_LIBRARIES+=lapack
LOCAL_MODULE:=g2o
LOCAL_EXPORT_LDLIBS := $(LOCAL_LDLIBS)
LOCAL_EXPORT_C_INCLUDES+=LOCAL_C_INCLUDES
LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions
LOCAL_CPPFLAGS += -D__cplusplus=201103L
LOCAL_PATH:=$(MAIN_DIR)
include $(BUILD_SHARED_LIBRARY)
############################################################

##############Pangolin妯″潡##################################
#include $(CLEAR_VARS)
#MAIN_DIR:=$(LOCAL_PATH)
#
#LOCAL_MODULE:=pangolin
#LOCAL_C_INCLUDES:=$(LOCAL_PATH)/Thirdparty/pangolin/include
#
#SRC_PANGOLIN_DIR:=$(LOCAL_PATH)/Thirdparty/pangolin/src
#LOCAL_SRC_FILES+=$(SRC_PANGOLIN_DIR)/console/SonsoleView.cpp
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/display/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/display/device/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/display/widgets/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/gl/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/gl/compat/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/handler/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/hud/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/image/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/log/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/plot/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/python/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/utils/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/var/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#
#FILE_LIST:=$(wildcard $(SRC_PANGOLIN_DIR)/video/*.cpp)
#LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
#LOCAL_EXPORT_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/pangolin/include
#
#LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions -ftemplate-backtrace-limit=0
#LOCAL_CPPFLAGS += -D__cplusplus=201103L
#
#LOCAL_PATH:=$(MAIN_DIR)
#
#include $(BUILD_SHARED_LIBRARY)

##############ORB_SLAM2妯″潡##################################
include $(CLEAR_VARS)
MAIN_DIR:=$(LOCAL_PATH)
OPENCV_LIB_TYPE:=STATIC
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")  
#try to load OpenCV.mk from default install location  
include C:/OpenCVForAndroid/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
else  
include $(OPENCV_MK_PATH)  
endif 
LOCAL_MODULE := ORB_SLAM2
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/eigen3
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/ORB_SLAM2/include
FILE_LIST:=$(wildcard $(LOCAL_PATH)/ORB_SLAM2/src/*.cc)
LOCAL_SRC_FILES+=$(FILE_LIST:$(LOCAL_PATH)/%=%)
LOCAL_CPP_EXTENSION := .cc
LOCAL_SHARED_LIBRARIES+=DBoW2
LOCAL_SHARED_LIBRARIES+=DLib
LOCAL_SHARED_LIBRARIES+=g2o
LOCAL_LDLIBS += -llog -landroid -lEGL -lGLESv1_CM 
LOCAL_EXPORT_C_INCLUDES+=$(LOCAL_PATH)/ORB_SLAM2/include
LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions -ftemplate-backtrace-limit=0
LOCAL_CPPFLAGS += -D__cplusplus=201103L
LOCAL_PATH:=$(MAIN_DIR)
include $(BUILD_SHARED_LIBRARY)
############################################################

##############ORB_SLAM2 鍩疯妯″潡###############################
include $(CLEAR_VARS)
MAIN_DIR:=$(LOCAL_PATH)
OPENCV_LIB_TYPE:=STATIC
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")  
#try to load OpenCV.mk from default install location  
include C:/OpenCVForAndroid/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
else  
include $(OPENCV_MK_PATH)  
endif 
LOCAL_MODULE := ORB_SLAM2_EXCUTOR
LOCAL_C_INCLUDES+=$(LOCAL_PATH)/Thirdparty/eigen3
LOCAL_C_INCLUDES+=orb_slam2_android_nativefunc_OrbNdkHelper.h
LOCAL_SRC_FILES+=orb_slam2_android_nativefunc_OrbNdkHelper.cpp
LOCAL_SHARED_LIBRARIES+=ORB_SLAM2
LOCAL_SHARED_LIBRARIES+=g2o
LOCAL_LDLIBS += -llog -landroid -lEGL -lGLESv1_CM  

LOCAL_CPPFLAGS := -std=c++11 -pthread -frtti -fexceptions -ftemplate-backtrace-limit=0
LOCAL_CPPFLAGS += -D__cplusplus=201103L
LOCAL_PATH:=$(MAIN_DIR)
include $(BUILD_SHARED_LIBRARY)
############################################################


学习过程:

1.很多安卓手机没有菜单键,有的是长按3秒任务键呼出菜单键。新增一个button代替menu按键。

2.如何设计文件选取功能

public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.choose_calibration:
			if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))//judge if SD card does exist if not return error message
			    startActivityForResult(fileChooserIntent , REQUEST_CODE_2);
	    	else
	    		Toast.makeText(CameraModeActivity.this, "can't find SDcard", Toast.LENGTH_LONG).show();//use Toast.makeText to show message on the screen
			break;
		case R.id.choose_voc:
			if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
			    startActivityForResult(fileChooserIntent , REQUEST_CODE_3);
	    	else
	    		Toast.makeText(CameraModeActivity.this, "can't find SDcard", Toast.LENGTH_LONG).show();
			break;
		case R.id.finish:
			if(!TextUtils.isEmpty(TUMPath)&&!TextUtils.isEmpty(VOCPath)){
				Bundle bundle=new Bundle();
				bundle.putString("voc",VOCPath );
				bundle.putString("calibration",TUMPath );
				Intent intent =new Intent(CameraModeActivity.this,ORBSLAMForCameraActivity.class);//use intent to deliver data from CameraModeActivity to ORBSLAMForCameraActivity
				intent.putExtras(bundle);
				startActivity(intent);
				finish();
			}else{
				Toast.makeText(CameraModeActivity.this, "None of image path or Calibration path can be empty!", Toast.LENGTH_LONG).show();
			}
			break;
		}
	}

然后在ORBSLAMForCameraActivity.java中,可以用getIntent().getString(string)去对应获得相应的路径,实现在不同Activity中传递内容。利用startActivityForResult()开启传递,利用Bundle bundle = new Bundle(); Bundle.putString(string,value);

Intent intent = new Intent(Activity one.this ,Activity two.class); 

 intent.putExtras(bundle);startActivity(intent);

finish();

vocPath = getIntent().getStringExtra("voc");

实现带数据的Activity跳转。


你可能感兴趣的:(SLAM)