Android的人脸检测 [英] Android Face Detection
问题描述
我试图做的人脸检测在Android上,和我下面的指南的http://www.richardnichols.net/2011/01/java-facial-recognition-haar-cascade-with-jjil-guide/
I am trying to do face detection on android, and I am following the guide http://www.richardnichols.net/2011/01/java-facial-recognition-haar-cascade-with-jjil-guide/
但Android的替代。当我做
but on android instead. When i do
Gray8DetectHaarMultiScale detectHaar = new Gray8DetectHaarMultiScale(is, minScale, maxScale);
RgbAvgGray toGray = new RgbAvgGray();
toGray.push(RgbImage);
detectHaar.pushAndReturn(toGray.getFront());
看来pushAndReturn只从Android上的图像返回一个面虽然确切的code返回2面使用NetBeans code。所不同的是只在图像(RgbImage在Android和RgbImageJ2se的NetBeans)的种类
It seems that pushAndReturn is only returning one face from the image on Android although the exact code returns 2 faces using the netbeans code. The difference is only in the type of the image (RgbImage on android and RgbImageJ2se on netbeans)
我不知道是什么即时失踪,为什么我不能检测到多张人脸在Android?
I don't know what i m missing and why i can't detect more than one face on Android ?
我使用JJIL,所以我的意思是RgbImage:jjil.core.RgbImage类型,与RgbImageJ2SE类型。剩下的是一样的!似乎pushAndReturn仅返回堆栈中一个条目。与多张人脸的任何图像这是行不通的。
I am using JJIL so i mean by RgbImage: jjil.core.RgbImage type, vs. RgbImageJ2SE type. The rest is just the same!! it seems that pushAndReturn is only returning one entry in the stack. This does not work on any image with more than one face.
推荐答案
进入该公司工作,并检测所有面从给定的图片
Go for this its working and detecting all faces from a given picture
public class AndroidFaceDetector extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setContentView(new myView(this));
}
private class myView extends View{
private int imageWidth, imageHeight;
private int numberOfFace = 5;
private FaceDetector myFaceDetect;
private FaceDetector.Face[] myFace;
float myEyesDistance;
int numberOfFaceDetected;
Bitmap myBitmap;
public myView(Context context) {
super(context);
// TODO Auto-generated constructor stub
BitmapFactory.Options BitmapFactoryOptionsbfo = new BitmapFactory.Options();
BitmapFactoryOptionsbfo.inPreferredConfig = Bitmap.Config.RGB_565;
myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.face5,
BitmapFactoryOptionsbfo);
imageWidth = myBitmap.getWidth();
imageHeight = myBitmap.getHeight();
myFace = new FaceDetector.Face[numberOfFace];
myFaceDetect = new FaceDetector(imageWidth, imageHeight, numberOfFace);
numberOfFaceDetected = myFaceDetect.findFaces(myBitmap, myFace);
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
canvas.drawBitmap(myBitmap, 0, 0, null);
Paint myPaint = new Paint();
myPaint.setColor(Color.GREEN);
myPaint.setStyle(Paint.Style.STROKE);
myPaint.setStrokeWidth(3);
for(int i=0; i < numberOfFaceDetected; i++)
{
Face face = myFace[i];
PointF myMidPoint = new PointF();
face.getMidPoint(myMidPoint);
myEyesDistance = face.eyesDistance();
canvas.drawRect(
(int)(myMidPoint.x - myEyesDistance),
(int)(myMidPoint.y - myEyesDistance),
(int)(myMidPoint.x + myEyesDistance),
(int)(myMidPoint.y + myEyesDistance),
myPaint);
}
}
}
}
这篇关于Android的人脸检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!