OpenCV Android 拍摄静止图像

OpenCV4Android take still images

我正在使用下面的代码通过 OnTouch 事件捕获静止图像,但我的应用程序在我触摸时立即崩溃:

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;
}

我是 opencv 新手。感谢您的帮助!

终于找到问题了! mRgba 未在 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;
}