當前位置: 首頁>>代碼示例>>Java>>正文


Java FaceDetector類代碼示例

本文整理匯總了Java中android.media.FaceDetector的典型用法代碼示例。如果您正苦於以下問題:Java FaceDetector類的具體用法?Java FaceDetector怎麽用?Java FaceDetector使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


FaceDetector類屬於android.media包,在下文中一共展示了FaceDetector類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createCameraSource

import android.media.FaceDetector; //導入依賴的package包/類
/**
 * Creates and starts the camera.  Note that this uses a higher resolution in comparison
 * to other detection examples to enable the barcode detector to detect small barcodes
 * at long distances.
 */
private void createCameraSource() {
  mCameraSource = open();
  maxFace = mCameraSource.getParameters().getMaxNumDetectedFaces();
  if (maxFace == 0)
    maxFace = 10;
  //mCameraSource.setFaceDetectionListener(this);
  previewSize = mCameraSource.getParameters().getPreviewSize();

  bufflen = previewSize.width * previewSize.height;
  grayBuff = new byte[bufflen];
  rgbs = new int[bufflen];
  faces = new FaceResult[maxFace];
  faces_previous = new FaceResult[maxFace];
  for (int i = 0; i < maxFace; i++) {
    faces[i] = new FaceResult();
    faces_previous[i] = new FaceResult();
  }
  fdet = new android.media.FaceDetector(previewSize.width, previewSize.height, maxFace);
  mCameraSource.setPreviewCallback(this);
}
 
開發者ID:windwang,項目名稱:react-native-face-detect,代碼行數:26,代碼來源:FaceTrackerView.java

示例2: onStart

import android.media.FaceDetector; //導入依賴的package包/類
@Override
public void onStart() {
    super.onStart();
    initView();

    mFaces = new FaceResult[MAX_FACE_COUNT];
    mPreviousFaces = new FaceResult[MAX_FACE_COUNT];
    mDetectedFaces = new FaceDetector.Face[MAX_FACE_COUNT];
    for (int i = 0; i < MAX_FACE_COUNT; i++) {
        mFaces[i] = new FaceResult();
        mPreviousFaces[i] = new FaceResult();
    }
    mFacesCountMap = new SparseIntArray();

    presenter = new SignInPresenter(this,getContext());
    presenter.start();
}
 
開發者ID:lazyparser,項目名稱:xbot_head,代碼行數:18,代碼來源:SignInFragment.java

示例3: findFaceMid

import android.media.FaceDetector; //導入依賴的package包/類
private static PointF findFaceMid(Bitmap in){
	PointF mid = new PointF();
	Bitmap bitmap565 = in.copy(Bitmap.Config.RGB_565, true);

	FaceDetector fd = new FaceDetector(in.getWidth(), in.getHeight(), 1);
	FaceDetector.Face[] faces = new FaceDetector.Face[1];
	fd.findFaces(bitmap565, faces);
	

	FaceDetector.Face face = faces[0];
	if (face != null){
		try{
			face.getMidPoint(mid);
			return mid;
		} catch (NullPointerException n){}
	}
	return null;

}
 
開發者ID:mots,項目名稱:haxsync,代碼行數:20,代碼來源:BitmapUtil.java

示例4: detectFace

import android.media.FaceDetector; //導入依賴的package包/類
private int detectFace() {
    Bitmap bitmap = mOriginal.copy(Bitmap.Config.RGB_565, true);

    FaceDetector.Face faces[] = new FaceDetector.Face[MAX_FACES];
    FaceDetector detector = new FaceDetector(bitmap.getWidth(), bitmap.getHeight(), MAX_FACES);
    int count = detector.findFaces(bitmap, faces);
    if (count > 0) {
        FaceDetector.Face face = faces[0];
        face.getMidPoint(mCenterPoint);
        mEyeDistance = face.eyesDistance();
    } else {
        mCenterPoint.x = 0.0f;
        mCenterPoint.y = 0.0f;
        mEyeDistance = 0.0f;
    }

    bitmap.recycle();

    return count;
}
 
開發者ID:Tinker-S,項目名稱:FaceBarCodeDemo,代碼行數:21,代碼來源:FaceComposeActivity.java

