exception using opencv and jni in android project

asked 2014-05-10 15:35:38 -0600

atena_2019 gravatar image

i am working on a lip reading application in android. i am using openCV and jni for my project. i want to use openCV native camera, but when i run my code, i get this exception:

E/cv::error()(13512): OpenCV Error: Assertion failed (src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols) in void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean), file /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp, line 97
E/org.opencv.android.Utils(13512): nMatToBitmap catched cv::Exception: /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)
E/CameraBridge(13512): Mat type: Mat [ 352*288*CV_8UC4, isCont=true, isSubmat=false, nativeObj=0x5a4132a8, dataAddr=0x5f4c4010 ]
E/CameraBridge(13512): Bitmap type: 352*288
E/CameraBridge(13512): Utils.matToBitmap() throws an exception: /home/reports/ci/slave/50-SDK/opencv/modules/java/generator/src/cpp/utils.cpp:97: error: (-215) src.dims == 2 && info.height == (uint32_t)src.rows && info.width == (uint32_t)src.cols in function void Java_org_opencv_android_Utils_nMatToBitmap2(JNIEnv*, jclass, jlong, jobject, jboolean)

below is my code:

private BaseLoaderCallback  loaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
    switch (status) {
    case LoaderCallbackInterface.SUCCESS:
    {
        Log.i("adi", "OpenCV loaded successfully");

        // Load native library after(!) OpenCV initialization

        try
        {
            System.loadLibrary("feature_extractor");
            Log.i("adi" , " Success System.loadLibrary(\"feature_extractor\")");

        }

        catch(Exception ex){
            Log.i("adi" , " Exception System.loadLibrary(\"feature_extractor\")");

            ex.printStackTrace();
        }


        try {
            // load cascade file from application resources
            InputStream is = getResources().openRawResource(R.raw.haarcascade_mcs_mouth);
            File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
            cascadeFile = new File(cascadeDir, "haarcascade_mcs_mouth.xml");
            FileOutputStream os = new FileOutputStream(cascadeFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = is.read(buffer)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            is.close();
            os.close();

            //openCvCameraView.setMaxFrameSize(800, 800);
            fe = new FeatureExtractor(cascadeFile.getAbsolutePath(), openCvCameraView.getHeight(), openCvCameraView.getWidth());
            cascadeFile.delete();
        } catch (IOException e) {

            Log.e("adi", "Failed to load cascade. Exception thrown: " + e);
        }

        openCvCameraView.enableView();
    } break;
    default:
    {
        super.onManagerConnected(status);
    } break;
    }
}

};

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

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i("adi", "called onCreate");
    super.onCreate(savedInstanceState);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    setContentView(R.layout.main);



openCvCameraView = (CameraBridgeViewBase) findViewById(R.id.lip_reading_surface_view);
openCvCameraView.setCvCameraViewListener(this);
client = AndroidHttpClient.newInstance("lipreading-android");
tts = new TextToSpeech(this, this);
preferences = getPreferences(MODE_PRIVATE);
isTrainingMode = preferences.getBoolean(getString(R.string.trainingModePref), false);
uri = preferences.getString(getString(R.string.serverPref), getString(R.string.serverDef));
settingsFragment = new SettingsFragment().setContext(this);
output = (TextView) findViewById(R.id.output);
recordButton = (ImageButton) findViewById(R.id.recordButton);       
recordButton.setOnClickListener(
        new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onRecordButtonPressed();
            }
        });

and here is my FeatureExtractor.java class definition:

public class FeatureExtractor {
private static native long nativeCreateObject(String cascadeName, int w, int h);
private static native void nativeDestroyObject(long thiz);
private static native void nativeDetect(long thiz, long grayImage, long rgbaImage, int[]     points);

 public FeatureExtractor(String cascadeName, int w ...
(more)
edit retag flag offensive close merge delete

Comments

oh, please cut that down to some minimal example.

(else anyone will just shudder and move away...)

berak gravatar imageberak ( 2014-05-10 15:47:20 -0600 )edit