本文整理匯總了Java中android.media.FaceDetector.findFaces方法的典型用法代碼示例。如果您正苦於以下問題:Java FaceDetector.findFaces方法的具體用法?Java FaceDetector.findFaces怎麽用?Java FaceDetector.findFaces使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.media.FaceDetector
的用法示例。
在下文中一共展示了FaceDetector.findFaces方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: 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;
}
示例7: 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");
}
}
});
}
示例8: 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;
}
示例9: 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;
}
示例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) {
Crouton.makeText(CropImage.this, "Multi face crop help", Style.INFO).show();
}
}
});
}
示例11: run
import android.media.FaceDetector; //導入方法依賴的package包/類
@Override
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() {
@Override
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);
}
}
});
}
示例12: 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);
}
}
});
}
示例13: setFaces
import android.media.FaceDetector; //導入方法依賴的package包/類
public void setFaces(PreProcessorFactory.PreprocessingMode preprocessingMode) {
List<Mat> images = getImages();
PreferencesHelper preferencesHelper = new PreferencesHelper(context);
if (preferencesHelper.getDetectionMethod()){
faces = faceDetection.getFaces(images.get(0));
angle = faceDetection.getAngle();
} else {
Mat img = images.get(0);
FaceDetector faceDetector = new FaceDetector(img.cols(), img.rows(), 1);
Bitmap bmp = Bitmap.createBitmap(img.cols(), img.rows(), Bitmap.Config.RGB_565);
Utils.matToBitmap(img, bmp);
FaceDetector.Face[] facesAndroid = new FaceDetector.Face[1];
if (faceDetector.findFaces(bmp, facesAndroid) > 0){
faces = new Rect[facesAndroid.length];
for (int i=0; i<facesAndroid.length; i++){
PointF pointF = new PointF();
facesAndroid[i].getMidPoint(pointF);
int xWidth = (int) (1.34 * facesAndroid[i].eyesDistance());
int yWidth = (int) (1.12 * facesAndroid[i].eyesDistance());
int dist = (int) (2.77 * facesAndroid[i].eyesDistance());
Rect face = new Rect((int) pointF.x - xWidth, (int) pointF.y - yWidth, dist, dist);
faces[i] = face;
}
}
}
if (preprocessingMode == PreProcessorFactory.PreprocessingMode.RECOGNITION && preferencesHelper.getDetectionMethod()){
// Change the image rotation to the angle where the face was detected
images.remove(0);
images.add(faceDetection.getImg());
setImages(images);
}
}
開發者ID:Qualeams,項目名稱:Android-Face-Recognition-with-Deep-Learning-Library,代碼行數:35,代碼來源:PreProcessor.java
示例14: 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) {
Toast t = Toast.makeText(CropImage.this, R.string.multiface_crop_help, Toast.LENGTH_SHORT);
t.show();
}
}
});
}
示例15: run
import android.media.FaceDetector; //導入方法依賴的package包/類
public void run() {
mImageMatrix = mImageView.getImageMatrix();
Bitmap faceBitmap = prepareBitmap();
mScale = 1.0F / mScale;
if (faceBitmap != null) {
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;
makeDefault();
mImageView.invalidate();
if (mImageView.mHighlightViews.size() > 0) {
mCrop = mImageView.mHighlightViews.get(0);
mCrop.setFocus(true);
}
if (mNumFaces > 1) {
}
}
});
}