2

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:

  1. 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 to this, which will call onPreviewFrame when new picture is captured

    mCamera.setPreviewTexture(surfaceTexture);
    int buffersize = mFrameWidth * mFrameHeight
                    * ImageFormat.getBitsPerPixel(previewFormat) * 8;
    previewBuffer = new byte[buffersize];
    mCamera.addCallbackBuffer(previewBuffer);
    mCamera.setPreviewCallbackWithBuffer(this);
    mCamera.startPreview();
    
  2. 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 camera

    long 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?

Tommy Han
  • 21
  • 2

0 Answers0