# Android using OpenCV, Eigen
## set up NDK and javah
## Eigen for android
https://blog.csdn.net/u010154424/article/details/50975711
## OpenCV for android
https://blog.csdn.net/sbsujjbcy/article/details/49520791
First, download opencv for android https://opencv.org/releases.html
Here I'm using android studio and I create a project call another1
1. put "native" directory into project
``` cp -R /YourPath/OpenCV-android-sdk/sdk/native /YourPath/AndroidStudioProjects/another1/```
2. create JNI folder in ```AndroidStudioProjects/another1/app/src/main```
3. create Android.mk and Application.mk under JNI folder
4. edit gradle.properties
after adding ```android.useDeprecatedNdk = true``` click 'Sync now'
5. edit Application.mk
```
APP_STL := c++_shared
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := all
APP_PLATFORM := android-8
```
6. edit Android.mk
```
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
OpenCV_INSTALL_MODULES := on
OpenCV_CAMERA_MODULES := off
OPENCV_LIB_TYPE := SHARED
ifeq ("$(wildcard $(OPENCV_MK_PATH))", "")
include /YourProjectPath/native/jni/OpenCV.mk
else
include $(OPENCV_MK_PATH)
endif
LOCAL_MODULE := OpenCV
LOCAL_SRC_FILES :=
LOCAL_LDLIBS += -lm -llog
include $(BUILD_SHARED_LIBRARY)
```
6. use NDK build
7. create a java class
load the library we will create later(here I call opencv), and define a function
```
package com.example.eugenechou.another1;
public class OpenCVlib {
static{
System.loadLibrary("opencv");
}
public static native int[] function(int[] buf, int w, int h);
}
```
8. then use javah to create a header file
```
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class com_example_eugenechou_another1_OpenCVlib */
#ifndef _Included_com_example_eugenechou_another1_OpenCVlib
#define _Included_com_example_eugenechou_another1_OpenCVlib
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: com_example_eugenechou_another1_OpenCVlib
* Method: function
* Signature: ([III)[I
*/
JNIEXPORT jintArray JNICALL Java_com_example_eugenechou_another1_OpenCVlib_function
(JNIEnv *, jclass, jintArray, jint, jint);
#ifdef __cplusplus
}
#endif
#endif
```
9. create cpp file to implement function
10. edit Android.mk
```LOCAL_SRC_FILES := opencv.cpp```
###### tags: `note`