Skip to content

Commit

Permalink
Merge branch 'release/1.3.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
takuya-takeuchi committed May 26, 2020
2 parents 5230393 + 5151433 commit 86d559d
Show file tree
Hide file tree
Showing 101 changed files with 4,538 additions and 158 deletions.
13 changes: 8 additions & 5 deletions ExecuteTest.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
$CodecovVersion = "1.7.1"
$CoverletVersion = "1.4.1"
$CodecovVersion = "1.10.0"

# check Codecov Token
$token = $env:CODECOV_TOKEN
Expand All @@ -12,8 +11,9 @@ if ([string]::IsNullOrEmpty($token))
Write-Host "Environmental Value 'CODECOV_TOKEN' is ${token}." -ForegroundColor Green

# install coverlet
dotnet tool install --global coverlet.console --version $CoverletVersion > $null
dotnet tool install --global coverlet.console > $null
dotnet add test\FaceRecognitionDotNet.Tests\FaceRecognitionDotNet.Tests.csproj package coverlet.msbuild > $null
dotnet add test\FaceRecognitionDotNet.Tests\FaceRecognitionDotNet.Tests.csproj package coverlet.collector > $null
# install codecov but it is not used from test project
dotnet add test\FaceRecognitionDotNet.Tests\FaceRecognitionDotNet.Tests.csproj package Codecov --version $CodecovVersion > $null

Expand All @@ -22,11 +22,14 @@ Write-Host "Start Test and collect Coverage." -ForegroundColor Green
dotnet test test\FaceRecognitionDotNet.Tests\FaceRecognitionDotNet.Tests.csproj `
/p:CollectCoverage=true `
/p:CoverletOutputFormat=opencover `
/p:Exclude="[DlibDotNet]*" `
-c Release
/p:Exclude="[DlibDotNet]*"
Write-Host "End Test and collect Coverage." -ForegroundColor Green

$path = (dotnet nuget locals global-packages --list).Replace('info : global-packages: ', '').Trim()
if ($path)
{
$path = (dotnet nuget locals global-packages --list).Replace('global-packages: ', '').Trim()
}
$path = Join-Path $path "codecov" | `
Join-Path -ChildPath $CodecovVersion

Expand Down
2 changes: 1 addition & 1 deletion ExecuteTestNuget.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
set PROJECT=test\FaceRecognitionDotNet.Tests\FaceRecognitionDotNet.Tests
set PACKAGECPU=FaceRecognitionDotNet
set PACKAGECUDA=FaceRecognitionDotNet.CUDA92
set PACKAGECUDA=FaceRecognitionDotNet.CUDA102
set NUGETDIR=%cd%\nuget

dotnet remove %PROJECT%.csproj package %PACKAGECPU%
Expand Down
28 changes: 28 additions & 0 deletions FaceRecognitionDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenderTraining", "tools\Gen
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HelenTraining", "tools\HelenTraining\HelenTraining.csproj", "{86A8F7D7-E3D6-4478-856E-B0FA91F5ABFA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlinkDetection", "examples\BlinkDetection\BlinkDetection.csproj", "{29E51D3D-7AEF-419E-9604-49116E28A211}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RgbBgr", "examples\RgbBgr\RgbBgr.csproj", "{13DDB1E7-EF71-48BA-A1E7-365C94783709}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadPoseTraining", "tools\HeadPoseTraining\HeadPoseTraining.csproj", "{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HeadPoseEstimationDemo", "examples\HeadPoseEstimationDemo\HeadPoseEstimationDemo.csproj", "{8540B212-5605-4402-BAE4-BEFEBAAD9F97}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -89,6 +97,22 @@ Global
{86A8F7D7-E3D6-4478-856E-B0FA91F5ABFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{86A8F7D7-E3D6-4478-856E-B0FA91F5ABFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{86A8F7D7-E3D6-4478-856E-B0FA91F5ABFA}.Release|Any CPU.Build.0 = Release|Any CPU
{29E51D3D-7AEF-419E-9604-49116E28A211}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29E51D3D-7AEF-419E-9604-49116E28A211}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29E51D3D-7AEF-419E-9604-49116E28A211}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29E51D3D-7AEF-419E-9604-49116E28A211}.Release|Any CPU.Build.0 = Release|Any CPU
{13DDB1E7-EF71-48BA-A1E7-365C94783709}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{13DDB1E7-EF71-48BA-A1E7-365C94783709}.Debug|Any CPU.Build.0 = Debug|Any CPU
{13DDB1E7-EF71-48BA-A1E7-365C94783709}.Release|Any CPU.ActiveCfg = Release|Any CPU
{13DDB1E7-EF71-48BA-A1E7-365C94783709}.Release|Any CPU.Build.0 = Release|Any CPU
{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E}.Release|Any CPU.Build.0 = Release|Any CPU
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8540B212-5605-4402-BAE4-BEFEBAAD9F97}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -106,6 +130,10 @@ Global
{AF7429BE-0747-4E9A-AB2F-17480A8D485E} = {8C8838E0-B002-426F-9B25-4C1F65A6D33D}
{44781AB4-D08C-4FDA-92EF-55C7CE9D5A18} = {8C8838E0-B002-426F-9B25-4C1F65A6D33D}
{86A8F7D7-E3D6-4478-856E-B0FA91F5ABFA} = {8C8838E0-B002-426F-9B25-4C1F65A6D33D}
{29E51D3D-7AEF-419E-9604-49116E28A211} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
{13DDB1E7-EF71-48BA-A1E7-365C94783709} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
{BB6A1F98-DEF9-475C-A69A-82FE518D1E9E} = {8C8838E0-B002-426F-9B25-4C1F65A6D33D}
{8540B212-5605-4402-BAE4-BEFEBAAD9F97} = {FEEAC07F-70D7-4C12-B92C-153CEE0F2539}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D44C572-D749-4A76-A199-8C598A08AE8A}
Expand Down
33 changes: 17 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ This package supports cross platform, Windows, Linux and MacOSX!!
|FaceRecognitionDotNet for CUDA 10.1|Windows|-||-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.CUDA101.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.CUDA101)|
||Linux|-||-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.CUDA101.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.CUDA101)|
||OSX|-|-|-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.CUDA101.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.CUDA101)|
|FaceRecognitionDotNet for CUDA 10.2|Windows|-||-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.CUDA102.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.CUDA102)|
||Linux|-||-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.CUDA102.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.CUDA102)|
||OSX|-|-|-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.CUDA102.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.CUDA102)|
|FaceRecognitionDotNet for Intel MKL|Windows|-||-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.MKL.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.MKL)|
||Linux|-||-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.MKL.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.MKL)|
||OSX|-||-|-|[![NuGet version](https://img.shields.io/nuget/v/FaceRecognitionDotNet.MKL.svg)](https://www.nuget.org/packages/FaceRecognitionDotNet.MKL)|
Expand All @@ -40,11 +43,13 @@ This package supports cross platform, Windows, Linux and MacOSX!!
|face_locations|FaceLocations||
|load_image_file|LoadImageFile||
|-|CropFaces|Crop image with specified locations|
|-|LoadImage|From memory data|
|-|PredictAge|Use **Adience Benchmark Of Unfiltered Faces For Gender And Age Classification dataset** :warning:|
|-|PredictGender|Use **UTKFace dataset** :warning:|
|-|PredictProbabilityAge|Use **Adience Benchmark Of Unfiltered Faces For Gender And Age Classification dataset** :warning:|
|-|PredictProbabilityGender|Use **UTKFace dataset** :warning:|
|-|EyeBlinkDetect|Detect person is blinking or not<br>Support Large model and **Helen dataset** :warning:|
|-|LoadImage|From memory data or System.Drawing.Bitmap|
|-|PredictAge|Predict human age.<br>Use **Adience Benchmark Of Unfiltered Faces For Gender And Age Classification dataset** :warning:|
|-|PredictGender|Predict human gender.<br>Use **UTKFace dataset** :warning:|
|-|PredictProbabilityAge|Predict probability of human age.<br>Use **Adience Benchmark Of Unfiltered Faces For Gender And Age Classification dataset** :warning:|
|-|PredictProbabilityGender|Predict probability of human gender.<br>Use **UTKFace dataset** :warning:|
|-|PredictHeadPose|Predict human head pose.<br>Use **300W-LP dataset** :warning:|

##### :warning: Warning

Expand All @@ -54,23 +59,20 @@ You can check the following examples to train dataset.

* tools/AgeTraining
* tools/GenderTraining
* tools/HeadPoseTraining
* tools/HelenTraining

## Demo

#### Face Recognition

<img src="images/1.png" width="480"/>
<img src="images/1.png" width="480"/> <img src="images/2.png" width="480"/>

<img src="images/2.png" width="480"/>
#### Other Face Functions

#### Face Landmark

<img src="images/3.jpg" width="240"/>

#### Age and Gender Classification

<img src="examples/CustomClassificationDemo/images/result.png" width="240"/>
|Face Landmark|Age and Gender Classification|Head Pose Estimation|
|---|---|---|
|<img src="images/3.jpg" width="240"/>|<img src="examples/CustomClassificationDemo/images/result.png" width="240"/>|<img src="images/4.png" width="240"/>|

## Dependencies Libraries and Products

Expand Down Expand Up @@ -112,5 +114,4 @@ You can check the following examples to train dataset.
>
> **Author:** shimat
>
> **Principal Use:** Loading image data by opencv wrapper for example
> **Principal Use:** Loading image data by opencv wrapper for example
4 changes: 3 additions & 1 deletion examples/Benchmark/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ This sample requires test image and model files.
1. Open command prompt and change to &lt;Benchmark_dir&gt;
1. Type the following command
````
dotnet build -c Release
$ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj
$ dotnet add package FaceRecognitionDotNet
$ dotnet build -c Release
````
2. Copy ***DlibDotNet.dll***, ***DlibDotNet.Native.dll*** and ***DlibDotNet.Dnn.dll*** to output directory; &lt;Benchmark_dir&gt;\bin\Release\netcoreapp2.0.
* if you use FaceRecognitionDotNet with CUDA, you must copy also cuda libraries.
Expand Down
4 changes: 4 additions & 0 deletions examples/BlinkDetection/.gitignore
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
19 changes: 19 additions & 0 deletions examples/BlinkDetection/BlinkDetection.csproj
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>
127 changes: 127 additions & 0 deletions examples/BlinkDetection/Program.cs
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

}

}
32 changes: 32 additions & 0 deletions examples/BlinkDetection/README.md
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 &lt;BlinkDetection_dir&gt;
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 &lt;BlinkDetection_dir&gt;
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
4 changes: 3 additions & 1 deletion examples/CustomClassificationDemo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ And you must generate the following model files and copy to &lt;CustomClassifica
1. Open command prompt and change to &lt;CustomClassificationDemo_dir&gt;
1. Type the following command
````
dotnet build -c Release
$ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj
$ dotnet add package FaceRecognitionDotNet
$ dotnet build -c Release
````
3. Copy ***DlibDotNetNative.dll***, ***DlibDotNetNativeDnn.dll***, ***DlibDotNetNativeDnnAgeClassification.dll*** and ***DlibDotNetNativeDnnGenderClassification.dll*** to output directory; &lt;CustomClassificationDemo_dir&gt;\bin\Release\netcoreapp2.0.
* if you use FaceRecognitionDotNet with CUDA, you must copy also cuda libraries.
Expand Down
4 changes: 3 additions & 1 deletion examples/FaceDetection/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ The directory that contains model files should be in &lt;FaceDetection_dir&gt;.
1. Open command prompt and change to &lt;FaceDetection_dir&gt;
1. Type the following command
````
dotnet build -c Release
$ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj
$ dotnet add package FaceRecognitionDotNet
$ dotnet build -c Release
````
2. Copy ***DlibDotNet.dll***, ***DlibDotNet.Native.dll*** and ***DlibDotNet.Dnn.dll*** to output directory; &lt;FaceDetection_dir&gt;\bin\Release\netcoreapp2.0.
* if you use FaceRecognitionDotNet with CUDA, you must copy also cuda libraries.
Expand Down
4 changes: 3 additions & 1 deletion examples/FaceEncodingPerformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ This sample requires test image and model files.
1. Open command prompt and change to &lt;FaceEncodingPerformance_dir&gt;
1. Type the following command
````
dotnet build -c Release
$ dotnet remove reference ../../src/FaceRecognitionDotNet\FaceRecognitionDotNet.csproj
$ dotnet add package FaceRecognitionDotNet
$ dotnet build -c Release
````
2. Copy ***DlibDotNet.dll***, ***DlibDotNet.Native.dll*** and ***DlibDotNet.Dnn.dll*** to output directory; &lt;FaceEncodingPerformance_dir&gt;\bin\Release\netcoreapp2.0.
* if you use FaceRecognitionDotNet with CUDA, you must copy also cuda libraries.
Expand Down
2 changes: 1 addition & 1 deletion examples/FindFacesInBatches/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static void Main(string[] args)
var array = new byte[tmp.Width * tmp.Height * tmp.ElemSize()];
Marshal.Copy(tmp.Data, array, 0, array.Length);

var image = FaceRecognition.LoadImage(array, tmp.Rows, tmp.Cols, tmp.ElemSize());
var image = FaceRecognition.LoadImage(array, tmp.Rows, tmp.Cols, tmp.Width * tmp.ElemSize(), Mode.Rgb);

// Save each frame of the video to a list
frameCount += 1;
Expand Down
Loading

0 comments on commit 86d559d

Please sign in to comment.