Skip to content

Commit

Permalink
First push of nonNative(Java) from NativeLib(cpp)
Browse files Browse the repository at this point in the history
ARMarker with OpenCv 3.4.1
  • Loading branch information
Pascal66 committed Sep 19, 2019
1 parent 236ba8a commit 3c72fe3
Show file tree
Hide file tree
Showing 159 changed files with 11,408 additions and 10,521 deletions.
2 changes: 2 additions & 0 deletions ARMarker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ android {
defaultConfig {
minSdkVersion 19
targetSdkVersion 29
versionCode = 1
versionName = '1.0'
}

buildTypes {
Expand Down
13 changes: 6 additions & 7 deletions ARMarker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="de.rwth" android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
xmlns:tools="http://schemas.android.com/tools"
package="de.rwth">

<application android:label="@string/app_name">
</application>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application android:label="@string/app_name" />

</manifest>
36 changes: 16 additions & 20 deletions ARMarker/src/main/java/markerDetection/DetectionThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import nativeLib.NativeLib;

import nativeLib.notNativeLib;
import preview.Preview;

import android.opengl.GLSurfaceView;
Expand All @@ -19,7 +20,8 @@ public class DetectionThread extends Thread {
private boolean stopRequest = false;
private GLSurfaceView openglView;
private Preview preview;
private NativeLib nativelib;
//private NativeLib nativelib;
private notNativeLib notNativelib;
private float[] mat;
private long start = 0;
private long now = 0;
Expand All @@ -29,12 +31,12 @@ public class DetectionThread extends Thread {
private HashMap<Integer, MarkerObject> markerObjectMap;
private UnrecognizedMarkerListener unrecognizedMarkerListener;

public DetectionThread(NativeLib nativeLib, GLSurfaceView openglView,
public DetectionThread(notNativeLib notNativeLib, GLSurfaceView openglView,
HashMap<Integer, MarkerObject> markerObjectMap,
UnrecognizedMarkerListener unrecognizedMarkerListener) {
this.openglView = openglView;
this.markerObjectMap = markerObjectMap;
this.nativelib = nativeLib;
this.notNativelib = notNativeLib;
this.unrecognizedMarkerListener = unrecognizedMarkerListener;

// TODO make size dynamically after the init function.
Expand All @@ -48,16 +50,14 @@ public DetectionThread(NativeLib nativeLib, GLSurfaceView openglView,
@Override
public synchronized void run() {
while (true) {
while (busy == false || stopRequest == true) {
while (!busy || stopRequest) {
try {
wait();// wait for a new frame
} catch (InterruptedException ignored) {
}
}

if (stopRequest == true) {
// do nothing
} else {
if (!stopRequest) {
if (calcFps) {
// calculate the fps
if (start == 0) {
Expand All @@ -72,10 +72,10 @@ public synchronized void run() {
fcount = 0;
}
}
// Pass the frame to the native code and find the
// marker information.
// Pass the frame to the native code and find the marker information.
// The false at the end is a remainder of the calibration.
//TODO nativelib.detectMarkers(frame, mat, frameHeight, frameWidth,false);
notNativelib.detectMarkers(frame, mat, frameHeight, frameWidth,false);

// Needs to be reworked to. Either just deleted, or changed into
// some timer delay
Expand All @@ -92,16 +92,13 @@ public synchronized void run() {

// Log.d(LOG_TAG, "StartIdx");

MarkerObject markerObj = markerObjectMap
.get((int) mat[idIdx]);
MarkerObject markerObj = markerObjectMap.get((int) mat[idIdx]);

if (markerObj != null) {
markerObj.OnMarkerPositionRecognized(mat, startIdx,
endIdx);
markerObj.OnMarkerPositionRecognized(mat, startIdx, endIdx);
} else {
if (unrecognizedMarkerListener != null) {
unrecognizedMarkerListener
.onUnrecognizedMarkerDetected(
unrecognizedMarkerListener.onUnrecognizedMarkerDetected(
(int) mat[idIdx], mat, startIdx,
endIdx, (int) mat[rotIdx]);
}
Expand All @@ -110,15 +107,15 @@ public synchronized void run() {

busy = false;
preview.reAddCallbackBuffer(frame);
}
} // else do nothing

yield();
}

}

public synchronized void nextFrame(byte[] data) {
if (busy == false /* this.getState() == Thread.State.WAITING */) {
if (!busy /* this.getState() == Thread.State.WAITING */) {
// ok, we are ready for a new frame:
busy = true;
this.frame = data;
Expand All @@ -135,7 +132,7 @@ public void setImageSizeAndRun(int height, int width) {
frameHeight = height;
frameWidth = width;

if (stopRequest == true) {
if (stopRequest) {
// this means the thread is active, no starting is needed,
// just reset the flag.
stopRequest = false;
Expand All @@ -162,8 +159,7 @@ public void calculateFrameRate() {
calcFps = true;
}

public void setMarkerObjectMap(
HashMap<Integer, MarkerObject> markerObjectMap) {
public void setMarkerObjectMap(HashMap<Integer, MarkerObject> markerObjectMap) {
this.markerObjectMap = markerObjectMap;
}
}
36 changes: 13 additions & 23 deletions ARMarker/src/main/java/markerDetection/MarkerDetectionSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import nativeLib.NativeLib;

import nativeLib.notNativeLib;
import preview.Preview;
import preview.PreviewPost2_0;
import preview.PreviewPre2_0;
Expand All @@ -37,8 +38,7 @@
public abstract class MarkerDetectionSetup extends Setup {

// /**
// * This is the ID for the MarkerObject that defines which object to
// display
// * This is the ID for the MarkerObject that defines which object to display
// * for all markers if no specific object for a marker was defined.
// */
// public final static int UNDIFINED_MARKER_OBJECT = -1;
Expand All @@ -52,7 +52,7 @@ public abstract class MarkerDetectionSetup extends Setup {

// private ProgressDialog pd;
// public int MAX_CALIB_FRAMES;
private NativeLib nativeLib = new NativeLib();
private notNativeLib nativeLib = new notNativeLib();
private CameraCalibration calib = null;
private Camera.Size cameraSize;
private LayoutParams optimalLayoutParams;
Expand All @@ -61,11 +61,10 @@ public abstract class MarkerDetectionSetup extends Setup {
public void initializeCamera() {

MarkerObjectMap markerObjectMap = new MarkerObjectMap();
DisplayMetrics displayMetrics = myTargetActivity.getResources()
.getDisplayMetrics();
DisplayMetrics displayMetrics = myTargetActivity.getResources().getDisplayMetrics();
int weight = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
int apiLevel = Integer.parseInt(android.os.Build.VERSION.SDK);
int apiLevel = /*Integer.parseInt*/(android.os.Build.VERSION.SDK_INT);

Camera mCamera = Camera.open();
Camera.Parameters parameters = mCamera.getParameters();
Expand All @@ -85,16 +84,14 @@ public void initializeCamera() {
// initialize native code.
int[] constants = new int[2];
//TODO nativeLib.initThread(constants, calib.cameraMatrix, calib.distortionMatrix);

notNativeLib.initThread(constants, calib.cameraMatrix, calib.distortionMatrix);
myThread = new DetectionThread(nativeLib, myGLSurfaceView,
markerObjectMap, _a2_getUnrecognizedMarkerListener());
if (apiLevel <= 5) {
cameraPreview = new PreviewPre2_0(myTargetActivity, myThread,
cameraSize);
cameraPreview = new PreviewPre2_0(myTargetActivity, myThread, cameraSize);
Log.d("AR", "API Level: " + apiLevel + " Created Preview Pre2.1");
} else {
cameraPreview = new PreviewPost2_0(myTargetActivity, myThread,
cameraSize);
cameraPreview = new PreviewPost2_0(myTargetActivity, myThread, cameraSize);
Log.d("AR", "API Level: " + apiLevel + " Created Preview Post2.1");
}

Expand Down Expand Up @@ -148,10 +145,7 @@ private int postSdkV5(Camera.Parameters parameters, int w, int h) {

for (int i = 1; i < supportedSizes.size(); i++) {
currentSizeChoice = supportedSizes.get(i);
if (((Math.abs(aspectRatio
- ((double) cameraSize.width / (double) cameraSize.height))) > Math
.abs((aspectRatio - ((double) currentSizeChoice.width / (double) currentSizeChoice.height))))
&& (currentSizeChoice.height <= 240)) {
if (((Math.abs(aspectRatio - ((double) cameraSize.width / (double) cameraSize.height))) > Math.abs((aspectRatio - ((double) currentSizeChoice.width / (double) currentSizeChoice.height)))) && (currentSizeChoice.height <= 240)) {
cameraSize = currentSizeChoice;
}
}
Expand All @@ -163,8 +157,7 @@ private int postSdkV5(Camera.Parameters parameters, int w, int h) {

private void tryToLoadCameraSettings() {
// Load previously stored calibrations
SharedPreferences settings = myTargetActivity.getSharedPreferences(
CALIB_PATH, 0);
SharedPreferences settings = myTargetActivity.getSharedPreferences(CALIB_PATH, 0);
String fileName = settings.getString("calibration", null);
if (fileName != null) {
try {
Expand All @@ -173,13 +166,11 @@ private void tryToLoadCameraSettings() {
Log.d("AR", "using old calibration");
} catch (Exception e) {
Log.d("AR", "default value, file is empty");
calib = CameraCalibration.defaultCalib(cameraSize.width,
cameraSize.height);
calib = CameraCalibration.defaultCalib(cameraSize.width, cameraSize.height);
}
} else {
Log.d("AR", "default value, file not found");
calib = CameraCalibration.defaultCalib(cameraSize.width,
cameraSize.height);
calib = CameraCalibration.defaultCalib(cameraSize.width, cameraSize.height);
}
}

Expand All @@ -198,8 +189,7 @@ private void tryToLoadCameraSettings() {

public abstract UnrecognizedMarkerListener _a2_getUnrecognizedMarkerListener();

public abstract void _a3_registerMarkerObjects(
MarkerObjectMap markerObjectMap);
public abstract void _a3_registerMarkerObjects(MarkerObjectMap markerObjectMap);

@Override
public void onDestroy(Activity a) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
public interface UnrecognizedMarkerListener {

/**
* @param markerCode
* @param mat
* @param startIdx
* @param endIdx
* @param rotationValue
* @param markerCode int
* @param mat float[]
* @param startIdx int
* @param endIdx int
* @param rotationValue int
* 0 90 180 or 270
*/
void onUnrecognizedMarkerDetected(int markerCode, float[] mat,
int startIdx, int endIdx, int rotationValue);
void onUnrecognizedMarkerDetected(int markerCode, float[] mat, int startIdx, int endIdx, int rotationValue);

}
Loading

0 comments on commit 3c72fe3

Please sign in to comment.