OpenCV Android - 将可绘制图像加载到Mat

时间:2015-04-30 06:28:58

标签: java android opencv image-processing

我已经看到here关于显示图片的答案,以及here关于Android中的上下文的答案,但我仍然很困惑在我的程序中使用它。这是我的程序的样子:

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

我运行程序但是会弹出这些错误:

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)

我尝试将上下文更改为MainActivity.this,但它仍然是错误的。我看到了Mat错误,因此我尝试将声明更改为Mat drawImage = new Mat()Mat drawImage = new Mat(60, 60, CvType.CV_8UC3),但没有任何运气。

我使用上下文错了吗?或者还有其他什么?任何建议都会有帮助。谢谢。

0 个答案:

没有答案