I'm trying to do some work on porting a Visual-Inertial State Estimator to Android Platform using Camera and Sensors (Gyroscope & Accelerometer) of Android.
But after I finished it, I just found out something really disappointed me in the result, which has been confirmed to be the timestamp of picture captured by Camera is not accurate.
To simplify this problem, I'm now trying to save all pictures captured by camera of Android to files, with another csv file containing all picture filenames and their corresponding timestamps.
Below is part of my code and what I have done for this problem:
Connect a camera with a SurfaceTexture, which I used for eliminating the time cosuming for showing the picture on screen(which may be useless though), and add a
CallbackWithBuffer
tothis
, which will callonPreviewFrame
when new picture is capturedmCamera.setPreviewTexture(surfaceTexture); int buffersize = mFrameWidth * mFrameHeight * ImageFormat.getBitsPerPixel(previewFormat) * 8; previewBuffer = new byte[buffersize]; mCamera.addCallbackBuffer(previewBuffer); mCamera.setPreviewCallbackWithBuffer(this); mCamera.startPreview();
onPreviewFrame, put all pictures and timestamp to a buffer, and use another thread to save pictures.
outImage
is that csv file containing all picture filenames and their corresponding timestamps, and the real process for saving picture is in another process. The first line is where I get the timestamp of the picture captured by cameralong realTime = SystemClock.elapsedRealtimeNanos(); String fileName = "picture_" + realTime + ".jpg"; outImage.println(realTime + "," + fileName); synchronized (buffer) { buffer.add(new Pair<String, byte[]>(fileName, data)); } camera.addCallbackBuffer(previewBuffer);
Could you kindly please help me out of this problem?