我正在尝试检测在检测到的面部中眼睛是睁着还是闭着。我正在使用以下代码进行眼睛检测。这段代码的作用本质上是检测眼睛之间的距离。然后它计算面部的中点,并从那里检测眼睛的中心并在眼睛周围画一个圆圈。那就是眼睛检测部分。
但是我想做的是找到眼睛是闭着还是闭着。我想如何做到这一点首先找出如何检测眼睛/如何在较低级别检测眼睛之间的距离,并使用该较低级别的代码来决定眼睛是闭上还是闭上 - 即我想使用此代码能够检测眼睛以找出它是如何做到的,从而确定它是打开还是关闭。有人可以帮帮我吗?我不想使用opencv。我只想使用下面给出的代码的简单性。
package my.eyedetector.code;
import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PointF;
import android.media.FaceDetector;
import android.media.FaceDetector.Face;
import android.view.View;
public class EyeDetectorActivity 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 = 4;
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.mypic, 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.RED);
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.drawCircle((float)(myMidPoint.x - myEyesDistance/2.0), myMidPoint.y, (float)20.0, myPaint);
canvas.drawCircle((float)(myMidPoint.x + myEyesDistance/2.0), myMidPoint.y, (float)20.0, myPaint);
}
}
}
}