Skip to content

Commit

Permalink
Merge pull request #23 from Lauszus/gnustl
Browse files Browse the repository at this point in the history
 Fixed support for Android NDK r18, as gnustl has been removed
  • Loading branch information
Lauszus authored Dec 17, 2018
2 parents 4560b83 + 79020d2 commit f67687e
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 72 deletions.
18 changes: 11 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,36 @@ android:
- platform-tools

# The BuildTools version used by your project
- build-tools-27.0.3
- build-tools-28.0.3

# The SDK version used to compile your project
- android-27
- android-28

# Additional components
- extra-android-m2repository

before_install:
# Accept the licenses needed for OpenCV and this project
- yes | sdkmanager "platforms;android-27" "platforms;android-28"

before_script:
# Download Android NDK, OpenCV Android SDK and Eigen 3
- if test ! -e $HOME/zip-cache/android-ndk.zip ; then wget https://dl.google.com/android/repository/android-ndk-r16b-linux-x86_64.zip -O $HOME/zip-cache/android-ndk.zip ; fi
- if test ! -e $HOME/zip-cache/android-ndk.zip ; then wget https://dl.google.com/android/repository/android-ndk-r18-linux-x86_64.zip -O $HOME/zip-cache/android-ndk.zip ; fi
- if test ! -e $HOME/zip-cache/opencv-sdk.zip ; then wget https://github.com/opencv/opencv/releases/download/3.4.1/opencv-3.4.1-android-sdk.zip -O $HOME/zip-cache/opencv-sdk.zip ; fi
- if test ! -e $HOME/zip-cache/eigen3.zip ; then wget https://bitbucket.org/eigen/eigen/get/3.3.4.zip -O $HOME/zip-cache/eigen3.zip ; fi
- if test ! -e $HOME/zip-cache/eigen3.zip ; then wget https://bitbucket.org/eigen/eigen/get/3.3.5.zip -O $HOME/zip-cache/eigen3.zip ; fi

# Unzip the zip files into their directories
- unzip -qq -n $HOME/zip-cache/android-ndk.zip -d $HOME/android-ndk
- unzip -qq -n $HOME/zip-cache/opencv-sdk.zip -d $HOME/opencv-sdk
- unzip -qq -n $HOME/zip-cache/eigen3.zip -d $HOME/eigen3

# Set environmental variables
- export ANDROID_NDK_HOME=$HOME/android-ndk/android-ndk-r16b
- export ANDROID_NDK_HOME=$(dirname $HOME/android-ndk/android-ndk-*/ndk-build)
- export OPENCV_ANDROID_SDK=$HOME/opencv-sdk/OpenCV-android-sdk
- export EIGEN3_DIR=$(dirname $(find $HOME/eigen3 -type f -name 'signature_of_eigen3_matrix_library' -print -quit))

# Patch OpenCV, so it does not abort on lint errors
- patch $OPENCV_ANDROID_SDK/sdk/build.gradle < opencv.patch
# Apply patch to OpenCV
- patch -d$OPENCV_ANDROID_SDK/../ -p0 < opencv.patch

script:
- ./gradlew --no-daemon build
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ git submodule update --init --recursive

The project is relying on the environmental variables ```OPENCV_ANDROID_SDK``` and ```EIGEN3_DIR``` for [settings.gradle](settings.gradle) and [Android.mk](app/src/main/cpp/Android.mk) to be set to the path of the [OpenCV Android SDK](http://opencv.org/platforms/android) and [Eigen3](https://eigen.tuxfamily.org) libraries.

Please use [OpenCV 3.4.1](https://github.com/opencv/opencv/releases/download/3.4.1/opencv-3.4.1-android-sdk.zip) and [Eigen3 3.3.4](https://bitbucket.org/eigen/eigen/get/3.3.4.zip). Both can be installed from the command line like so:
Please use [OpenCV 3.4.1](https://github.com/opencv/opencv/releases/download/3.4.1/opencv-3.4.1-android-sdk.zip) and [Eigen3 3.3.5](https://bitbucket.org/eigen/eigen/get/3.3.5.zip). Both can be installed from the command line like so:

```bash
wget https://github.com/opencv/opencv/releases/download/3.4.1/opencv-3.4.1-android-sdk.zip
unzip opencv-3.4.1-android-sdk.zip
wget https://bitbucket.org/eigen/eigen/get/3.3.4.zip -O Eigen3.zip
wget https://bitbucket.org/eigen/eigen/get/3.3.5.zip -O Eigen3.zip
unzip Eigen3.zip
```

Expand Down Expand Up @@ -84,5 +84,3 @@ echo %OPENCV_ANDROID_SDK% %EIGEN3_DIR%
__Please note that ```/path/to/``` should be replaced with the actual path to the Eigen and OpenCV Android SDK directories.__

If you have troubles setting the environmental variables, then you can just hardcode the paths in [settings.gradle](settings.gradle) and [Android.mk](app/src/main/cpp/Android.mk).

For more information send me an email at <lauszus@gmail.com>.
14 changes: 7 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
compileSdkVersion 28
defaultConfig {
applicationId 'com.lauszus.facerecognitionapp'
minSdkVersion 15
targetSdkVersion 27
minSdkVersion 16
targetSdkVersion 28
versionCode 5
versionName '1.2.2'
vectorDrawables.useSupportLibrary = true
ndk {
stl 'gnustl_static'
cFlags '-std=gnu++11 -fexceptions -frtti'
stl 'c++_static'
cFlags '-std=gnu++11 -fexceptions -frtti -DANDROID_STL=c++_static'
}
setProperty('archivesBaseName', rootProject.name + '-' + defaultConfig.versionName)
}
Expand Down Expand Up @@ -70,8 +70,8 @@ android {
}

dependencies {
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation project(':opencv')
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/cpp/Application.mk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
APP_PLATFORM := android-27
APP_PLATFORM := android-28
APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
APP_STL := gnustl_static
APP_CPPFLAGS := -std=gnu++11 -frtti -fexceptions
APP_STL := c++_static
APP_CPPFLAGS := -std=gnu++11 -frtti -fexceptions -DANDROID_STL=c++_static

ifeq ($(NDK_DEBUG),0)
APP_CPPFLAGS += -DNDEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,8 @@ public abstract class CameraBridgeViewBase extends SurfaceView implements Surfac

public CameraBridgeViewBase(Context context, int cameraId) {
super(context);
mCameraIndex = cameraId;
getHolder().addCallback(this);
mMaxWidth = MAX_UNSPECIFIED;
mMaxHeight = MAX_UNSPECIFIED;
construct(context, cameraId);

}

public CameraBridgeViewBase(Context context, AttributeSet attrs) {
Expand All @@ -87,13 +85,16 @@ public CameraBridgeViewBase(Context context, AttributeSet attrs) {
if (styledAttrs.getBoolean(R.styleable.CameraBridgeViewBase_show_fps, false))
enableFpsMeter();

mCameraIndex = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, CAMERA_ID_ANY);
int cameraId = styledAttrs.getInt(R.styleable.CameraBridgeViewBase_camera_id, CAMERA_ID_ANY);
styledAttrs.recycle();
construct(context, cameraId);
}

private void construct(Context context, int cameraId) {
mCameraIndex = cameraId;
getHolder().addCallback(this);
mMaxWidth = MAX_UNSPECIFIED;
mMaxHeight = MAX_UNSPECIFIED;
styledAttrs.recycle();

mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
import android.support.v7.widget.Toolbar;
import android.text.InputType;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -394,7 +396,11 @@ public void onClick(View v) {
Log.i(TAG, "Gray height: " + mGray.height() + " Width: " + mGray.width() + " total: " + mGray.total());
if (mGray.total() == 0)
return;
Size imageSize = new Size(200, 200.0f / ((float) mGray.width() / (float) mGray.height())); // Scale image in order to decrease computation time

// Scale image in order to decrease computation time and make the image square,
// so it does not crash on phones with different aspect ratios for the front
// and back camera
Size imageSize = new Size(200, 200);
Imgproc.resize(mGray, mGray, imageSize);
Log.i(TAG, "Small gray height: " + mGray.height() + " Width: " + mGray.width() + " total: " + mGray.total());
//SaveImage(mGray);
Expand All @@ -417,10 +423,29 @@ public void onClick(View v) {
}
});

final GestureDetector mGestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onDoubleTap(MotionEvent e) {
// Show flip animation when the camera is flipped due to a double tap
flipCameraAnimation();
return true;
}
});

mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.camera_java_surface_view);
mOpenCvCameraView.setCameraIndex(prefs.getInt("mCameraIndex", CameraBridgeViewBase.CAMERA_ID_FRONT));
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
mOpenCvCameraView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
});
}

