UnsatisfiedLinkError - 在Android中旋转摄像机图像数据(用于OpenCV,而不仅仅是在屏幕上显示)

时间:2015-03-19 23:32:05

标签: android image opencv rotation

我正在以纵向模式开发Android应用程序,我想将相机输出到屏幕上的2帧。

第一帧是相机的直线输出,方向错误。我可以通过使用这一行解决这个问题:

mCamera.setDisplayOrientation(90);

然而,对于第二帧,我想输出从C ++中的OpenCV函数渲染的内容。我无法正确旋转图像。我最近的尝试是使用Java中的OpenCV旋转,但是我得到了一个" UnsatisfiedLinkError",我已经发布了下面的日志。以下是我尝试用来旋转图片的代码(信用到:Rotate camera preview to Portrait Android OpenCV Camera):

        mYuv = new Mat(PreviewSizeHeight + PreviewSizeHeight/2, PreviewSizeWidth, CvType.CV_8UC1);
        mYuv.put(0, 0, arg0);
        Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGBA, 4);

以下是我使用上述代码的函数:

@Override
public void onPreviewFrame(byte[] arg0, Camera arg1) 
{


    // At preview mode, the frame data will push to here.
    if (imageFormat == ImageFormat.NV21)
    {
        mYuv = new Mat(PreviewSizeHeight + PreviewSizeHeight/2, PreviewSizeWidth, CvType.CV_8UC1);
        mYuv.put(0, 0, arg0);
        Imgproc.cvtColor(mYuv, mRgba, Imgproc.COLOR_YUV420sp2RGBA, 4);

        //We only accept the NV21(YUV420) format.
        if ( !bProcessing )
        {
            //FrameData = arg0;
            mHandler.post(DoImageProcessing);
        }
    }
}

这是我得到的错误:

    03-20 02:06:34.793: D/OpenCV/StaticHelper(13063): Trying to get library list
