1

I'm getting frame by frame with startImageStream, but I would like to avoid doing the conversion from YUV420 to RGB with C++ code (using ffi), which adds a substantial overhead. therefore I have used the imageFormatGroup while instantiating the controller (link).

The ImageFormatGroup describes the output of the raw image format (link):

cameraController = CameraController(cameras[0],
                                    ResolutionPreset.medium,
                                    imageFormatGroup: ImageFormatGroup.bgra8888);

BUT still I keep getting yuv420 format although I have passed ImageFormatGroup.bgra8888 (I'm using android).

according to this wiki - RGBA8888 I should get three planes of the exact size, but I keep getting:

plane0.bytes.length - 368592

plane1.bytes.length - 184271

plane2.bytes.length - 184271

Eventually I'd like to pass the frame from flutter to C++ for processing the RGB image with OpenCV.

I also have tried ImageFormatGroup.jpeg, which holds a single plane.

Can someone suggest a way of using CameraController.startImageStream(...)

to get "out of the box" a frame in a RGB format?

JammingThebBits
  • 732
  • 11
  • 31
  • Not all devices (and this is an understatement) support RGB camera streams, that's why people are busy with different color conversion techniques. If you need it in OpenCV and don't care about the slight color distortion between CCIR 601 and JFIF spaces, you can use `cvtColor(CV_YUV420sp2BGR)`. If this is unacceptable, you should reshuffle the chroma pixels of input YUV image and call CV_YCrCb2BGR transform, or use some other color convertor, e.g. libyuv. – Alex Cohn Jun 17 '21 at 14:28
  • In some cases, you can employ renderscript, but remember that the [builtin rsYuvToRGBA_uchar4 script](https://stackoverflow.com/a/43642425/192373) assumes CCIR 601 color space. Now, about the YUV planes: most often, the planes **1** and **2** actually overlap (note that they have pixel stride of 2), so in the end, planes **0** and **1** together provide the NV21 image. – Alex Cohn Jun 17 '21 at 14:38

0 Answers0