我是Android和图像处理的新手。到目前为止我所做的是拥有一个精彩的视频(运行正常)
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
Mat imgOriginal = inputFrame.rgba();
Mat imgCanny = new Mat();
Imgproc.Canny(imgOriginal, imgCanny, 70, 100);
return (imgCanny);
}
并在触摸屏幕时捕获图像。然后将图像存储到目录中(这也正常运行)
@SuppressLint("SimpleDateFormat")
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.i(TAG,"onTouch event");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String currentDateAndTime = simpleDateFormat.format(new Date());
//String fileName = Environment.getExternalStorageDirectory().getPath() + "/sample_picture_" + currentDateandTime + ".jpg";
//String test = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath();
final String fileName = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/sample_picture_" + currentDateAndTime + ".jpg";
mOpenCvCameraView.takePicture(fileName);
Toast.makeText(this, fileName + " saved", Toast.LENGTH_LONG).show();
return false;
}
我想要实现的目标是:
在一些计时器或延迟一秒后从视频中捕获图像并将其存储在目录中。我不知道该怎么做。我通过复制Ontouch()中的代码并为mOpenCvCameraView.takePicture(fileName)放置了一个计时器,在OnCameraFrame中尝试了Timer和倒数计时器; 但他们并没有为我工作。
编辑:我正在尝试做类似这样的事情,但在我的情况下它不起作用。我希望在1秒后捕获图像而不是OnTouch事件。有什么建议吗?
new Timer().scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
String currentDateAndTime = simpleDateFormat.format(new Date());
final String fileName = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getPath() + "/sample_picture_" + currentDateAndTime + ".jpg";
mOpenCvCameraView.takePicture(fileName);
}
}, 0, 1000);