示例5: detectFace

import android.media.FaceDetector; //導入依賴的package包/類
private int detectFace() {
    Bitmap bitmap = mOriginal.copy(Bitmap.Config.RGB_565, true);

    FaceDetector.Face faces[] = new FaceDetector.Face[MAX_FACES];
    FaceDetector detector = new FaceDetector(bitmap.getWidth(), bitmap.getHeight(), MAX_FACES);
    int count = detector.findFaces(bitmap, faces);
    if (count > 0) {
        FaceDetector.Face face = faces[0];
        face.getMidPoint(mCenterPoint);
        mEyeDistance = face.eyesDistance();
    } else {
        mCenterPoint.x = 0.0f;
        mCenterPoint.y = 0.0f;
        mEyeDistance = 0.0f;
    }

    bitmap.recycle();
    bitmap = null;

    return count;
}
 
開發者ID:Tinker-S,項目名稱:FaceBarCodeDemo,代碼行數:22,代碼來源:ImageComposeDemoActivity.java

示例6: findFaces

import android.media.FaceDetector; //導入依賴的package包/類
@Override
public List<Rect> findFaces(Bitmap img) {
	
	if(img.getWidth()!=width || img.getHeight()!=height)
	{
		width = img.getWidth();
		height = img.getHeight();
	
		Log.v("SkinFaceDetector", String.format("Changing face detector resolution to %dx%d", width, height));
		
		myFaceDetect = new FaceDetector(width, height, NUMBER_OF_FACES);
	}
	
	faces.clear();
	
	time = System.currentTimeMillis();
	int n = myFaceDetect.findFaces(img, myFace);
	time = System.currentTimeMillis() - time;
	
   	for (int i = 0; i < n; i++) {
   		Rect r = face2Rect(myFace[i], img.getWidth(), img.getHeight());
   		faces.add(r);
	}
	
	return faces;
}
 
開發者ID:uberspot,項目名稱:Offline3fAuth,代碼行數:27,代碼來源:SkinFaceDetector.java

示例7: detectFace

import android.media.FaceDetector; //導入依賴的package包/類
@Nullable private static PointF detectFace(@NonNull Bitmap testBitmap) {
    final int maxFaces = 1;
    long millis = System.currentTimeMillis();
    // initialize the face detector, and look for only one face...
    FaceDetector fd = new FaceDetector(testBitmap.getWidth(), testBitmap.getHeight(), maxFaces);
    FaceDetector.Face[] faces = new FaceDetector.Face[maxFaces];
    int numFound = fd.findFaces(testBitmap, faces);
    PointF facePos = null;
    if (numFound > 0) {
        facePos = new PointF();
        faces[0].getMidPoint(facePos);
        // center on the nose, not on the eyes
        facePos.y += faces[0].eyesDistance() / 2;
        // normalize the position to [0, 1]
        facePos.set(MathUtil.constrain(facePos.x / testBitmap.getWidth(), 0, 1),
                MathUtil.constrain(facePos.y / testBitmap.getHeight(), 0, 1));
        L.d("Found face at " + facePos.x + ", " + facePos.y);
    }
    L.d("Face detection took " + (System.currentTimeMillis() - millis) + "ms");
    return facePos;
}
 
開發者ID:wikimedia,項目名稱:apps-android-wikipedia,代碼行數:22,代碼來源:FacePostprocessor.java

示例8: getFaces

import android.media.FaceDetector; //導入依賴的package包/類
List<FaceDetector.Face> getFaces(UQI uqi) {
    int max = 10;
    List<FaceDetector.Face> faces = new ArrayList<>();
    Bitmap bitmap = this.getBitmapRGB565(uqi);
    if (bitmap == null) return faces;
    FaceDetector detector = new FaceDetector(bitmap.getWidth(), bitmap.getHeight(), max);
    FaceDetector.Face[] facesArray = new FaceDetector.Face[max];
    int count = detector.findFaces(bitmap, facesArray);
    for (int i = 0; i < count; i++) {
        FaceDetector.Face face = facesArray[i];
        if (face != null && face.confidence() > 0.3)
            faces.add(face);
    }
    return faces;
}
 
