Create New Project Create Android Project Application name RobotCar. Devel. Tracking Company domain otapiGems.net Project location oidP r ojects\RobotCar. Devel .Tracking package name net.otapigems.robotcar.devel.tracking • Include C++ support Next Cancel

Set up OpenCV SDK for Android Studio

I’m using Visual Studio for C# stuff, but I didn’t found a free proper solution to use the OpenCV SDK for Android development in VS (Xamarin). Also I preferred Android Studio over Eclipse for Android development just to follow Google’s plans. Unfortunatelly, I didn’t find any tutorial of OpenCV’s portal to set up it for Android Studio. So I had to make some investigation for a manual (and preferable a simple) install.

Prepare the OpenCV SDK for Android Studio 3

First of all I had to download and extract to a temporary folder the Android Pack of the latest release of OpenCV SDK from the https://opencv.org/releases.html.

Then:

  • Import module from the extracted SDK folder – select the sdk/java/ folder of extracted to OpenCV SDK
  • Set the Destination Directory (should be different from the extracted SDK folder):

Import Project from ADT (Eclipse Android) Importing a project creates a full copy of the project and does not alter the original Eclipse project. Import Destination Directory:

Machine generated alternative text: Import Project from ADT (Eclipse Android) The ADT project importer can identify some .jar files and even whole source copies of libraries, and replace them with Gradle dependencies. However, it cannot figure out which exact version of the library to use, so it will use the latest. If your project needs to be adjusted to compile with the latest library, you can either import the project again and disable the following options, or better yet, update your project. Replace jars with dependencies, when possible Replace library sources with dependencies, when possible Other Import Options: Create Gradle-style (camelCase) module names Previous Finish Cancel Help

 

  • the target versions had to be fixed on all places: changed everything to API version 23 (Android 6.0) in all graddle script

 

15 puzzle - - openCVSample15puzzle - Android Studio 3.0.1 tile Edit View Navigate Code Analyze Hetactor Nuild Run Tools VCS Window Help -f GODenCVSamDle15Duzzle• C L. Li ? 15•puzzle openCVSample15puzzle build.gradle import-summary-txt • 15-puzzle • alocal.properties CopenCVLibrary331 - openCVSample15puzzle x O Puzzlel SActivityjava DopenCVLibrary331 openCVSample15puzzle G Gradle Scripts build.gradle (Project: Is-puzzle) build.gradle (Module: openCVLibrary331) build_gradle (Module: openCVSampIeISpu771e) *gradle-wrapper.properties (Gradle Version) settings.gradle {Project Settings) locaLproperties (SDK Location) apply plugir.: compi es •com. . application e rsxon bail drools version default Config I applicationld . opencv. samples . puzzle15" targetSdkVersion _ buildTypes I release mini prog

and Compile Sdk Version in all modules:

Project Structure properties Signing Flavors guild lypes Dependencies SDK Location Project Developer Se... Ads Authentication Notifications Modules opencvsa.- mopenCVLibr„. Compile Sdk Version guild Tools Version Library Repository API 23: Android 6.0 (Marshmallow) 26.02 Ignore Assets Pattern Incremental Dex Source Compatibility Target Compatibility 0K Cancel

  • Build the app with menu Build -> Rebuild Project
    • In case of error “Gradle sync failed: Minimum supported Gradle version is 4.1.” the following should be set: File -> Project Structure -> Project -> Gradle version to 4.1

Project Structure Gradie version SDK Location Android Plugin Version 301 Android Plugin Repository jcenter Developer Services Ads Authentication Notifications Modules hi, app Default Library Repository jcenter 0K Cancel

  • Close Project

Create a new OpenCVproject

File -> New -> New Project…

Create New Project Create Android Project Application name RobotCar. Devel. Tracking Company domain otapiGems.net Project location oidP r ojects\RobotCar. Devel .Tracking package name net.otapigems.robotcar.devel.tracking • Include C++ support Next Cancel

Choose the SDK version carefully:

Create New Project Target Android Devices Select the form factors and minimum SDK Some devices require additional SDKs. Low API levels target more devices, but offer fewer phone and Tablet API 23: Android (Marshmallow) By targeting API 23 and later. your app will run on approximately 39.3% of devil Include Android Instant App support Wear API 23: Android 60 (Marshmallow) TV API 21: Android (Lollipop) • Android Auto previous Next Cancel

Choose Empty Activity, switch off Backwards Compatibility (AppCompat):

