1. Preparation
- Install Eclipse
- Install Android SDK
- Install Android NDK
- Download and save OpenCV4Android
2. Create a hello world project
a. Create a regular Android application project
File->New->Android Application Project:Select Blank Activity, click "Next", and "Finish"
b. Add NDK support:
Right click on HelloWorld project->Android Tools->Add Native Support.Now you have new folder jni with two files:
Create a file "Application.mk", with following content:
APP_ABI := armeabi-v7a
NDK_TOOLCHAIN_VERSION := 4.9
APP_CPPFLAGS += -std=c++11 -fexceptions -frtti
APP_STL := gnustl_static
And put to folder "jni".
Edit "Android.mk" so it contains:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OPENCV_SDK_JNI = c:\\OpenCV-2.4.11-android-sdk\\sdk\\native\\jni
include $(OPENCV_SDK_JNI)/OpenCV.mk
LOCAL_MODULE := HelloWorld
LOCAL_SRC_FILES := HelloWorld.cpp
LOCAL_C_INCLUDES += $(OPENCV_SDK_JNI)/include
include $(BUILD_SHARED_LIBRARY)
Where OPENCV_SDK_JNI should point to the correct location in your machine.Edit HelloWorld.cpp. Save everything.
#include <jni.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
extern "C" {
JNIEXPORT int JNICALL Java_org_ski_helloworld_MainActivity_test0(JNIEnv*, jobject, jlong addrData){
Mat& mDat = *(Mat*)addrData;
// doing stuff ...
}
}
Select "Build Project". Now you should have correct syntax highlighting of c++ files.
No comments:
Post a Comment