NativeCameraView in OpenCV4Android not working

asked 2013-05-18 08:00:50 -0500

sp_mic88 gravatar image

Good morning to all. I have tried to create a simple application for Android that uses opencv4android. This app simply should access through opencv to camera, and captures frames. I have followed this guide: http://docs.opencv.org/doc/tutorials/introduction/android_binary_package/dev_with_OCV_on_Android.html#application-development-with-async-initialization If I use org.opencv.android.JavaCameraView it works correctly, but if I want to use org.opencv.NativeCameraView, when I try to run the app, in my logcat I see:

 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r2.3.3.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.0.3.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.2.0.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.1.1.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r4.0.0.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r2.2.0.so
 05-18 13:00:16.979: E/OpenCV::camera(29894): ||libnative_camera_r3.0.1.so
 05-18 13:00:17.239: A/libc(29894): @@@ ABORTING: LIBC: HEAP MEMORY CORRUPTION IN dlmalloc
 05-18 13:00:17.249: A/libc(29894): Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 29894 (.videocamopencv)

Here my code:

---MAIN ACTIVITY:

package com.example.videocamopencv;

import org.opencv.android.BaseLoaderCallback;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
import org.opencv.android.LoaderCallbackInterface;
import org.opencv.android.NativeCameraView;
import org.opencv.android.OpenCVLoader;
import org.opencv.core.Mat;

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.SurfaceView;
import android.view.WindowManager;

public class MainActivity extends Activity implements CvCameraViewListener2{
private NativeCameraView mOpenCvCameraView;
private static final String TAG ="VideoCamera App :: ";

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");
                mOpenCvCameraView.enableView();
            } break;
            default:
            {
                super.onManagerConnected(status);
            } break;
        }
    }
};

public MainActivity(){
    Log.i(TAG, "Instantiated new " + this.getClass());
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "called onCreate");
     super.onCreate(savedInstanceState);
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
     setContentView(R.layout.activity_main);
     mOpenCvCameraView = (NativeCameraView) findViewById(R.id.HelloOpenCvView);
     mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
     mOpenCvCameraView.setCvCameraViewListener(this);

}

@Override
 public void onPause()
 {
     super.onPause();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }

 public void onDestroy() {
     super.onDestroy();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }

 public void onCameraViewStarted(int width, int height) {
 }

 public void onCameraViewStopped() {
 }

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

}

----MANIFEST.XML:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.videocamopencv"
android:versionCode="21"
android:versionName="2.1" >


<!-- android:icon="@drawable/ic_launcher" -->
<!-- android:label="@string/app_name" -->
<!-- android:theme="@style/AppTheme" -->
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
    <activity
        android:name="MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape"
        android:configChanges="keyboardHidden|orientation" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent ...
(more)
edit retag flag offensive close merge delete

Comments

I also get the same error running sample android image manipulations activity on sony experia

swamynathan gravatar imageswamynathan ( 2013-07-09 12:38:35 -0500 )edit