I have this android face recognition algorithm i wrote but the problem with this is it gives me different facial values (e.g eye distance, confidence, mid-point x and y) for different pictures with the same person. for example if i have a picture of me but taken and two distinct different time and moods it gives me different face values. How can i correct that
public class FaceAlgorithm {
/**
* Face details variables
*/
private int facesFound = 0;
private static final PointF midPoint = new PointF();
private static float eyeDistance = 0.0f;
private static float confidence = 0.0f;
/**
* Image variables
*/
private Bitmap cameraBitmap = null;
private Bitmap output = null;
/**
* Collector variable
*/
private ArrayList<Map<String, Float>> Faces = null;
private Map<String, Float> facevalue;
public FaceAlgorithm() {
// TODO Auto-generated constructor stu
}
public void detectFaces() {
if (null != cameraBitmap) {
int width = cameraBitmap.getWidth();
int height = cameraBitmap.getHeight();
FaceDetector detector = new FaceDetector(width, height,
config.MAX_FACES);
Face[] faces = new Face[config.MAX_FACES];
Bitmap bitmap565 = Bitmap.createBitmap(width, height,
Config.RGB_565);
Paint ditherPaint = new Paint();
Paint drawPaint = new Paint();
ditherPaint.setDither(true);
drawPaint.setColor(Color.GREEN);
drawPaint.setStyle(Paint.Style.STROKE);
drawPaint.setStrokeWidth(90);
Canvas canvas = new Canvas();
canvas.setBitmap(bitmap565);
canvas.drawBitmap(cameraBitmap, 0, 0, ditherPaint);
facesFound = detector.findFaces(bitmap565, faces);
Log.i("FaceDetector", "Number of faces found: " + facesFound);
Faces = new ArrayList<Map<String, Float>>();
if (facesFound > 0) {
for (int index = 0; index < facesFound; ++index) {
faces[index].getMidPoint(midPoint);
eyeDistance = faces[index].eyesDistance();
confidence = faces[index].confidence();
Log.i("FaceDetector", "Confidence: " + confidence
+ ", Eye distance: " + eyeDistance
+ ", Mid Point: (" + midPoint.x + ", " + midPoint.y
+ ")");
facevalue = new HashMap<String, Float>();
facevalue.put(config.TAG_CON, confidence);
facevalue.put(config.TAG_EYE, eyeDistance);
facevalue.put(config.TAG_MX, midPoint.x);
facevalue.put(config.TAG_MY, midPoint.y);
Faces.add(facevalue);
// draws the rectangle over individual faces
canvas.drawRect((int) midPoint.x - eyeDistance,
(int) midPoint.y - eyeDistance, (int) midPoint.x
+ eyeDistance, (int) midPoint.y
+ eyeDistance, drawPaint);
}
}else
{
setOutput(null);
return;//break outta
}
//setting the output
setOutput(bitmap565);
}
}
private void setOutput(Bitmap bitmap565) {
// TODO Auto-generated method stub
this.output = bitmap565;
}
public Bitmap getOutput() {
return this.output;
}
public void setCameraBitmap(Bitmap cameraBitmap) {
this.cameraBitmap = cameraBitmap;
}
public int getNumberofFaces() {
return this.facesFound;
}
public ArrayList<Map<String, Float>> getFacesDetected()
{
return this.Faces;
}
}
0 comments:
Post a Comment