Android: Do I use native library or not?

asked 2013-04-28 12:52:50 -0500

AAZZ gravatar image

I want to use the native libraries for an Android camera app. But I don't know whether my app uses native or java calls.

I've done what's described here at "Native/C++":

http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#dev-with-ocv-on-android

ndk-build did well without errors.

And in the Eclipse package explorer I get an obj directory with libnative_camera_rX.X.X.so (X.X.X stands for version, there are a lot of versions in the directory).

At project properties I added Library "OpenCV Library - 2.4.5". If I additionally check "Is Library" and try to start I get error "Android library projects cannot be laucnched.", if I uncheck "Is Library" I can run app.

a) Why that?

My Activity class implements CvCameraViewListener2 and I imported: import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame; and import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;

The app uses this methods:

static { if (!OpenCVLoader.initDebug()) { // Handle initialization error } } private CameraBridgeViewBase mOpenCvCameraView;

//onCreate: mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCvView); mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE); mOpenCvCameraView.setCvCameraViewListener(this);

//onPause/onDestroy if (mOpenCvCameraView != null) mOpenCvCameraView.disableView();

public Mat onCameraFrame(CvCameraViewFrame inputFrame) { return inputFrame.rgba(); }

But I don't know whether my app uses native calls or not.

Is the inputFrame.rgba() a native call of a C++ library method in libnative_camera_rX.X.X.so or is it a call of a java method of one of the imported libs import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame or import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2?

b) When it's not a native call: How to do a native call of method rgba(), something like this: System.nativecall(inputFrame.rgba(), libnative_camera_rX.X.X.so)?

c) When it is a native call: Why it's a lot slower than the standard camera app of my smartphone? I get 14 fps with return inputFrame.rgba() as sole method in onCameraFrame and screen picture is delayed when I pan the camera; with standard camera app ther is no delay.

edit retag flag offensive close merge delete