03-20 02:06:34.803: E/OpenCV/StaticHelper(13063): OpenCV error: Cannot load info library for OpenCV
03-20 02:06:34.803: D/OpenCV/StaticHelper(13063): Library list: ""
03-20 02:06:34.803: D/OpenCV/StaticHelper(13063): First attempt to load libs
03-20 02:06:34.803: D/OpenCV/StaticHelper(13063): Trying to init OpenCV libs
03-20 02:06:34.803: D/OpenCV/StaticHelper(13063): Trying to load library opencv_java
03-20 02:06:34.803: D/OpenCV/StaticHelper(13063): Cannot load library "opencv_java"
03-20 02:06:34.803: W/System.err(13063): java.lang.UnsatisfiedLinkError: Couldn't load opencv_java from loader dalvik.system.PathClassLoader[dexPath=/data/app/my.project.realtimeSpotDetection-102.apk,libraryPath=/data/app-lib/my.project.realtimeSpotDetection-102]: findLibrary returned null
03-20 02:06:34.803: W/System.err(13063):    at java.lang.Runtime.loadLibrary(Runtime.java:358)
03-20 02:06:34.803: W/System.err(13063):    at java.lang.System.loadLibrary(System.java:526)
03-20 02:06:34.803: W/System.err(13063):    at org.opencv.android.StaticHelper.loadLibrary(StaticHelper.java:64)
03-20 02:06:34.803: W/System.err(13063):    at org.opencv.android.StaticHelper.initOpenCVLibs(StaticHelper.java:95)
03-20 02:06:34.803: W/System.err(13063):    at org.opencv.android.StaticHelper.initOpenCV(StaticHelper.java:39)
03-20 02:06:34.803: W/System.err(13063):    at org.opencv.android.OpenCVLoader.initDebug(OpenCVLoader.java:56)
03-20 02:06:34.803: W/System.err(13063):    at my.project.realtimeSpotDetection.CameraPreview.<clinit>(CameraPreview.java:33)
03-20 02:06:34.803: W/System.err(13063):    at my.project.realtimeSpotDetection.realtimeSpotDetection.onCreate(realtimeSpotDetection.java:77)
03-20 02:06:34.803: W/System.err(13063):    at android.app.Activity.performCreate(Activity.java:5453)
03-20 02:06:34.803: W/System.err(13063):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
03-20 02:06:34.803: W/System.err(13063):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2377)
03-20 02:06:34.803: W/System.err(13063):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2471)
03-20 02:06:34.803: W/System.err(13063):    at android.app.ActivityThread.access$900(ActivityThread.java:175)
03-20 02:06:34.803: W/System.err(13063):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
03-20 02:06:34.803: W/System.err(13063):    at android.os.Handler.dispatchMessage(Handler.java:102)
03-20 02:06:34.803: W/System.err(13063):    at android.os.Looper.loop(Looper.java:146)
03-20 02:06:34.803: W/System.err(13063):    at android.app.ActivityThread.main(ActivityThread.java:5602)
03-20 02:06:34.803: W/System.err(13063):    at java.lang.reflect.Method.invokeNative(Native Method)
03-20 02:06:34.803: W/System.err(13063):    at java.lang.reflect.Method.invoke(Method.java:515)
03-20 02:06:34.803: W/System.err(13063):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
03-20 02:06:34.803: W/System.err(13063):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
03-20 02:06:34.803: W/System.err(13063):    at dalvik.system.NativeStart.main(Native Method)
03-20 02:06:34.803: D/OpenCV/StaticHelper(13063): First attempt to load libs fails
03-20 02:06:34.803: D/dalvikvm(13063): Trying to load lib /data/app-lib/my.project.realtimeSpotDetection-102/libImageProcessing.so 0x425086a8
03-20 02:06:34.808: W/linker(13063): libImageProcessing.so has text relocations. This is wasting memory and is a security risk. Please fix.
03-20 02:06:34.843: D/dalvikvm(13063): Added shared lib /data/app-lib/my.project.realtimeSpotDetection-102/libImageProcessing.so 0x425086a8
03-20 02:06:34.848: D/dalvikvm(13063): No JNI_OnLoad found in /data/app-lib/my.project.realtimeSpotDetection-102/libImageProcessing.so 0x425086a8, skipping init
03-20 02:06:35.038: D/libEGL(13063): loaded /system/lib/egl/libEGL_mali.so
03-20 02:06:35.083: D/libEGL(13063): loaded /system/lib/egl/libGLESv1_CM_mali.so
03-20 02:06:35.088: D/libEGL(13063): loaded /system/lib/egl/libGLESv2_mali.so
03-20 02:06:35.098: E/(13063): Device driver API match
03-20 02:06:35.098: E/(13063): Device driver API version: 29
03-20 02:06:35.098: E/(13063): User space API version: 29 
03-20 02:06:35.103: E/(13063): mali: REVISION=Linux-r3p2-01rel3 BUILD_DATE=Tue Jul 22 19:59:34 KST 2014 
03-20 02:06:35.233: D/OpenGLRenderer(13063): Enabling debug mode 0
03-20 02:06:36.068: I/dalvikvm-heap(13063): Grow heap (frag case) to 11.507MB for 1036816-byte allocation
03-20 02:06:36.143: W/dalvikvm(13063): No implementation found for native Lorg/opencv/core/Mat;.n_Mat:(III)J
03-20 02:06:36.143: D/AndroidRuntime(13063): Shutting down VM
03-20 02:06:36.143: W/dalvikvm(13063): threadid=1: thread exiting with uncaught exception (group=0x41c28c08)
03-20 02:06:36.163: E/AndroidRuntime(13063): FATAL EXCEPTION: main
03-20 02:06:36.163: E/AndroidRuntime(13063): Process: my.project.realtimeSpotDetection, PID: 13063
03-20 02:06:36.163: E/AndroidRuntime(13063): java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.core.Mat.n_Mat:(III)J
03-20 02:06:36.163: E/AndroidRuntime(13063):    at org.opencv.core.Mat.n_Mat(Native Method)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at org.opencv.core.Mat.<init>(Mat.java:477)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at my.project.realtimeSpotDetection.CameraPreview.onPreviewFrame(CameraPreview.java:77)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1016)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at android.os.Handler.dispatchMessage(Handler.java:102)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at android.os.Looper.loop(Looper.java:146)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at android.app.ActivityThread.main(ActivityThread.java:5602)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at java.lang.reflect.Method.invokeNative(Native Method)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at java.lang.reflect.Method.invoke(Method.java:515)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
03-20 02:06:36.163: E/AndroidRuntime(13063):    at dalvik.system.NativeStart.main(Native Method)
03-20 02:06:36.173: I/dalvikvm-heap(13063): Grow heap (frag case) to 12.525MB for 1036816-byte allocation

Android.mk文件:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_LIB_TYPE:=STATIC
OPENCV_CAMERA_MODULES := on 
OPENCV_INSTALL_MODULES := on

## include ../includeOpenCV.mk
OPENCV_MK_PATH:=/home/android/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
    #try to load OpenCV.mk from default install location
    include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk
else
    include $(OPENCV_MK_PATH)
endif

LOCAL_MODULE    := ImageProcessing
LOCAL_SRC_FILES := ImageProcessing.cpp
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

2 个答案:

答案 0 :(得分:0)

您的Android项目中的libs目录中的opencv_java共享库是什么?该库可以很容易地包含在你的eclipse项目中而不会导致编译错误,但它不会包含在你的.apk文件中,除非它在libs目录中

答案 1 :(得分:0)

所以当我编写本机代码并在C ++代码块中使用OpenCV时,我最终使用了另一种方法。 不是一个实际的解决方案,但Gary上面的最后评论可能是最接近解决方案的(你需要在手机上安装OpenCV应用程序,以便它可以访问这些库)