I am trying to create an application that can determine the number of faces in a shot taken with a device camera. So far, the code that I have is shown below. Exploring the question here, I think this may be a problem when the image resolution is too poor for FaceDetector, but if so, I'm not sure how to fix this problem. If this is not so, then I do not understand what happened. Any help is much appreciated!
public class CrowdDetection extends Activity { ImageView display; ImageView pic; Bitmap image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_crowd_detection); display = (ImageView) findViewById(R.id.imageView2); Button takePicture = (Button) findViewById(R.id.button1); takePicture.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, 0); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data){ super.onActivityResult(requestCode, resultCode, data); setContentView(R.layout.detect_faces); pic = (ImageView) findViewById(R.id.imageView1); image = (Bitmap) data.getExtras().get("data"); image = BitmapFactory.decodeFile(data.getData().getPath()); pic.setImageBitmap(image); Button detect = (Button) findViewById(R.id.button2); detect.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ detectFaces(); } }); } private void detectFaces() { setContentView(R.layout.display_crowd); 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); pic2.setImageBitmap(image); int facesFound = detector.findFaces(image, faces); TextView result = (TextView) findViewById(R.id.textView3); if(facesFound>5){ result.setText("There are " + facesFound + " faces in this picture, therefore you have a crowd!"); } else{ result.setText("There are only " + facesFound + " faces in this picture, therefore you do not have a crowd!"); } } @Override public boolean onCreateOptionsMenu(Menu menu) {
Thanks for the help in advance!
source share