Android-OpenCV


Source link: https://github.com/ahasbini/Android-OpenCV

Android-OpenCV

An Android Studio project which has a module that contains OpenCV SDK files ported and configured to use CMake and Gradle plugin 2.3.1 or above, making it easy to include OpenCV into Android applications.

Integration

Currently the doc contains details of integrating the opencv module into an exiting git repo of an Android Studio project using git submodule.

Note: if your project is not versioned by git, it will not work. You could enable git by running the following command in the project root directory, but careful not do so if your project is versioned by other VCS tools:

git init 

Sooner or later I'll include steps to include the opencv module without using git submodule and for projects that are not versioned by git. It is better to understand how git submodule works via this link: Git - Submodules. For team managed git repositories, read the section Cloning a Project with Submodules carefully.

Within the project directory, open bash/cmd and run the following command:

git submodule add https://github.com/ahasbini/Android-OpenCV.git android-opencv 

Then within the project directory, edit settings.gradle file and append the following and do Gradle Sync :

include ':android-opencv:opencv' 

Within the Project View in Android Studio, right click and choose "Configure project subset" and check opencv. Then do a Gradle Sync Gradle Sync . You should see opencv as a module as the image below:

Then within the app module directory (or application module that you're developing), create or alter the CMakeLists.txt file and add the following lines (Note that if you you are not developing a native library, you can skip this step):

set(OpenCV_DIR "../android-opencv/opencv/src/sdk/native/jni") find_package(OpenCV REQUIRED) message(STATUS "OpenCV libraries: ${
OpenCV_LIBS
}
") target_link_libraries(YOUR_TARGET_LIB ${
OpenCV_LIBS
}
) 