Create New Project Configure Activity Cmt" a mpty "tivity Acuvtty Name j MainActivity Generate Layout File Layout Name activity_main Backwards Compatibility (AppCompat) If false, this activity base class will be Activity instead of AppCompatActivity previous Next Cancel Finish

File -> Project Structure -> app -> Properties: set Compile SDK version to the proper one (23 in my case):

Project Structure SDK Location Project Developer Services Ads Authentication Notifications Modules properties Signing Flavors Build Iypes Dependencies Compile Sdk Version API 23: Android 6.0 (Marshmallow) Build Tools Version Library Repository Ignore Assets Pattern Incremental Dex Source Compatibility Target Compatibility 0K Cancel

The target versions had to be fixed on all places: changed everything to API version 23 (Android 6.0) in all graddle script

15 puzzle - - openCVSample15puzzle - Android Studio 3.0.1 tile Edit View Navigate Code Analyze Hetactor Nuild Run Tools VCS Window Help -f GODenCVSamDle15Duzzle• C L. Li ? 15•puzzle openCVSample15puzzle build.gradle import-summary-txt • 15-puzzle • alocal.properties CopenCVLibrary331 - openCVSample15puzzle x O Puzzlel SActivityjava DopenCVLibrary331 openCVSample15puzzle G Gradle Scripts build.gradle (Project: Is-puzzle) build.gradle (Module: openCVLibrary331) build_gradle (Module: openCVSampIeISpu771e) *gradle-wrapper.properties (Gradle Version) settings.gradle {Project Settings) locaLproperties (SDK Location) apply plugir.: compi es •com. . application e rsxon bail drools version default Config I applicationld . opencv. samples . puzzle15" targetSdkVersion _ buildTypes I release mini prog

roundIcon doesn’t supported in API 23 (why Android Studio adds this then?), so this line should be removed from the AndroidManifest.xml:

android:roundIcon="@mipmap/ic_launcher_round"
  • Build -> Rebuild Project
  • Run -> Run ‘app’

The dummy sample should run properly

  • File -> New -> Import Module…

To use it in an app, add following line to the settings.gradle:

include':openCVLibrary331'

 

Add to build.gradle:

dependencies{

compileproject(':openCVLibrary331')

}

(change the version number 331 accordingly)

Error message on the phone during running an OpenCV app: “It seems that your device does not support camera”

After some days without any problems, suddenly I got this error message upon debugging an app via Android Studio. The solution is simple, but why didn’t asked this before?:

Settings -> Applications -> Permissions -> Permissions Control -> Camera -> find the app for debug and enable it

Just a side note: of course, the app should have the proper access requests in its AndroidManifest.xml:

<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"/>

From <https://stackoverflow.com/questions/20666366/it-seems-that-your-device-does-not-support-cameraor-it-is-locked>

Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 12860 (Thread-6)

During debug, this error can be fixed by manual install of OpenCV Manager instead of the Google Play one.

It seems that it is a problem of OpenCV Manager version distributed on Play Store (updated 21/09/15).

The version distributed with Android SDK works just fine (OpenCV-android-sdk/apk/OpenCV_3.1.0_Manager_3.10_{platform}.apk). You can download it from OpenCV website.

To install the apk from adb via command line:

adb install c:\AndroidProjects\temp\OpenCV-android-sdk\apk\OpenCV_3.3.1_Manager_3.31_arm64-v8a.apk

From <https://stackoverflow.com/questions/35843940/opencv-3-1-0-absdiff-does-not-work/39833284#39833284>

Install OpenCV Manager to Redmi 4X

OpenCV Manager is targeted to specific platforms and need to be installed on the phone the proper one. Unfortunatelly, it seems the OpenCV Manager available on the Google Play is outdated (2015) and crashes during running sample if the OpenCV. So I had to install the provided OpenCV Manager via the SDK.

Since I have Redmi 4X phone, I installed the OpenCV_3.3.1_Manager_3.31_arm64-v8a.apk.

see for more:

https://stackoverflow.com/questions/25610727/adding-external-library-in-android-studio

Alt-gr special key does not work in Android Studio

If you have a non-English keyboard with some extra characters available only via Alt-gr, you would need the following additional settings as well to reach all the characters on the keyboard.

Add this line:

actionSystem.force.alt.gr=true

to this file:

…\Android\android-studio\bin\idea.properties

From <https://stackoverflow.com/questions/19938618/strange-key-mapping-in-android-studio>

 

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *