Skip to content

Commit

Permalink
Update android project
Browse files Browse the repository at this point in the history
  • Loading branch information
khoben committed Aug 28, 2019
1 parent 286fe51 commit 524735e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 70 deletions.
17 changes: 8 additions & 9 deletions android/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@ include_directories(
${OpenCV_DIR}/include/
${LIB_SRC_DIR}/src/)

file(GLOB_RECURSE PROJECT_CXX_FILES
${LIB_SRC_DIR}/src/*.cpp
${LIB_SRC_DIR}/src/*.hpp
)

list(FILTER PROJECT_CXX_FILES EXCLUDE REGEX ".+main\\.cpp")

add_library(ar_core-lib
SHARED
${LIB_SRC_DIR}/src/Utils/CvUtils.hpp
${LIB_SRC_DIR}/src/Recognition/Recognition.hpp
${LIB_SRC_DIR}/src/Tracking/Tracking.hpp
${LIB_SRC_DIR}/src/Recognition/Recognition.cpp
${LIB_SRC_DIR}/src/Tracking/Tracking.cpp
${LIB_SRC_DIR}/src/AR/Ar.cpp
${LIB_SRC_DIR}/src/AR/Ar.hpp
${LIB_SRC_DIR}/src/Recognition/FeatureDB.hpp
${LIB_SRC_DIR}/src/Recognition/FeatureDB.cpp
${PROJECT_CXX_FILES}
src/main/cpp/android.hpp
src/main/cpp/android.cpp
src/main/cpp/native-lib.cpp
Expand Down
7 changes: 0 additions & 7 deletions android/app/src/main/cpp/android.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ int addMarker(cv::Mat img) {
return 0;
}

int createMarkerDB() {
if (ar == nullptr)
return -1;
ar->create();
return 0;
}

int process(Mat frame, Mat &out) {
if (ar == nullptr)
return -1;
Expand Down
7 changes: 0 additions & 7 deletions android/app/src/main/cpp/android.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,6 @@ void init(Mat frame);
*/
int addMarker(cv::Mat img);

/**
* @brief Create marker 'database'
*
* @return int
*/
int createMarkerDB();

/**
* @brief Process frame, find matching in marker 'database'
*
Expand Down
41 changes: 2 additions & 39 deletions android/app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,9 @@
using namespace std;
using namespace cv;

int toGray(Mat img, Mat& gray);

extern "C"
JNIEXPORT jint JNICALL
Java_com_khoben_arcore_OpenCVJNI_toGray(JNIEnv *env, jclass type, jlong matAddrRgba,
jlong matAddrGray) {
Mat& mRgb = *(Mat*)matAddrRgba;
Mat& mGray = *(Mat*)matAddrGray;

int conv;
jint retVal;

conv = toGray(mRgb, mGray);
retVal = (jint)conv;

return retVal;

}

extern "C"
JNIEXPORT jint JNICALL
Java_com_khoben_arcore_OpenCVJNI_initAR(JNIEnv *env, jclass type, jlong matAddrRgba) {
Java_com_khoben_arcore_OpenCVJNI_init(JNIEnv *env, jclass type, jlong matAddrRgba) {
Mat& mRgb = *(Mat*)matAddrRgba;
// init AR
init(mRgb);
Expand All @@ -39,7 +20,7 @@ Java_com_khoben_arcore_OpenCVJNI_initAR(JNIEnv *env, jclass type, jlong matAddrR

extern "C"
JNIEXPORT jint JNICALL
Java_com_khoben_arcore_OpenCVJNI_startAR(JNIEnv *env, jclass type, jlong matAddrRgba,
Java_com_khoben_arcore_OpenCVJNI_start(JNIEnv *env, jclass type, jlong matAddrRgba,
jlong matAddrGray) {

Mat& mRgb = *(Mat*)matAddrRgba;
Expand All @@ -65,21 +46,3 @@ Java_com_khoben_arcore_OpenCVJNI_addMarker(JNIEnv *env, jclass type, jlong matAd
return 0;

}

extern "C"
JNIEXPORT jint JNICALL
Java_com_khoben_arcore_OpenCVJNI_createMarkerDB(JNIEnv *env, jclass type) {
createMarkerDB();
return 0;
}

int toGray(Mat img, Mat& gray)
{
cvtColor(img, gray, COLOR_RGBA2GRAY); // Assuming RGBA input

if (gray.rows == img.rows && gray.cols == img.cols)
{
return (1);
}
return(0);
}
6 changes: 2 additions & 4 deletions android/app/src/main/java/com/khoben/arcore/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase;
import org.opencv.android.JavaCamera2View;
import org.opencv.android.JavaCameraView;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.OpenCVLoader;
Expand Down Expand Up @@ -86,7 +85,6 @@ private void loadMarkers() {
OpenCVJNI.addMarker(mat_2.getNativeObjAddr());
OpenCVJNI.addMarker(mat_3.getNativeObjAddr());
OpenCVJNI.addMarker(mat_1.getNativeObjAddr());
OpenCVJNI.createMarkerDB();
}

public void onPause() {
Expand Down Expand Up @@ -118,7 +116,7 @@ public void onCameraViewStarted(int width, int height) {
Log.i(TAG, "started");
frame = new Mat(height, width, CvType.CV_8UC4);
processedFrame = new Mat(height, width, CvType.CV_8UC4);
OpenCVJNI.initAR(frame.getNativeObjAddr());
OpenCVJNI.init(frame.getNativeObjAddr());
loadMarkers();
}

Expand All @@ -132,7 +130,7 @@ public void onCameraViewStopped() {
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Log.i(TAG, "on frame");
frame = inputFrame.rgba();
OpenCVJNI.startAR(frame.getNativeObjAddr(), processedFrame.getNativeObjAddr());
OpenCVJNI.start(frame.getNativeObjAddr(), processedFrame.getNativeObjAddr());
return processedFrame;
}
}
6 changes: 2 additions & 4 deletions android/app/src/main/java/com/khoben/arcore/OpenCVJNI.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.khoben.arcore;

public class OpenCVJNI {
public static native int toGray(long matAddrRgba, long matAddrGray);
public static native int startAR(long matAddrRgba, long matAddrGray);
public static native int initAR(long matAddrRgba);
public static native int start(long matAddrRgba, long matAddrGray);
public static native int init(long matAddrRgba);
public static native int addMarker(long matAddrRgba);
public static native int createMarkerDB();
}

0 comments on commit 524735e

Please sign in to comment.