Java的OpenCV的 - 而conevrting位图太错误位图、错误、Java、OpenCV

2023-09-07 02:23:14 作者:把我掐死算了

我使用的Java OpenCV的,我尝试加载一张照片,在它运行的模板匹配。 模板匹配方法处理垫的对象,所以我需要加载图像,并将其转换成垫。

I am using Java openCV, and i try to load a photo and run the template matching over it. The template matching method deals with Mat objects, so i need to load the images and convert them into Mat.

我的方式做到这一点是:

The way i do it is:

Bitmap i = BitmapFactory.decodeFile("/sdcard/TVguide/Detection/detected.jpg");
image = Utils.bitmapToMat(i);

这样我加载从我的Andr​​oid SD卡中的照片,并试图将其转换成使用OpenCV的方法bitmapToMat垫目标。 的问题是,在转换时,应用程序崩溃。

This way i load a photo from my android SD card, and try to convert it into Mat object using the openCV method bitmapToMat. The problem is that on the conversion, the application crashes.

下面是LogCat中:

Here is the LogCat:

            03-14 15:15:57.636: W/dalvikvm(1059): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lorg/opencv/android/Utils;
            03-14 15:15:57.636: D/AndroidRuntime(1059): Shutting down VM
            03-14 15:15:57.636: W/dalvikvm(1059): threadid=1: thread exiting with uncaught exception (group=0x40015578)
            03-14 15:15:57.640: E/AndroidRuntime(1059): FATAL EXCEPTION: main
            03-14 15:15:57.640: E/AndroidRuntime(1059): java.lang.ExceptionInInitializerError
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at com.marakana.Preview$3.onPictureTaken(Preview.java:191)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at android.hardware.Camera$EventHandler.handleMessage(Camera.java:565)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at android.os.Handler.dispatchMessage(Handler.java:99)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at android.os.Looper.loop(Looper.java:123)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at android.app.ActivityThread.main(ActivityThread.java:3687)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at java.lang.reflect.Method.invokeNative(Native Method)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at java.lang.reflect.Method.invoke(Method.java:507)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at dalvik.system.NativeStart.main(Native Method)
            03-14 15:15:57.640: E/AndroidRuntime(1059): Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv_java: findLibrary returned null
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at java.lang.Runtime.loadLibrary(Runtime.java:429)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at java.lang.System.loadLibrary(System.java:554)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     at org.opencv.android.Utils.<clinit>(Utils.java:86)
            03-14 15:15:57.640: E/AndroidRuntime(1059):     ... 10 more
            03-14 15:16:03.472: I/Process(1059): Sending signal. PID: 1059 SIG: 9

我不明白,如果我做错了什么,或者它仅仅是一个越野车的OpenCV。

I can't understand if i am doing something wrong or it is just a buggy openCV.

谢谢 的Eyal

推荐答案

您需要将您的位​​图转换为RGBA格式为:

You need to convert your bitmap to the RGBA format:

Bitmap bmp32 = i.copy(Bitmap.Config.ARGB_8888, true);

其实这是对Android的OpenCV的用户群讨论最多的问题: https://开头groups.google.com/group/android-opencv/

有关此问题的解决方法是在OpenCV的树干已经上市,并会被列入到的OpenCV的下一个版本。

The fix for this problem is already available in OpenCV trunk and will be included into the next release of OpenCV.

您也可以使用OpenCV的API读取图像:

Also you can read image using the OpenCV API:

Mat image = Highgui.imread("/sdcard/TVguide/Detection/detected.jpg");