Search code examples
androidandroid-cameraface-detection

Number of occurrence of a face between an interval of [40 cm; 80cm]


I tried to increase++ a number (i) each time the distance between the camera and my face is between 40 cm and 80 cm. Unfortunately when it happen the textview shows (The number of occurrence is: 50). Help me please

public void update(final Messsage msg) {    
    for(int i = 0; i < 50; ++i) {
        if (msg.getDistanceToFace() > 40 && msg.getDistanceToFace() < 80) {
            textView.setText("The number of occurrence is: " + i);
            textView.setTextColor(Color.GREEN);
        }
    }
}

Solution

  • you should probably add a break after you set the text, the way you coded it will set a text for all the iteration of i but you will only see the last one (50)