Ask Your Question

Static Initialization of Android Application makes it a lot slower

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

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.


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.

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

include /home/jay/Android_OpenCV/OpenCV-2.4.8-android-sdk/sdk/native/jni/

LOCAL_MODULE    := light_exposure
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl

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 {
             Log.i(TAG, "Static linking failed");
               System.loadLibrary("light_exposure"); // jni module  
               Log.i(TAG, "static linking success");

     // other code

     public void 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(;

    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

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

Money gravatar image

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

edit flag offensive delete link more

Question Tools


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

Seen: 1,290 times

Last updated: Sep 09 '14