有一个示例可以删除官方SDK中的视频帧。 主要代码如下:
@SuppressLint("SimpleDateFormat")
@Override
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() +
"/sample_picture_" + currentDateandTime + ".jpg";
mOpenCvCameraView.takePicture(fileName);
Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show();
return false;
}
现在我想把它改成一个可以自动输出视频帧的样本。我已经评论了上面的代码并更改了名为的方法 onManagerConnected。更改如下:
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();
String filename = Environment.getExternalStorageDirectory().getPath()+"test"+".jpg";
mOpenCvCameraView.takePicture(filename);
Log.i(TAG, filename);
// mOpenCvCameraView.setOnTouchListener(Tutorial3Activity.this);
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};
然后抛出一个nullpointException,显示var" mPictureFileName"和" mCamera"是空的。
public void takePicture(final String fileName) {
Log.i(TAG, "Taking picture");
mPictureFileName = fileName;
// Postview and jpeg are sent in the same buffers if the queue is not empty when performing a capture.
// Clear up buffers to avoid mCamera.takePicture to be stuck because of a memory issue
mCamera.setPreviewCallback(null);
// PictureCallback is implemented by the current class
mCamera.takePicture(null, null, this);
}
反正!
感谢您的回答!
答案 0 :(得分:0)
当视图打开时,相机未启动。因此,您无法在“启动”方法中剪切视频。 我将这些代码移到方法“onCameraFrame”。完成!
public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
String filename = null;
filename = Environment.getExternalStorageDirectory().getPath()+"/test"+i+".jpg";
mOpenCvCameraView.takePicture(filename);
Log.d("camera", filename);
return inputFrame.rgba();
}