Detecting eye blinking algorithms

  

I have implemented face detection on my application using this guide.
And i want to add eye blinking detection to it now. unfortunately there is no detailed properties in the Face Detector about eye blinking in Android.
The solution I thought about is : count the percentage of black color (iris) in both eye Rects drawn in the Paintbox, if that is possible, more black color means the eye is open and less black color means eye is closed.
I’m not sure how to implement that. As there is no way i know to get the color parameters from Paintbox.
here is the code if Painting :
procedure TCameraView.PaintBox1Paint(Sender: TObject; Canvas: TCanvas);
var
SrcRect, DstRect, Rect: TRectF;
Scale, DstWidth, DstHeight: Single;
Face: TgoFace;

procedure PaintEye(const APosition: TPointF; const AColor: TAlphaColor);
var
P: TPointF;
R: TRectF;
Radius: Single;
begin
try
{ Exit if eye position is not available }
if (APosition.X = 0) and (APosition.Y = 0) then
Exit;

P.X := APosition.X * Scale;
P.Y := APosition.Y * Scale;
P.Offset(DstRect.TopLeft);

Radius := Face.EyesDistance * Scale * 0.2;
R := RectF(P.X – Radius, P.Y – Radius, P.X + Radius, P.Y + Radius);
Canvas.Stroke.Color := AColor;
Canvas.DrawEllipse(R, 1);
Except on E :Exception do
begin
// ShowMessage(e.Message);
end;
end;
end;

begin
try
{ Paint bitmap to fit the paint box while preserving aspect ratio. }
SrcRect := RectF(0, 0, FBitmap.Width, FBitmap.Height);
Scale := Min(PaintBox1.Width / FBitmap.Width, PaintBox1.Height / FBitmap.Height);
DstWidth := Round(FBitmap.Width * Scale);
DstHeight := Round(FBitmap.Height * Scale);
DstRect.Left := Floor(0.5 * (PaintBox1.Width – DstWidth));
DstRect.Top := Floor(0.5 * (PaintBox1.Height – DstHeight));
DstRect.Width := DstWidth;
DstRect.Height := DstHeight;
Canvas.DrawBitmap(FBitmap, SrcRect, DstRect, 1);

Canvas.Stroke.Kind := TBrushKind.Solid;
Canvas.Stroke.Thickness := 2;

{ Paint each face with its features }
for Face in FFaces do
begin
{ Paint bounds around entire face }
Rect := Face.Bounds;
Rect.Left := Floor(Rect.Left * Scale);
Rect.Top := Floor(Rect.Top * Scale);
Rect.Right := Ceil(Rect.Right * Scale);
Rect.Bottom := Ceil(Rect.Bottom * Scale);
Rect.Offset(DstRect.TopLeft);

Canvas.Stroke.Color := TAlphaColors.Lime;
Canvas.DrawRect(Rect, 4, 4, AllCorners, 1);

{ Paint the eyes }
PaintEye(Face.LeftEyePosition, TAlphaColors.Magenta);
PaintEye(Face.RightEyePosition, TAlphaColors.Cyan);
end;
Except on E :Exception do
begin
// ShowMessagE(E.message);
end;
end;
end;

Comments are closed.