Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to detect face using FaceDetector in android
    primarykey
    data
    text
    <p>I need to detect the user face and also compare the face to authenticate my application,for that I used FaceDetector API to detect the user face.</p> <p>When i run my code it works without any defects.But it gives detected faces count as Zero.</p> <pre><code> public class AndroidFaceDetectorActivity extends Activity { private static final int TAKE_PICTURE_CODE = 100; private static final int MAX_FACES = 5; private Bitmap cameraBitmap = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ((Button)findViewById(R.id.take_picture)).setOnClickListener(btnClick); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(TAKE_PICTURE_CODE == requestCode){ processCameraImage(data); } } private void openCamera(){ Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(intent, TAKE_PICTURE_CODE); } private void processCameraImage(Intent intent){ setContentView(R.layout.detectlayout); ((Button)findViewById(R.id.detect_face)).setOnClickListener(btnClick); ImageView imageView = (ImageView)findViewById(R.id.image_view); cameraBitmap = (Bitmap)intent.getExtras().get("data"); imageView.setImageBitmap(cameraBitmap); } private void detectFaces(){ if(null != cameraBitmap){ Log.d("FACE_RECOGNITION","CHECK"); int width = cameraBitmap.getWidth(); int height = cameraBitmap.getHeight(); FaceDetector detector = new FaceDetector(width, height,AndroidFaceDetectorActivity.MAX_FACES); Face[] faces = new Face[AndroidFaceDetectorActivity.MAX_FACES]; Bitmap bitmap565 = Bitmap.createBitmap(width, height, Config.RGB_565); Paint ditherPaint = new Paint(); Paint drawPaint = new Paint(); ditherPaint.setDither(true); drawPaint.setColor(Color.RED); drawPaint.setStyle(Paint.Style.STROKE); drawPaint.setStrokeWidth(2); Canvas canvas = new Canvas(); canvas.setBitmap(bitmap565); canvas.drawBitmap(cameraBitmap, 0, 0, ditherPaint); int facesFound = detector.findFaces(bitmap565, faces); PointF midPoint = new PointF(); float eyeDistance = 0.0f; float confidence = 0.0f; Log.i("FaceDetector", "Number of faces found: " + facesFound); if(facesFound &gt; 0) { for(int index=0; index&lt;facesFound; ++index){ faces[index].getMidPoint(midPoint); eyeDistance = faces[index].eyesDistance(); confidence = faces[index].confidence(); Log.i("FaceDetector", "Confidence: " + confidence + ", Eye distance: " + eyeDistance + ", Mid Point: (" + midPoint.x + ", " + midPoint.y + ")"); canvas.drawRect((int)midPoint.x - eyeDistance , (int)midPoint.y - eyeDistance , (int)midPoint.x + eyeDistance, (int)midPoint.y + eyeDistance, drawPaint); } } String filepath = Environment.getExternalStorageDirectory() + "/facedetect" + System.currentTimeMillis() + ".jpg"; try { FileOutputStream fos = new FileOutputStream(filepath); bitmap565.compress(CompressFormat.JPEG, 90, fos); fos.flush(); fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } ImageView imageView = (ImageView)findViewById(R.id.image_view); imageView.setImageBitmap(bitmap565); } } private View.OnClickListener btnClick = new View.OnClickListener() { //@Override public void onClick(View v) { switch(v.getId()){ case R.id.take_picture: openCamera(); break; case R.id.detect_face: detectFaces(); break; } } }; } </code></pre> <p>What i did wrong?</p> <p>or</p> <p>Is any other way to do that?</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload