-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
101 changed files
with
4,538 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
dlib_face_recognition_resnet_model_v1.dat | ||
mmod_human_face_detector.dat | ||
shape_predictor_5_face_landmarks.dat | ||
shape_predictor_68_face_landmarks.dat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<Authors>Takuya Takeuchi</Authors> | ||
<Description>Example of FaceRecognitionDotNet</Description> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" /> | ||
<PackageReference Include="OpenCvSharp3-AnyCPU" Version="3.4.4.20181118" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\FaceRecognitionDotNet\FaceRecognitionDotNet.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
using FaceRecognitionDotNet; | ||
using FaceRecognitionDotNet.Extensions; | ||
using Microsoft.Extensions.CommandLineUtils; | ||
using OpenCvSharp; | ||
using Point = FaceRecognitionDotNet.Point; | ||
|
||
namespace BlinkDetection | ||
{ | ||
|
||
internal class Program | ||
{ | ||
|
||
#region Fields | ||
|
||
private const int EyesClosedSeconds = 5; | ||
|
||
#endregion | ||
|
||
#region Methods | ||
|
||
private static void Main(string[] args) | ||
{ | ||
var app = new CommandLineApplication(false); | ||
app.Name = nameof(BlinkDetection); | ||
app.Description = "The program for blink detection demo"; | ||
app.HelpOption("-h|--help"); | ||
|
||
app.OnExecute(() => | ||
{ | ||
var closedCount = 0; | ||
var process = true; | ||
|
||
using (var fr = FaceRecognition.Create("models")) | ||
using (var videoCapture = new VideoCapture(0)) | ||
{ | ||
fr.CustomEyeBlinkDetector = new EyeAspectRatioLargeEyeBlinkDetector(0.2, 0.2); | ||
|
||
while (true) | ||
{ | ||
using (var frame = videoCapture.RetrieveMat()) | ||
using (var smallFrame = new Mat()) | ||
{ | ||
if (process) | ||
{ | ||
//Cv2.Resize(frame, smallFrame, Size.Zero, 0.25, 0.25); | ||
Cv2.Resize(frame, smallFrame, Size.Zero, 1, 1); | ||
|
||
var cols = smallFrame.Cols; | ||
var rows = smallFrame.Rows; | ||
var elems = smallFrame.ElemSize(); | ||
|
||
|
||
// get the correct face landmarks | ||
var bytes = new byte[rows * cols * elems]; | ||
Marshal.Copy(smallFrame.Data, bytes, 0, bytes.Length); | ||
using (var rgbSmallFrame = FaceRecognition.LoadImage(bytes, rows, cols, cols * elems, Mode.Rgb)) | ||
{ | ||
var faceLandmarksList = fr.FaceLandmark(rgbSmallFrame).ToArray(); | ||
|
||
// get eyes | ||
foreach (var faceLandmark in faceLandmarksList) | ||
{ | ||
var leftEye = faceLandmark[FacePart.LeftEye].ToArray(); | ||
var rightEye = faceLandmark[FacePart.RightEye].ToArray(); | ||
|
||
var color = new Scalar(255, 0, 0); | ||
var thickness = 2; | ||
|
||
var lp = new OpenCvSharp.Point(leftEye[0].Point.X, leftEye[0].Point.Y); | ||
var rp = new OpenCvSharp.Point(rightEye[rightEye.Length - 1].Point.X, rightEye[rightEye.Length - 1].Point.Y); | ||
var l = Math.Min(lp.X, rp.X); | ||
var r = Math.Max(lp.X, rp.X); | ||
var t = Math.Min(lp.Y, rp.Y); | ||
var b = Math.Max(lp.Y, rp.Y); | ||
Cv2.Rectangle(smallFrame, new OpenCvSharp.Point(l, t), new OpenCvSharp.Point(r, b), color, thickness); | ||
|
||
Cv2.ImShow("Video", smallFrame); | ||
Cv2.WaitKey(1); | ||
|
||
fr.EyeBlinkDetect(faceLandmark, out var leftBlink, out var rightBlink); | ||
|
||
var closed = leftBlink && rightBlink; | ||
|
||
if (closed) | ||
closedCount += 1; | ||
else | ||
closedCount = 0; | ||
|
||
if (closedCount >= EyesClosedSeconds) | ||
{ | ||
var asleep = true; | ||
while (asleep) // continue this loop until they wake up and acknowledge music | ||
{ | ||
Console.WriteLine("EYE CLOSED"); | ||
|
||
var key = Console.ReadKey(); | ||
|
||
if (key.Key == ConsoleKey.Spacebar) | ||
asleep = false; | ||
} | ||
|
||
closedCount = 0; | ||
} | ||
} | ||
} | ||
} | ||
|
||
process = !process; | ||
} | ||
} | ||
} | ||
|
||
return 0; | ||
}); | ||
|
||
app.Execute(args); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Blink Detection | ||
|
||
This example demonstrate detection of eye blink. | ||
This sample program is ported by C# from https://github.com/ageitgey/face_recognition/blob/master/examples/blink_detection.py | ||
|
||
## How to use? | ||
|
||
## 1. Preparation | ||
|
||
This sample requires model files and webcam. | ||
|
||
## 2. Build | ||
|
||
1. Open command prompt and change to <BlinkDetection_dir> | ||
1. Type the following command | ||
```` | ||
$ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj | ||
$ dotnet add package FaceRecognitionDotNet | ||
$ dotnet build -c Release | ||
```` | ||
|
||
## 3. Run | ||
|
||
1. Open command prompt and change to <BlinkDetection_dir> | ||
1. Type the following sample command | ||
```` | ||
$ dotnet run -c Release | ||
```` | ||
1. CameraImage is shown after camera detect face | ||
1. Blue rectangle is drawn if syes are detected | ||
1. Program will be paused if eyes are closing on 5 sec | ||
1. User can restart program by push space button if program is paused |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.