Home » Android » Android FaceDetector not finding any faces…findFace() returns 0 every time

Android FaceDetector not finding any faces…findFace() returns 0 every time

Posted by: admin June 15, 2020 Leave a comment


I am trying to build an app that can detect the number of faces in a picture taken by the devices camera. So far, the code I have is shown below. From researching the question on here, I think it may be an issue with the picture’s resolution being too poor for the FaceDetector, but if that is the case, I am not sure how to fix that problem. If that’s not the case, then I’m at a loss at what is wrong. Any help is much appreciated!

public class CrowdDetection extends Activity {

ImageView display;
ImageView pic;
Bitmap image;

protected void onCreate(Bundle savedInstanceState) {

    display = (ImageView) findViewById(R.id.imageView2);

    Button takePicture = (Button) findViewById(R.id.button1);
    takePicture.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            startActivityForResult(intent, 0);

protected void onActivityResult(int requestCode, int resultCode, Intent data){

    super.onActivityResult(requestCode, resultCode, data);


    pic = (ImageView) findViewById(R.id.imageView1);

    image = (Bitmap) data.getExtras().get("data");
    image = BitmapFactory.decodeFile(data.getData().getPath());

    Button detect = (Button) findViewById(R.id.button2);
    detect.setOnClickListener(new OnClickListener(){

        public void onClick(View v){

private void detectFaces() {


    int h = image.getHeight();
    int w = image.getWidth();
    int max = 10;

    FaceDetector detector = new FaceDetector(w, h, max);
    Face[] faces = new Face[max];

    ImageView pic2 = (ImageView) findViewById(R.id.imageView3);

    int facesFound = detector.findFaces(image, faces);

    TextView result = (TextView) findViewById(R.id.textView3);

        result.setText("There are " + facesFound + " faces in this picture, therefore you have a crowd!");
        result.setText("There are only " + facesFound + " faces in this picture, therefore you do not have a crowd!");


public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.crowd_detection, menu);
    return true;


Thanks for the help in advance!

How to&Answers:

The reason you can’t detect any faces is you need to convert your bitmap to RGB 565.

Use this to convert your bitmap to RGB 565

BitmapFactory.Options bitmapFatoryOptions=new BitmapFactory.Options();
image=BitmapFactory.decodeResource(getResources(),        R.drawable.image,bitmapFatoryOptions);