Android FaceDetector - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android FaceDetector class.

This code example shows how to use the following methods:findFaces
            Bitmap bmp = Bitmap.createBitmap(size.width, size.height, Bitmap.Config.ALPHA_8);
            Buffer src = ByteBuffer.wrap(data, 0, size.width * size.height);
            bmp.copyPixelsFromBuffer(src);
            if (mnLastWidth != size.width || mnLastHeight != size.height) {
                // recreate the face detector if the image size changed 
                mFd = new FaceDetector(size.width, size.height, 1);
            } 
            FaceDetector.Face[] faces = {null};
            int nFaces = mFd.findFaces(bmp, faces);
            if (nFaces != 0) {
                PointF midpoint = new PointF();
                faces[0].getMidPoint(midpoint);
                RectF rf = new RectF(midpoint.x - 10, midpoint.y - 10, midpoint.x + 10, midpoint.y + 10);
                mLogoView.setRect(rf);
            } 
        } 
    } 
} 
6
CodeRank
This code example shows how to use the following methods:
	Bitmap bmp;
	int numFaces = 0;
 
	public GoogleFaceDetection(Bitmap _bmp) {
		setBitmap(_bmp);
		faceDetector = new FaceDetector(bmp.getWidth(), bmp.getHeight(), MAX_FACES);
	 
	} 
 
	public int findFaces() { 
		 
		numFaces = faceDetector.findFaces(bmp, faces);
		return numFaces;
	} 
 
	public RectF[] getFaces() {
		RectF[] faceRects = new RectF[numFaces];
		 
	    if (numFaces > 0) {
	        for (int i = 0; i < faces.length; i++) {
5
CodeRank
This code example shows how to use the following methods:findFaces
	public boolean setFaces() 
	{ 
		if(bMap != null)
		{ 
			int k;
			arrayFaces = new FaceDetector(bMap.getWidth(), bMap.getHeight(), 1);
			 
			k = arrayFaces.findFaces(bMap, getAllFaces);
			 
			myFace = getAllFaces[0];
			 
			 
			if(myFace != null)
			{ 
				myFace.getMidPoint(eyesMidPoint);
				eyesDistance = myFace.eyesDistance();
			} 
			else 
			{ 
				return false; 
4
CodeRank
This code example shows how to use the following methods:findFaces
		finish();
	} 
	 
	private int faceCount(){ 
		FaceDetector.Face[] faces = new FaceDetector.Face[MAX_FACES];
	    FaceDetector fd = new FaceDetector(bmp.getWidth(), bmp.getHeight(), MAX_FACES);
	    return fd.findFaces(bmp, faces);
	} 
	 
	private Bitmap processImage(Bitmap bmp){
		Bitmap result;
		Matrix rotateMatrix = new Matrix();
		if(isFront)
			rotateMatrix.postRotate(270);
		else 
			rotateMatrix.postRotate(90);
		 
		result = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), rotateMatrix, false);
		 
		return makeItFunny(result);
4
CodeRank
This code example shows how to use the following methods:findFaces
         
        //When we are running the camera app, we want uri to be of the file 
        Uri uri = Uri.fromFile(getTempFile(this));
         
        //Pass the intent some parameters... 
        //intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); 
        //intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0); 
         
        //And we're running the camera app! 
        this.startActivityForResult(intent, PICTURE_RESULT);
         
         
    } 
     
    //This code runs after the camera app has been completed! Face detection and image manip 
    //Will be done here. 
    public void onActivityResult(int requestCode, int resultCode, Intent data)
    { 
        if(requestCode == PICTURE_RESULT)
        { 
4
CodeRank
This code example shows how to use the following methods:findFaces
		myBitmap = BitmapFactory.decodeFile(bitmapPath).copy(Bitmap.Config.RGB_565, true);
		 
		int imageWidth = myBitmap.getWidth();
		int imageHeight = myBitmap.getHeight();
		myFace = new FaceDetector.Face[numberOfFace];
		myFaceDetect = new FaceDetector(imageWidth, imageHeight, numberOfFace);
		mNumberFaces = myFaceDetect.findFaces(myBitmap, myFace);
		Log.e("number of faces", String.valueOf(numberOfFaceDetected));
	} 
	 
	public int getFacesNumber(){ 
		return mNumberFaces;
	} 
	 
	public Bitmap getChangedPhoto(){		
		 
		Canvas canvas = new Canvas(myBitmap);
	    Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
	    Bitmap overlay = BitmapFactory.decodeResource(context.getResources(), R.drawable.eye);
	     
5
CodeRank
This code example shows how to use the following methods:findFaces
This code example shows how to use the following methods:findFaces
    @Override 
    protected Face[] doInBackground(Bitmap... params) {
        mEditBitmap = detect(params[0]);        
        mCanvas = new Canvas(mEditBitmap);
        Face[] faces = new Face[MAX_FACES];
        FaceDetector detector = new FaceDetector(mEditBitmap.getWidth(), mEditBitmap.getHeight(), MAX_FACES);
        mFaceNum = detector.findFaces(mEditBitmap, faces);
        return faces;
    } 
     
    @Override 
    protected void onPostExecute(Face[] faces) {
        if(mWaitDialog!=null) {
            mWaitDialog.dismiss();
        } 
        Paint paint = getPaint();
        String mark = "★";
        FontMetrics fontMetrics = paint.getFontMetrics();
        //小数点切り上げ 
        int textWidth = (int) FloatMath.ceil(paint.measureText(mark));
4
CodeRank
This code example shows how to use the following methods:findFaces
    public void detect() { 
        int width = mBackBmp.getWidth();
        int height = mBackBmp.getHeight();
 
        FaceDetector.Face faces[] = new FaceDetector.Face[10];
        FaceDetector detector = new FaceDetector(width, height, faces.length);
        Bitmap bmp = mBackBmp.copy(Bitmap.Config.RGB_565, true); // 16bit
        detector.findFaces(bmp, faces);
 
        if (faces[0] == null) {
            Log.d(TAG, "face not found.");
            return; 
        } 
 
        PointF mid = new PointF();
        faces[0].getMidPoint(mid);
        float halfDist = faces[0].eyesDistance() / 2f;
        // 目の範囲 
        float paddingH = halfDist * .9f;
        float paddingV = halfDist * .6f;
4
CodeRank
This code example shows how to use the following methods:findFaces
    // ----------------------------------------------------- 
    private Face faceDetect(Bitmap bmp)
    { 
         
        FaceDetector.Face[] faces = new FaceDetector.Face[1]; // 結果受け取り用
        FaceDetector detector = new FaceDetector(bmp.getWidth(), bmp.getHeight(), faces.length);
        int numFaces = detector.findFaces(bmp, faces); // 顔認識実行
        if (numFaces > 0) {
            Face face = faces[0];
            return face;
        } else { 
            return null; 
        } 
    } 
     
    // ----------------------------------------------------- 
    // Native Code 
    // ----------------------------------------------------- 
    public native void NativeBitmapFunc(Bitmap bmp);
     
4
CodeRank

Related Android FaceDetector Questions & Answers:

See Code Examples for Android FaceDetector Methods: