I've seen the answers from here regarding displaying image, and here regarding context in Android, but I'm still confused to use it in my program. Here's what my program looks like:
Mat drawImage;
Bitmap drawBitmap;
try {
drawImage = Utils.loadResource(this, R.drawable.sample, Highgui.CV_LOAD_IMAGE_COLOR);
drawBitmap = Bitmap.createBitmap(drawImage.cols(), drawImage.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(drawImage, drawBitmap);
viewImage.setImageBitmap(drawBitmap);
} catch (IOException e) {
e.printStackTrace();
}
// sample is filename of target image
// viewImage is ImageView object in .xml
I run the program but these errors pop out:
04-30 13:04:57.965: E/AndroidRuntime(5425): FATAL EXCEPTION: main
04-30 13:04:57.965: E/AndroidRuntime(5425): java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.core.Mat.n_Mat:(III)J
04-30 13:04:57.965: E/AndroidRuntime(5425): at org.opencv.core.Mat.n_Mat(Native Method)
04-30 13:04:57.965: E/AndroidRuntime(5425): at org.opencv.core.Mat.<init>(Mat.java:477)
04-30 13:04:57.965: E/AndroidRuntime(5425): at org.opencv.android.Utils.loadResource(Utils.java:66)
04-30 13:04:57.965: E/AndroidRuntime(5425): at com.development.sign2.MainActivity.onCreate(MainActivity.java:146)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.app.Activity.performCreate(Activity.java:5047)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2056)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2117)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.app.ActivityThread.access$700(ActivityThread.java:134)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1218)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.os.Handler.dispatchMessage(Handler.java:99)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.os.Looper.loop(Looper.java:137)
04-30 13:04:57.965: E/AndroidRuntime(5425): at android.app.ActivityThread.main(ActivityThread.java:4867)
04-30 13:04:57.965: E/AndroidRuntime(5425): at java.lang.reflect.Method.invokeNative(Native Method)
04-30 13:04:57.965: E/AndroidRuntime(5425): at java.lang.reflect.Method.invoke(Method.java:511)
04-30 13:04:57.965: E/AndroidRuntime(5425): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1007)
04-30 13:04:57.965: E/AndroidRuntime(5425): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:774)
04-30 13:04:57.965: E/AndroidRuntime(5425): at dalvik.system.NativeStart.main(Native Method)
I tried to change the context into MainActivity.this
but it's still error. I saw the Mat
error one so I tried to change the declaration into Mat drawImage = new Mat()
and Mat drawImage = new Mat(60, 60, CvType.CV_8UC3)
but no luck whatsoever.
Am I using the context wrong? Or is there something else? Any advice will help. Thanks before.