Skip to content Skip to sidebar Skip to footer

How To Get Opencv Samples To Work With Android Studio 2.1

I'm having a hell of a time trying to get opencv to work with Android Studio. I've followed all of the obvious tutorials, but can't get the opencv version 2.4.11 sample code to wo

Solution 1:

Ok, I figured out the basic answer, which now allows the samples to actually run, although they still have flaws as described in other questions.

The core answer is that you must set:

minSdkVersion 19
targetSdkVersion 19

in the build.gradle files.

The reason is apparently that the way Android "Intents" are specified changed from relative to absolute after version 19 of Android, and opencv hasn't been updated to take care of this. I found this out first through this obscure reference on answers.opencv.org (which apparently no longer exists - what the heck is happening to opencv?):

https://webcache.googleusercontent.com/search?q=cache:T5pTdiCxRJIJ:answers.opencv.org/question/54450/error-opencv4android-caused-by-javalangillegalargumentexception-service-intent-must-be-explicit/+&cd=1&hl=en&ct=clnk&gl=us

You must fix this in every build.gradle file that includes this targetSdkVersion directive, including in the opencv library directory and in each sample directory.

The samples still only work in landscape mode and not portrait mode as I ask in question:

How to force an Android camera to display in portrait mode with opencv?

And there are still more problems with the display of menus in the sample apps, etc., etc.

What the heck is going on with opencv and Android? Android sdk version 19 (Android 4.4.2) is at least a year (or two or three) or more old, and this (approximate) version of opencv has been around for probably a year or more. And the samples supplied with the distribution don't even work out of the box? Is anyone still maintaining opencv for Android?

(Sorry for the commentary, please don't bother replying with opinions, just if you know something about when this stuff is going to be fixed in the standard distribution.)

Post a Comment for "How To Get Opencv Samples To Work With Android Studio 2.1"