In the new API for working with the camera, you can set several recipients of the output stream from the camera, in the List<Surface> format. I need to process the stream from the camera frame by frame, for this I plan to use ImageReader as a recipient. I don’t understand how after all the manipulations in the OnImageAvailableListener.onImageAvailable() method I should see the changes on the screen?
1 answer
So, taking into account that as image receivers are transferred to Surface from different objects, you should do it another way - after image processing in OnImageAvailableListener.onImageAvailable() send the result to the Surface the View that is responsible for the preview. Initially, I used the format YUV_420_888
imageReader = ImageReader.newInstance(w, h, ImageFormat.YUV_420_888); because it is the fastest, but to bring it into a form suitable for editing turned out to be a no less creative task (unequivocally, processing the three channels in a cycle will not allow superimposing changes in real time). Decided to use ImageFormat.JPEG . I found very useful information here . However, using ImageFormat.JPEG too slow, and following one of the answers from the above link, other formats, even if they convert to Bitmap relatively quickly, may not be supported by some devices.
At the moment, I consider the method of solving the task I have described as not optimal. Perhaps on the diagram below you can find other entry points for interception and image processing, but I decided to look for alternatives.
OpenCV is suitable for my purposes. Despite the fact that the library is written in C ++, there is a ready-made solution in Java wrapper for Android.
