0

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 work at all.

The app compiles, but when trying to run it I simply get an error message on the phone:

Unfortunately OCV T3 Camera Control has stopped.

and logcat:

05-02 00:23:37.876 18962-18962/org.opencv.samples.tutorial3 E/AndroidRuntime: FATAL EXCEPTION: main
                                                                          Process: org.opencv.samples.tutorial3, PID: 18962
                                                                          java.lang.RuntimeException: Unable to resume activity {org.opencv.samples.tutorial3/org.opencv.samples.tutorial3.Tutorial3Activity}: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }
                                                                              at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3103)
                                                                              at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481)
                                                                              at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:148)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                           Caused by: java.lang.IllegalArgumentException: Service Intent must be explicit: Intent { act=org.opencv.engine.BIND }
                                                                              at android.app.ContextImpl.validateServiceIntent(ContextImpl.java:1209)
                                                                              at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1308)
                                                                              at android.app.ContextImpl.bindService(ContextImpl.java:1286)
                                                                              at android.content.ContextWrapper.bindService(ContextWrapper.java:604)
                                                                              at org.opencv.android.AsyncServiceHelper.initOpenCV(AsyncServiceHelper.java:24)
                                                                              at org.opencv.android.OpenCVLoader.initAsync(OpenCVLoader.java:89)
                                                                              at org.opencv.samples.tutorial3.Tutorial3Activity.onResume(Tutorial3Activity.java:91)
                                                                              at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1258)
                                                                              at android.app.Activity.performResume(Activity.java:6327)
                                                                              at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3092)
                                                                              at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3134) 
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2481) 
                                                                              at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                              at android.os.Looper.loop(Looper.java:148) 
                                                                              at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

I'm trying to work with the most current Android Studio version 2.1 and Android version 6.0, which is SDK version 23, but I don't care if earlier versions would suffice. I've seen posts saying that perhaps it is folly to try using these later versions, and that maybe I should use SDK version 21 or 19?

I've tried modifying my build.gradle files to use

    minSdkVersion 19
    targetSdkVersion 21

and this seems to change nothing.

Please help.

Gary Samad
  • 813
  • 7
  • 14

1 Answers1

0

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.)

Gary Samad
  • 813
  • 7
  • 14