Ask Your Question
3

Static Initialization of Android Application makes it a lot slower

asked 2014-04-11 05:52:00 -0600

I have made a simple application using Android OpenCV. It also has a jni part. Everything is working fine. Now, I wanted to initialize it statically so I followed instructions and it seemed to work.

PROBLEM:

The Application works really slow. I'm capturing image from camera using CameraBridgeViewBase. I process it in C++ using jni and show the processed image on another adjacent window (ImageView). When I was using OpenCV's Android manager to link the application, it was working at 10 FPS. But when I linked it statically, it slowed down to 2 FPS. I changed to native camera from java camera which was more slower. (native camera seems slower even when linked to opencv manager). I'm testing this on NEXUS 4 with Android 4.4 and using OpenCV 2.4.8.

Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=on
OPENCV_INSTALL_MODULES:=on
include /home/jay/Android_OpenCV/OpenCV-2.4.8-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := light_exposure
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl
include $(BUILD_SHARED_LIBRARY)

Application.mk:

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a
APP_PLATFORM := android-9

Java Code:

public class ExposureActivity extends Activity implements CvCameraViewListener2 {

    private static final String TAG = "exposure::ExposureActivity";
    private CameraBridgeViewBase mOpenCvCameraView;
    private int tFrame=0;
    // other code

    static {
     if(!OpenCVLoader.initDebug())
     {
             Log.i(TAG, "Static linking failed");
     }
     else
         {
               System.loadLibrary("opencv_java");
               System.loadLibrary("light_exposure"); // jni module  
               Log.i(TAG, "static linking success");
         }
    }

     // other code

     @Override
     public void onResume()
     {
         super.onResume();
         //OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback);
     }

     // When I press start button in the application
     public void onClickStartButton(View view){
         mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.opencv_part_java_surface_view);
         mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
         mOpenCvCameraView.setCvCameraViewListener(this);
         mOpenCvCameraView.enableView();
     }

    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
        tFrames ++;
        Log.i(TAG, "frame number " + String.valueOf(tFrames));
        mRgba = inputFrame.rgba();
        processForExposure(mRgba.getNativeObjAddr(), mDis.getNativeObjAddr()); // native function

        int w = mDis.width();
        int h = mDis.height();
        Bitmap.Config conf = Bitmap.Config.ARGB_8888;
        Bitmap retBmp = Bitmap.createBitmap(w, h, conf);

        Utils.matToBitmap(mDis, retBmp);

        Message msg = new Message();
        msg.obj = retBmp;
        mHandler.sendMessage(msg); // to set the bitmap image in ImageView

        return mRgba;
   }

}

Am I missing something? Why is the performance so slow? Also, java_camera seems to drop frames. image description

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-09-09 02:23:53 -0600

Money gravatar image

Hi, Did you get this issue fixed, I met this same issue now.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-11 05:52:00 -0600

Seen: 1,416 times

Last updated: Sep 09 '14