OpenCV4Android take still images

Issue

I am using the code below to capture still images using OnTouch event but my app crashes as soon as I touch:

public boolean onTouch(View v, MotionEvent event) {
    Log.i(TAG,"onTouch event");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
    String currentDateandTime = sdf.format(new Date());
    String fileName = Environment.getExternalStorageDirectory().getPath() +
            "/DCIM/app/sample_picture_" + currentDateandTime + ".jpg";
    Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show();
    Imgcodecs.imwrite(fileName,mRgba);
    return false;
}

I am new to opencv. Thanks for help!

Solution

Finally I found the problem! mRgba was not initialized in onCameraViewStarted().

public boolean onTouch(View v, MotionEvent event) {
    Log.i(TAG,"onTouch event");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
    String currentDateandTime = sdf.format(new Date());
    String fileName = Environment.getExternalStorageDirectory().getPath() +
            "/DCIM/app/sample_picture_" + currentDateandTime + ".jpg";
    Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show();
    Imgcodecs.imwrite(fileName, mIntermediateMat);
    return false;
}

Answered By – Ank

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published