開發者ID:PrivacyStreams,項目名稱:PrivacyStreams,代碼行數:16,代碼來源:ImageData.java

示例9: getFaceRect

import android.media.FaceDetector; //導入依賴的package包/類
/**
 * 計算識別框
 */
private void getFaceRect() {
    Rect[] faceRectList = new Rect[mDetectorData.getFacesCount()];
    Rect rect = null;
    float distance = 0;
    for (int i = 0; i < mDetectorData.getFacesCount(); i++) {
        faceRectList[i] = new Rect();
        FaceDetector.Face face = mFaces[i];
        if (face != null) {
            float eyeDistance = face.eyesDistance();
            eyeDistance = eyeDistance * mZoomRatio;
            if (eyeDistance > distance) {
                distance = eyeDistance;
                rect = faceRectList[i];
            }
            PointF midEyesPoint = new PointF();
            face.getMidPoint(midEyesPoint);
            midEyesPoint.x = midEyesPoint.x * mZoomRatio;
            midEyesPoint.y = midEyesPoint.y * mZoomRatio;
            ViseLog.i("eyeDistance:" + eyeDistance + ",midEyesPoint.x:" + midEyesPoint.x
                    + ",midEyesPoint.y:" + midEyesPoint.y);
            faceRectList[i].set((int) (midEyesPoint.x - eyeDistance),
                    (int) (midEyesPoint.y - eyeDistance),
                    (int) (midEyesPoint.x + eyeDistance),
                    (int) (midEyesPoint.y + eyeDistance));
            ViseLog.i("FaceRectList[" + i + "]:" + faceRectList[i]);
        }
    }
    mDetectorData.setLightIntensity(FaceUtil.getYUVLight(mDetectorData.getFaceData(), rect, mCameraWidth));
    mDetectorData.setFaceRectList(faceRectList);
    if (mCameraWidth > 0) {
        mDetectorData.setDistance(distance * 2 / mCameraWidth);
    }
}
 
開發者ID:xiaoyaoyou1212,項目名稱:ViseFace,代碼行數:37,代碼來源:NormalFaceDetector.java

示例10: run

