Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
leadrien committed Nov 19, 2015
0 parents commit b5a295c
Show file tree
Hide file tree
Showing 141 changed files with 25,510 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
build/
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 119 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Native OpenCV with Android Studio

This application is a sample Android Studio project (tested on 1.4.1) with native OpenCV.

It gets the camera frames, make JNI calls with its gray matrices references as parameters, add some random noise to the images from a C++ method, and render the generated frames.

## Usage
Here is how to use this project to run native OpenCV code.

* Make sure you have Android SDK up to date, with NDK installed
* Download latest OpenCV SDK for Android from OpenCV.org and decompress the zip file.
* Clone this project
* Create a symlink named `jniLibs` in `app/src/main` that points to `$OPENCV_SDK/sdk/native/libs`
* In `app/build.gradle` change lines 29 and 30 to points to your OPENCV_SDK
* Sync gradle
* Run the application


## How to create the native OpenCV project from scratch
Here is how I made this project.

I used mostly [this](http://stackoverflow.com/questions/27406303/opencv-in-android-studio), [this](http://stackoverflow.com/questions/32171259/opencv-with-android-studio-1-3-using-new-gradle-undefined-reference) and [that](https://github.com/jlhonora/opencv-android-sample)


* Download latest OpenCV sdk for Android from OpenCV.org and decompress the zip file.
* Import OpenCV to Android Studio, From File -> New -> Import Module, choose sdk/java folder in the unzipped opencv archive.
* Add module dependency by Application -> Module Settings, and select the Dependencies tab. Click + icon at bottom, choose Module Dependency and select the imported OpenCV module.

* Make a symlink named `jniLibs` in `app/src/main` that points to `OPENCV_SDK/sdk/native/libs`

* In application build.gradle use `grandle-experimental:0.3.alpha7`
replace
`classpath 'com.android.tools.build:gradle:1.3.0'`
with
`classpath 'com.android.tools.build:gradle-experimental:0.3.0-alpha7'`


* In gradle-wrapper.properties, use grade 2.6
```
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.6-all.zip
```

* In openCVLibrary module, use the `model` plugin and make sure you use java 7
```
apply plugin: 'com.android.model.library'
model {
compileOptions.with {
sourceCompatibility=JavaVersion.VERSION_1_7
targetCompatibility=JavaVersion.VERSION_1_7
}
android {
compileSdkVersion = 19
buildToolsVersion = "19.1"
defaultConfig.with {
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 19
}
}
}
```

* In app `build.gradle`: use the `model` plugin, make sure you use java 7, add opencv native stuff, remove unused
dependencies

Remove the following lines:

```
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
```

And add OpenCV stuff:
See the file [here](https://github.com/leadrien/opencv_native_androidstudio/blob/master/app/build.gradle)
(You have to set the OpenCV SDK location in it)



* In the app module, delete the following files and folders:
```
src/main/res/values-21
src/main/res/values-w820dp
src/main/res/values/stypes.xml
```

* In `src/main/res/menu/menu_main.xml` remove `app:showAsAction="never"`

* In `AndreoidManifest.xml` remove the following lines:
```
android:theme="@style/AppTheme"
android:theme="@style/AppTheme.NoActionBar" >
```

And add the camera permissions:

```
<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera"/>
<uses-feature android:name="android.hardware.camera.autofocus"/>
<uses-feature android:name="android.hardware.camera.front"/>
<uses-feature android:name="android.hardware.camera.front.autofocus"/>
```

* [Here](https://github.com/leadrien/opencv_native_androidstudio/blob/master/app/src/main/java/ch/hepia/lsn/opencvnative/MainActivity.java) is an example of the Activity.


* In `app/src/main` add a new directory named `jni`
Create a new cpp class, named `native_opencv.h` `native_opencv.cpp`

* [Here](https://github.com/leadrien/opencv_native_androidstudio/blob/master/app/src/main/jni/mymodule.cpp) is an example of C++ code that add random noise to a frame
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
Loading

0 comments on commit b5a295c

Please sign in to comment.