Then within the app module directory (or application module that you're developing), alter it's build.gradle file as such (Note that if you you are not developing a native library, only the compile line is needed):

apply plugin: 'com.android.application' ... android {

  ...
  defaultConfig {

...

externalNativeBuild {

 cmake {

  cppFlags "-frtti -fexceptions"

  //Choose the abi architectures that you would like to compile to

  abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'

 
}

}

  
}

  buildTypes {

...
  
}

  externalNativeBuild {

cmake {

 path "CMakeLists.txt"

}

  
}
 
}
  dependencies {

  ...
  compile project(':android-opencv:opencv') 
}
 

After final step, OpenCV would be included within the application and their APIs could be accessed from within the Java and Native C/C++ code. To check if OpenCV is working properly, add the following in an Application, Activity or any class to load OpenCV (make sure that the class will be accessed at runtime):

public class MyClass {

static {

if (BuildConfig.DEBUG) {

 OpenCVLoader.initDebug();

}

  
}

... 
}
 

Then build and launch the application. Once the class is loaded, the logcat will display OpenCV messages as below (the first error is normal):

10-21 16:53:28.399 D/OpenCV/StaticHelper: Trying to get library list 10-21 16:53:28.419 E/OpenCV/StaticHelper: OpenCV error: Cannot load info library for OpenCV 10-21 16:53:28.419 D/OpenCV/StaticHelper: Library list: "" 10-21 16:53:28.419 D/OpenCV/StaticHelper: First attempt to load libs 10-21 16:53:28.419 D/OpenCV/StaticHelper: Trying to init OpenCV libs 10-21 16:53:28.420 D/OpenCV/StaticHelper: Trying to load library opencv_java3 10-21 16:53:28.428 I/OpenCV: calling android_getCpuFeatures() ... 10-21 16:53:28.430 I/OpenCV: calling android_getCpuFeatures() ... Done (1f7ff) 10-21 16:53:28.441 D/OpenCV/StaticHelper: Library opencv_java3 loaded 10-21 16:53:28.441 D/OpenCV/StaticHelper: First attempt to load libs is OK 10-21 16:53:28.444 I/OpenCV/StaticHelper: General configuration for OpenCV 3.3.0 ===================================== 10-21 16:53:28.444 I/OpenCV/StaticHelper:
Version control:

3.3.0 10-21 16:53:28.444 I/OpenCV/StaticHelper:
Platform: 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  Timestamp:

 2017-08-04T00:30:10Z 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  Host:

Linux 4.8.0-58-generic x86_64 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  Target:

 Linux 1 armv7-a 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  CMake:

  2.8.12.2 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  CMake generator:

 Ninja 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  CMake build tool:

/usr/bin/ninja 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  Configuration:

Release 10-21 16:53:28.444 I/OpenCV/StaticHelper:
CPU/HW features: 10-21 16:53:28.444 I/OpenCV/StaticHelper:
  Baseline:

  NEON NEON 10-21 16:53:28.444 I/OpenCV/StaticHelper:

 requested:

  DETECT 10-21 16:53:28.444 I/OpenCV/StaticHelper:

 required:

NEON 10-21 16:53:28.444 I/OpenCV/StaticHelper:

 disabled:

VFPV3 10-21 16:53:28.444 I/OpenCV/StaticHelper:
C/C++: 10-21 16:53:28.445 I/OpenCV/StaticHelper:
  Built as dynamic libs?:

NO 10-21 16:53:28.445 I/OpenCV/StaticHelper:
  C++ Compiler:

 /usr/bin/ccache /opt/android/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ (ver 4.8) 

Also, you could inspect the built apk under app_module_directory/build/outputs to see that the libopenc_java3.so is included within the abi architecture folders (drag the apk onto the text editor tabs of Android Studio):

Updating OpenCV

I'll be monitoring OpenCV's SDK and releases on their website in order to re-port it with their updated files. Please post an issue if I haven't done so within a day or two.

In order to update the OpenCV module to the latest version simply open a bash/cmd in project_root_directory/android-opencv/ and run the command:

git pull 

Once the command finishes, the opencv module will be updated to the latest commit on the repo. Do a Gradle Sync , refresh linked C++ projects ( Build > Refresh Linked C++ Projects) and compile to make sure the update was successful.

Checkout to a certain version of OpenCV

With each release of OpenCV SDK a tag with the OpenCV version will be created on the commit of the release. To checkout to a certain version of the OpenCV library, open a bash/cmd in project_root_directory/android-opencv/ and run the command:

git pull git checkout version-number 

Where version-number is the version of OpenCV you'd like to checkout to (example: 3.2.0). The minimum version of the OpenCV within the repo is 3.2.0.

Don't forget to do a Gradle Sync , refresh linked C++ projects ( Build > Refresh Linked C++ Projects) and compile to make sure the checkout was successful.

Resources

Implementation of a TextView and all its direct/indirect subclasses with native support for the Roboto fonts, includes the brand new Roboto Slab fonts.

Gradle port of Google's SlidingTabLayout to display a custom ViewPager title strip as used in Google I/O Android App, Android SlidingTabsBasic Sample, and Android SlidingTabsColors Sample. It has minor modifications to work from SDK 8

Android's EditText widget supports formatted (a.k.a., "rich text") editing. It just lacks any way for the user to supply formatting, and it does not provide much in the way of convenience methods for a developer to, say, tie in some sort of toolbar to allow users to format selections.

That's where RichEditText comes in.

RichEditText is a drop-in replacement for EditText that:

  • Provides an action mode on Android 4.0+ that allows users to format selected pieces of text
  • Provides convenience methods to allow developers to trigger formatting for selected text via other means

A facade between executing requests and creating them. The library provides an interface for creating requests, but delegates the actual execution to RequestExecutors. It also generates REST services for you using annotation processing.

The fastest view-injection Android library that populates View Holders. Using annotation processing, this library generates findViewById(), saves code by connecting view-related methods to your views without need to findViewById and then setOnClickListener, and some other smart features that make it amazingly easy to use.

A sample android starter project to demonstrate the integration of the following tools:

  • Automation: Gradle
  • Testing: Android Testing Framework, Robotium, Roboelectric (JUnit, Android)
  • Continuous Integration: TravisCI

Sample Tasks:

  • Adding testing-only project dependencies
  • Using square spoon to run integraton tests
  • Writing android tests with robotium
  • Writing junit tests with robolectric
  • Android tests can be run with only Robotium use "gradle connectedAndroidTest"
  • Android tests can be run with Robotium and Spoon "gradle spoon"
  • Robolectric junit tests can be run with "gradle clean test"

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes