2017-05-29 27 views
0

,但我的应用程序,只要我碰崩溃:OpenCV4Android拍摄静止我使用下面的代码来捕获仍然使用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。感谢帮助!

回答

0

最后我发现了这个问题! 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; 
} 
相关问题