Android: Accessing hardware camera preview frame data without drawing them

后端 未结 2 950
忘掉有多难
忘掉有多难 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条回答
  • 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.

    0 讨论(0)
  • 2021-02-19 18:29

    There is no getting around having the SurfaceView for image preview. What you could do is delegate the responsibility of capturing the byte[] to the apps implementing your library which would allows them to use your library for not only images from the camera but allows images that have already been taken.

    0 讨论(0)
提交回复
热议问题