Mohammad Elsayed
Mohammad Elsayed

Reputation: 2066

MlKit SelfieSegmentation with Android Camera2 and ImageReader

I am trying to get mask using the SelfieSegmentation api according to this link, my app uses camera2 and therefore, I don't have the ImageAnalysis use-case, instead, I have ImageReader which works fine, it give MediaImages which I can pass to the Segmenter, the issue is that ImageReader has the issue of maxImages (30) has already been acquired, call #close before acquiring more I don't know how to handle that, I searched everywhere, I tried to find alternatives for ImageReader even, I tried to make the image as light as possible by using the lowest possible resolution with no luck, the only difference it makes is that it give more time before the error happens.

Upvotes: 0

Views: 88

Answers (1)

Eddy Talvala
Eddy Talvala

Reputation: 18097

You need to call Image.close() when you're done using a given image buffer. So after the segmenter has completed its processing for each frame, presumably.

The memory underlying each Image is a shared buffer that the camera hardware, service, and your app all can access. So you need to signal the system the buffer can be reused for a new camera frame.

If you don't, eventually you run out buffers to fill and the system grinds to a halt and you get errors when you try to get another buffer.

Upvotes: 1

Related Questions