3

In my android application, I need to get each frame that is returned by the android.hardware.camera2, make some processing with it's data and only then display it on the surfacetexture. This question is similar to mine, but it didn't help me: Camera preview image data processing with Android L and Camera2 API

I've 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 useful, as the callback is called only after the user performed capture of image. And I don't need it only on capture, I need to get each frame that is sent to the camerapreview surface. I wonder, maybe the farme can be taken here (from the texture):

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

        }

If yes, how?

I'm using this sample from google, as a basis:

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

Community
  • 1
  • 1
user2924714
  • 1,918
  • 1
  • 19
  • 26
  • SurfaceTexture converts the camera frame to an OpenGL ES texture, which is then rendered on the preview Surface. You can render that to an off-screen pbuffer and read the pixels out with `glReadPixels()`. Not sure if that's the best way to do it in Camera2. – fadden Jul 05 '15 at 15:23
  • Thank you. I will try. But probably there is a way to get it directly from the camera callback. – user2924714 Jul 05 '15 at 15:38

2 Answers2

0

Yes, you definitely can get the buffer from camera callback. You can provide your own texture and update it when you wish, and even modify the pixel data for this buffer.

You should push the 'original' SurfaceTexture (specified in createCaptureSession()) off screen, otherwise it will interfere with your filtered/modified buffers.

The main caveat of this approach is that it is now your responsibility to produce pseudo-preview buffers timely.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
0

I want to do some image processing too. I've been studding the code on github.com/googlesamples/android-Camera2Basic, and I believe that mCaptureSession redirects the camera's pipeline to the preview texture and to the capture itself but not both at same time. The preview texture is 'refreshed' by mCaptureSession.setRepeatingRequest and the mOnImageAvailableListener is called when 'capture' is fired on captureStillPicture(), but if you disable the 'preview texture' and you set Repeating Request with the same builder that the 'preview texture' has to try call mOnImageAvailableListener it just won't work. Has anyone else been working on it? Any enlightenment?

Rinaldi Segecin
  • 449
  • 8
  • 23