Get the data of each android.hardware.camera2 frame before it is displayed on the surfacetexture

In my android app, I need to get each frame returned by android.hardware.camera2, do some processing on its data, and only then render it onto the surfacetexture. This question is similar to mine, but it didn't work for me: Processing camera preview data using Android L and Camera2 API

I tried to get the frame from here (as suggested in the answer to the question):

private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
            = new ImageReader.OnImageAvailableListener() {

        @Override
        public void onImageAvailable(ImageReader reader) {

            Log.d("Img", "onImageAvailable");
            mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));
        }

    };

      

This was not helpful as the callback is only called after the user has captured the image. And I don’t need this only when capturing, I need to receive every frame that is sent to the surface of the camera. Interestingly, maybe the farm can be taken here (from the texture):

public void onSurfaceTextureUpdated(SurfaceTexture texture) {
            Log.d("Img", "onSurfaceTextureUpdated");

        }

      

If so, how?

I am using this sample from google as a basis:

https://github.com/googlesamples/android-Camera2Basic

+3


source to share


2 answers


Yes, you can definitely get the buffer from the camera callback. You can provide your own texture and update it whenever you want, and even change the pixel data for that buffer.

You must hit the "original" SurfaceTexture (as specified in createCaptureSession ()), otherwise it will interfere with your filtered / modified buffers.



The main caveat to this approach is that you are now responsible for creating the pseudo-preview buffers in a timely manner.

0


source


I want to do some image processing. I was looking into the code at github.com/googlesamples/android-Camera2Basic and I believe that mCaptureSession redirects the camera pipeline to the preview texture and to the capture, but not both at the same time. The preview texture is "updated" with mCaptureSession.setRepeatingRequest and the mOnImageAvailableListener is called when "capture" is triggered on captureStillPicture (), but if you turn off the "preview texture" and you set a Repeating Request with the same builder as the "preview texture" view 'should try to call mOnImageAvailableListener, it just won't work. Has anyone else worked on this? Any enlightenment?



0


source







All Articles