我試圖檢測眼睛是否打開或關閉在檢測到的臉部。我正在使用以下代碼進行眼睛檢測。這段代碼所要做的就是重點檢測眼睛之間的距離。然後它計算臉部的中點,並從那裏檢測到眼睛的中心並在眼睛周圍繪製一個圓圈。這是眼睛檢測部分。如何查找眼睛是否開啓或關閉臉部檢測算法Android
但是我想要做的是找到眼睛是閉合還是閉合。 我想如何做到這一點首先要了解如何檢測眼睛/如何在較低級別檢測到眼睛之間的距離並使用較低級別的代碼來判斷眼睛是閉合還是閉合 - 即我想使用此代碼的能力來檢測眼睛,找出它究竟做到了這一點,從而找出它是打開還是關閉。 有人可以幫我嗎?我不想使用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);
}
}
}
}