I'm trying to detect the status of an LED light using an android phone's camera. The camera app is using the onpreviewframe method to take each frame and using the luma part of the YUV file (each frame taken is saved in a buffer as a YUV file, the first width*height bytes of YUV are the luma part and include the grayscale of the corresponding pixels, I work with those bytes to make a decision).
Currently with each frame I calculate the grayscale mean and compare it with a threshold number to decide if the bit is an 0 or a 1; I'm creating the threshold number by getting the grayscale mean of the first 50 frames. This algorithm is too simple and weak to hold in different situations and I'm looking to make it more robust.
I have seen a few questions regarding my problem (**) but non of them asks for an actual algorithm which is what I'm looking for as I am new to image processing.
My questions -
What algorithms should I implement for a better decision making?
How (if needed) to create a more precise threshold number?
Are there any sources I can use (preferably in java)?
*The LED is fixed and the phone is handheld.
**OpenCV: Detect blinking lights in a video feed & openCV detect blinking lights