0

This is the code I'm trying to use

File filePath = new File(Environment.getExternalStorageDirectory(), "/test.bmp");
String file = filePath.getAbsolutePath();
Mat input_mat = Highgui.imread(file);

When I use the app with the last line it crashes. I'm not sure if the last line is the mistake or if I'm not accessing the test.bmp file properly. Its saved on the root of the sdcard.

It is for an android app on eclipse.

edit logcat

01-11 22:38:50.288: E/AndroidRuntime(545): FATAL EXCEPTION: main
01-11 22:38:50.288: E/AndroidRuntime(545): java.lang.UnsatisfiedLinkError: imread_1
01-11 22:38:50.288: E/AndroidRuntime(545):  at org.opencv.highgui.Highgui.imread_1(Native Method)
01-11 22:38:50.288: E/AndroidRuntime(545):  at org.opencv.highgui.Highgui.imread(Highgui.java:324)
01-11 22:38:50.288: E/AndroidRuntime(545):  at com.example.android.photobyintent.PhotoIntentActivity.dispatchProcVideoIntent(PhotoIntentActivity.java:186)
01-11 22:38:50.288: E/AndroidRuntime(545):  at com.example.android.photobyintent.PhotoIntentActivity.access$2(PhotoIntentActivity.java:182)
01-11 22:38:50.288: E/AndroidRuntime(545):  at com.example.android.photobyintent.PhotoIntentActivity$4.onClick(PhotoIntentActivity.java:264)
01-11 22:38:50.288: E/AndroidRuntime(545):  at android.view.View.performClick(View.java:3480)
01-11 22:38:50.288: E/AndroidRuntime(545):  at android.view.View$PerformClick.run(View.java:13983)
01-11 22:38:50.288: E/AndroidRuntime(545):  at android.os.Handler.handleCallback(Handler.java:605)
01-11 22:38:50.288: E/AndroidRuntime(545):  at android.os.Handler.dispatchMessage(Handler.java:92)
01-11 22:38:50.288: E/AndroidRuntime(545):  at android.os.Looper.loop(Looper.java:137)
01-11 22:38:50.288: E/AndroidRuntime(545):  at android.app.ActivityThread.main(ActivityThread.java:4340)
01-11 22:38:50.288: E/AndroidRuntime(545):  at java.lang.reflect.Method.invokeNative(Native Method)
01-11 22:38:50.288: E/AndroidRuntime(545):  at java.lang.reflect.Method.invoke(Method.java:511)
01-11 22:38:50.288: E/AndroidRuntime(545):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-11 22:38:50.288: E/AndroidRuntime(545):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-11 22:38:50.288: E/AndroidRuntime(545):  at dalvik.system.NativeStart.main(Native Method)
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • 1
    What is the error message from logcat that you're seeing when the app crashes? – Edward Falk Jan 11 '13 at 22:34
  • 1
    This isn't related to your problem, but I thought I'd mention that the leading '/' isn't needed in the filename, the "new File()" constructor will add it for you. Second, it's bad style to put files in the top level of the SD card; it can get very cluttered that way. You should create an application-specific directory for your files. – Edward Falk Jan 11 '13 at 22:37
  • Are you sure you just dont have permission to access the SDCard? – IAmGroot Jan 11 '13 at 22:40
  • I added logcat. And yes, I have a directory for the file, but when I had errors the first time, I tried moving to root. – user1971343 Jan 11 '13 at 22:41
  • Looks like the Highgui library is calling into a native library that's not present on your system. There's probably a required .so file that's missing. It's also likely that you won't be able to install it on your device. Are there any known instances of anybody ever getting Highgui to work on Android? – Edward Falk Jan 11 '13 at 22:45

1 Answers1

3

This has nothing to do with reading of the bitmap file. UnsatisfiedLinkError means it wasn't able to find the shared objects (.so files) implementing that class. It means something is wrong with your project configuration. Did you copy the required files to libs/armeabi, libs/armeabi-v7a and libs/x86?

Also see:

Android for OpenCV - error opening trace file, UnsatisfiedLinkError

Community
  • 1
  • 1
kichik
  • 33,220
  • 7
  • 94
  • 114
  • I didn't. I can only see android-support-v4.jar in there. No armeabi armeabi-v7a or x86. What are the "required files" I need to add? – user1971343 Jan 11 '13 at 23:03
  • They should be in the SDK you download. Follow the instructions on http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/O4A_SDK.html – kichik Jan 11 '13 at 23:05
  • I found armeabi-v7a x86 and mips but not armeabi. I added them but get the same error. Anything else I can try? – user1971343 Jan 11 '13 at 23:34
  • Download the correct SDK and get the `armeabi` version too from `sdk/native/libs`. I have no better tip than to follow that tutorial. It has step by step instructions that result in a working project. If that fails, add a list of all the files in your project so it can be verified. – kichik Jan 12 '13 at 00:41
  • I'm using v2.2 and couldn't find those files. So I tried v2.4.3 and the files were there but I get the same error. – user1971343 Jan 13 '13 at 17:51
  • Did you follow the entire tutorial? Did you try the first link I posted? – kichik Jan 13 '13 at 18:27
  • Yes I made a new workspace with that sdk and the imported by program then copied the files from native/libs. – user1971343 Jan 13 '13 at 23:02