Issue
I am building a facial recognition system that i want to be automatic. I use live data to observe for change in bitmap from the camera preview, if the change has a face in it I check with users in my database and compare the facial features, if a match is found I record the time the user checked in. The problem is that that request is sent severally since the bitmap is still updating the live data that I am observing to trigger the comparison function. Is there a way to ensure that the function is called exactly once inside the observer? I would appreciate any help. Any clarifying questions are also welcome.
Solution
I finally found an answer for anyone who will encounter the same problem. It might seem hacky but suggestions on improvements are welcome. I used two live data objects but state flow will also work fine. I named one of them the trigger the other one the facial data. The trigger is a boolean live data object, inside its observer I check if the trigger value is true before starting comparison using the data from the facial data object. once the comparison starts I update the trigger to false. No other comparison will be done during this period, once the comparison is done I display the result and update the trigger back to true for further comparisons to be done. I also allow a five second delay for the user to get out of frame and another user to come into frame to avoid several entries for a single user.
Answered By - OtienoSamwel
Answer Checked By - Cary Denson (JavaFixing Admin)