private NativeMethods.MeasureDistTask.Callback measureDistTaskCallback = new NativeMethods.MeasureDistTask.Callback() {
Expand Down Expand Up @@ -670,44 +695,49 @@ public boolean onCreateOptionsMenu(Menu menu) {
// Show rear camera icon if front camera is currently used and front camera icon if back camera is used
MenuItem menuItem = menu.findItem(R.id.flip_camera);
if (mOpenCvCameraView.mCameraIndex == CameraBridgeViewBase.CAMERA_ID_FRONT)
menuItem.setIcon(R.drawable.ic_camera_rear_white_24dp);
else
menuItem.setIcon(R.drawable.ic_camera_front_white_24dp);
else
menuItem.setIcon(R.drawable.ic_camera_rear_white_24dp);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.flip_camera:
mOpenCvCameraView.flipCamera();
private void flipCameraAnimation() {
// Flip the camera
mOpenCvCameraView.flipCamera();

// Do flip camera animation
View v = mToolbar.findViewById(R.id.flip_camera);
ObjectAnimator animator = ObjectAnimator.ofFloat(v, "rotationY", v.getRotationY() + 180.0f);
animator.setDuration(500);
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
// Do flip camera animation
View v = mToolbar.findViewById(R.id.flip_camera);
ObjectAnimator animator = ObjectAnimator.ofFloat(v, "rotationY", v.getRotationY() + 180.0f);
animator.setDuration(500);
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {

}
}

@Override
public void onAnimationEnd(Animator animation) {
supportInvalidateOptionsMenu(); // This will call onCreateOptionsMenu()
}
@Override
public void onAnimationEnd(Animator animation) {
supportInvalidateOptionsMenu(); // This will call onCreateOptionsMenu()
}

@Override
public void onAnimationCancel(Animator animation) {
@Override
public void onAnimationCancel(Animator animation) {

}
}

@Override
public void onAnimationRepeat(Animator animation) {
@Override
public void onAnimationRepeat(Animator animation) {

}
});
animator.start();
}
});
animator.start();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.flip_camera:
flipCameraAnimation();
return true;
}
return super.onOptionsItemSelected(item);
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath 'com.android.tools.build:gradle:3.2.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Apr 16 03:03:10 CEST 2018
#Sun Dec 16 21:52:50 CET 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
40 changes: 27 additions & 13 deletions opencv.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
--- build-orig.gradle 2018-04-16 09:10:01.000000000 +0200
+++ build.gradle 2018-04-16 09:11:53.000000000 +0200
@@ -121,6 +121,10 @@
manifest.srcFile 'java/AndroidManifest.xml'
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}

dependencies {
diff -crb OpenCV-android-sdk/sdk/build.gradle OpenCV-android-sdk-patch/sdk/build.gradle
*** OpenCV-android-sdk/sdk/build.gradle Sun Dec 16 22:44:27 2018
--- OpenCV-android-sdk-patch/sdk/build.gradle Sun Dec 16 22:34:33 2018
***************
*** 121,126 ****
--- 121,130 ----
manifest.srcFile 'java/AndroidManifest.xml'
}
}
+
+ lintOptions {
+ abortOnError false
+ }
}

dependencies {
diff -crb OpenCV-android-sdk/sdk/java/AndroidManifest.xml OpenCV-android-sdk-patch/sdk/java/AndroidManifest.xml
*** OpenCV-android-sdk/sdk/java/AndroidManifest.xml Fri Feb 23 12:24:24 2018
--- OpenCV-android-sdk-patch/sdk/java/AndroidManifest.xml Sun Dec 16 22:28:32 2018
***************
*** 4,8 ****
android:versionCode="3410"
android:versionName="3.4.1">

- <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="21" />
</manifest>
--- 4,7 ----

0 comments on commit f67687e

Please sign in to comment.