import android.media.FaceDetector; //導入依賴的package包/類
public void run() {
    mImageMatrix = mImageView.getImageMatrix();
    Bitmap faceBitmap = prepareBitmap();

    mScale = 1.0F / mScale;
    if (faceBitmap != null && mDoFaceDetection) {
        FaceDetector detector = new FaceDetector(faceBitmap.getWidth(),
                faceBitmap.getHeight(), mFaces.length);
        mNumFaces = detector.findFaces(faceBitmap, mFaces);
    }

    if (faceBitmap != null && faceBitmap != mBitmap) {
        faceBitmap.recycle();
    }

    mHandler.post(new Runnable() {
        public void run() {

            mWaitingToPick = mNumFaces > 1;
            if (mNumFaces > 0) {
                for (int i = 0; i < mNumFaces; i++) {
                    handleFace(mFaces[i]);
                }
            } else {
                makeDefault();
            }
            mImageView.invalidate();
            if (mImageView.mHighlightViews.size() == 1) {
                mCrop = mImageView.mHighlightViews.get(0);
                mCrop.setFocus(true);
            }

            if (mNumFaces > 1) {
                MagicToast.showInfo(CropImage.this, "Multi face crop help");
            }
        }
    });
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:39,代碼來源:CropImage.java

示例11: detectFaces

import android.media.FaceDetector; //導入依賴的package包/類
@ProtoMethod(description = "Detect faces in a bitmap", example = "")
@ProtoMethodParam(params = {"Bitmap", "numFaces"})
public int detectFaces(Bitmap bmp, int num_faces) {
    FaceDetector face_detector = new FaceDetector(bmp.getWidth(), bmp.getHeight(), num_faces);
    FaceDetector.Face[] faces = new FaceDetector.Face[num_faces];
    int face_count = face_detector.findFaces(bmp, faces);

    return face_count;
}
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:10,代碼來源:PUtil.java

示例12: CommentaryFragment

import android.media.FaceDetector; //導入依賴的package包/類
public CommentaryFragment() {
    faces = new FaceResult[MAX_FACE_COUNT];
    previousFaces = new FaceResult[MAX_FACE_COUNT];
    detectedFaces = new FaceDetector.Face[MAX_FACE_COUNT];
    for (int i = 0; i < MAX_FACE_COUNT; i++) {
        faces[i] = new FaceResult();
        previousFaces[i] = new FaceResult();
    }

    recyclerViewBitmapList = new ArrayList<>();
    facesCountMap = new SparseIntArray();
}
 
開發者ID:lazyparser,項目名稱:xbot_head,代碼行數:13,代碼來源:CommentaryFragment.java

示例13: onStart

import android.media.FaceDetector; //導入依賴的package包/類
@Override
public void onStart() {
    super.onStart();

    mFaces = new FaceResult[MAX_FACE_COUNT];
    mPreviousFaces = new FaceResult[MAX_FACE_COUNT];
    mDetectedFaces = new FaceDetector.Face[MAX_FACE_COUNT];
    for (int i = 0; i < MAX_FACE_COUNT; i++) {
        mFaces[i] = new FaceResult();
        mPreviousFaces[i] = new FaceResult();
    }
    mFacesCountMap = new SparseIntArray();

}
 
開發者ID:lazyparser,項目名稱:xbot_head,代碼行數:15,代碼來源:InteractionFragment.java

示例14: performTask

import android.media.FaceDetector; //導入依賴的package包/類
@Override
@Nullable
public PointF performTask() {
    // boost this thread's priority a bit
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY - 1);
    long millis = System.currentTimeMillis();
    // create a new bitmap onto which we'll draw the original bitmap,
    // because the FaceDetector requires it to be a 565 bitmap, and it
    // must also be even width. Reduce size of copy for performance.
    Bitmap testBmp = new565ScaledBitmap(srcBitmap);

    // initialize the face detector, and look for only one face...
    FaceDetector fd = new FaceDetector(testBmp.getWidth(), testBmp.getHeight(), 1);
    FaceDetector.Face[] faces = new FaceDetector.Face[1];
    int numFound = fd.findFaces(testBmp, faces);

    PointF facePos = null;
    if (numFound > 0) {
        facePos = new PointF();
        faces[0].getMidPoint(facePos);
        // scale back to proportions of original image
        facePos.x = (facePos.x * srcBitmap.getWidth() / BITMAP_COPY_WIDTH);
        facePos.y = (facePos.y * srcBitmap.getHeight() / testBmp.getHeight());
        L.d("Found face at " + facePos.x + ", " + facePos.y);
    }
    // free our temporary bitmap
    testBmp.recycle();

    L.d("Face detection took " + (System.currentTimeMillis() - millis) + "ms");

    return facePos;
}
 
開發者ID:gnosygnu,項目名稱:xowa_android,代碼行數:33,代碼來源:ImageViewWithFace.java

示例15: run

import android.media.FaceDetector; //導入依賴的package包/類
public void run() {
    mImageMatrix = mImageView.getImageMatrix();
    Bitmap faceBitmap = prepareBitmap();

    mScale = 1.0F / mScale;
    if (faceBitmap != null && mDoFaceDetection) {
        FaceDetector detector = new FaceDetector(faceBitmap.getWidth(),
                faceBitmap.getHeight(), mFaces.length);
        mNumFaces = detector.findFaces(faceBitmap, mFaces);
    }

    if (faceBitmap != null && faceBitmap != mBitmap) {
        faceBitmap.recycle();
    }

    mHandler.post(new Runnable() {
        public void run() {

            mWaitingToPick = mNumFaces > 1;
            if (mNumFaces > 0) {
                for (int i = 0; i < mNumFaces; i++) {
                    handleFace(mFaces[i]);
                }
            } else {
                makeDefault();
            }
            mImageView.invalidate();
            if (mImageView.mHighlightViews.size() == 1) {
                mCrop = mImageView.mHighlightViews.get(0);
                mCrop.setFocus(true);
            }

            if (mNumFaces > 1) {
                Crouton.makeText(CropImage.this, "Multi face crop help", Style.INFO).show();
            }
        }
    });
}
 
開發者ID:ekimual,項目名稱:croperino,代碼行數:39,代碼來源:CropImage.java


注:本文中的android.media.FaceDetector類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。