Estimating the brightness of a YUV frame

428 Views Asked by At

I want to estimate the rough brightness of a frame that comes in as a camera preview frame, as below. I want the method to be quite fast.

public void onPreviewFrame(final byte[] bytes, Camera camera) {
  // calculate brightness
}

Is there a way to do it without converting to RGB? It also would be very good if there is a fast way to determine blurriness without using OpenCV.

1

There are 1 best solutions below

0
On

Ok, I figured it out myself:

                            long sumY = 0;
                            for (int j = 0, yp = 0; j < previewHeight; j++) {
                                for (int i = 0; i < previewWidth; i++, yp++) {
                                    int y = (0xff & ((int) bytes[yp]));
                                    if (y < 0) {
                                        y = 0;
                                    }

                                    sumY += y;
                                }
                            }
                            int bp = (int)sumY/(previewWidth * previewHeight);