Android人脸检测


问题内容

我正在尝试在android上进行人脸检测,并且正在遵循指南http://www.richardnichols.net/2011/01/java-
facial-recognition-haar-cascade-with-jjil-
guide/

但是在android上。当我做

Gray8DetectHaarMultiScale detectHaar = new Gray8DetectHaarMultiScale(is, minScale, maxScale);
RgbAvgGray toGray = new RgbAvgGray();
toGray.push(RgbImage);
detectHaar.pushAndReturn(toGray.getFront());

尽管确切的代码使用netbeans代码返回了2张面孔,但pushAndReturn似乎只从Android图像上返回了一张面孔。区别仅在于图像的类型(Android上的RgbImage和netbeans上的RgbImageJ2se)

我不知道自己想念什么,为什么我在Android上检测不到一张脸?

我正在使用JJIL,所以我的意思是RgbImage:jjil.core.RgbImage类型与RgbImageJ2SE类型。其余的都一样!!似乎pushAndReturn只返回堆栈中的一个条目。此功能不适用于多于一张脸的任何图像。


问题答案:

为此,工作并从给定图片中检测所有面孔

    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);
            }
  }
    }
}