Android: Accessing hardware camera preview frame data without drawing them

后端 未结 2 931
忘掉有多难
忘掉有多难 2021-02-19 17:38

According to the android camera docs from the Java SDK side, the camera preview frames have to be supplied a (visible and active) surface to be drawn to in order to access the f

2条回答
  •  闹比i
    闹比i (楼主)
    2021-02-19 18:28

    I completely forgot I had this question up. 2 years and a couple of Android SDK versions later, we have a working system.

    We're using an extended SurfaceTexture, cameraSurface with a reference to the required camera. Using cameraSurface's SurfaceTexture, we call

    mCamera.setPreviewTexture(mSurfaceTexture);
    mCamera.startPreview();
    

    Then override the current active camera's previewCallback from your activity or wherever you need it.

    mCamera.setPreviewCallback(new PreviewCallback() {
    
         public void onPreviewFrame(final byte[] data, final Camera camera) {
             // Process the contents of byte for whatever you need
         }
    });
    

    This allows you to continuously process what the camera sees, rather than just having to go through stored images. Of course, this will be limited to your camera's preview resolution (which may be different from the still capture or video resolutions).

    If I get the time, I'll try to throw up a barebones working demo.

    Edit: The SDK I had linked to is no longer freely available. You can still request one via the BitGym contact page.

提交回复
热议问题