Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
何阳
/
FaceApp
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
0429304c
authored
Jan 11, 2024
by
何阳
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
半张脸尝试
parent
c683a1ef
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
7 deletions
FaceServer/Face/heyang.jpg → FaceServer/Face/何阳.jpg
FaceServer/FaceServer.csproj
FaceServer/Model/shape_predictor_81_face_landmarks.dat
FaceServer/Util/FaceRecognitionThread.cs
FaceServer/Face/
heyang
.jpg
→
FaceServer/Face/
何阳
.jpg
View file @
0429304c
99.4 KB
|
W:
|
H:
99.4 KB
|
W:
|
H:
2-up
Swipe
Onion skin
FaceServer/FaceServer.csproj
View file @
0429304c
...
...
@@ -195,6 +195,9 @@
<None Include="Model\shape_predictor_68_face_landmarks.dat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Model\shape_predictor_81_face_landmarks.dat">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
...
...
@@ -213,7 +216,7 @@
<Content Include="App.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Face\
heyang
.jpg">
<Content Include="Face\
何阳
.jpg">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
...
...
FaceServer/Model/shape_predictor_81_face_landmarks.dat
0 → 100644
View file @
0429304c
The file could not be displayed because it is too large.
FaceServer/Util/FaceRecognitionThread.cs
View file @
0429304c
...
...
@@ -11,16 +11,30 @@ using System.Threading.Tasks;
using
System.Windows.Media.Imaging
;
using
System.Text
;
using
Serilog
;
using
FaceRecognitionDotNet.Extensions
;
using
DlibDotNet
;
using
Rectangle
=
System
.
Drawing
.
Rectangle
;
public
class
FaceRecognitionServer
{
private
static
FaceRecognition
FaceRecognition
=
null
;
private
static
Dictionary
<
string
,
FaceEncoding
>
KnownFaceEncodings
=
null
;
public
Rectangle
Roi
{
set
;
get
;
}
=
default
;
public
System
.
Drawing
.
Rectangle
Roi
{
set
;
get
;
}
=
default
;
public
int
RoiSize
{
set
;
get
;
}
=
default
;
public
FaceRecognitionServer
(
string
faceDataPath
,
string
modelPath
)
{
FaceRecognition
=
FaceRecognition
??
FaceRecognition
.
Create
(
modelPath
);
FaceRecognition
.
InternalEncoding
=
Encoding
.
Default
;
var
modelParameter
=
new
ModelParameter
{
PosePredictor68FaceLandmarksModel
=
File
.
ReadAllBytes
(
Path
.
Combine
(
modelPath
,
"shape_predictor_68_face_landmarks.dat"
)),
PosePredictor5FaceLandmarksModel
=
File
.
ReadAllBytes
(
Path
.
Combine
(
modelPath
,
"shape_predictor_5_face_landmarks.dat"
)),
FaceRecognitionModel
=
File
.
ReadAllBytes
(
Path
.
Combine
(
modelPath
,
"dlib_face_recognition_resnet_model_v1.dat"
)),
CnnFaceDetectorModel
=
File
.
ReadAllBytes
(
Path
.
Combine
(
modelPath
,
"mmod_human_face_detector.dat"
))
};
//FaceRecognition = FaceRecognition ?? FaceRecognition.Create(modelPath);
FaceRecognition
=
FaceRecognition
??
FaceRecognition
.
Create
(
modelParameter
);
KnownFaceEncodings
=
KnownFaceEncodings
??
LoadKnownFaces
(
FaceRecognition
,
faceDataPath
);
}
...
...
@@ -64,14 +78,11 @@ public class FaceRecognitionServer
bitmap
.
Dispose
();
// Detect faces
var
faceLocations
=
FaceRecognition
.
FaceLocations
(
image
);
if
(!
faceLocations
.
Any
())
{
image
.
Dispose
();
return
new
List
<
FaceData
>();
}
var
faceLandmarks
=
FaceRecognition
.
FaceLandmark
(
image
,
faceLocations
).
ToList
();
List
<
FaceData
>
faces
=
new
List
<
FaceData
>();
for
(
int
i
=
0
;
i
<
faceLocations
.
Count
();
i
++)
...
...
@@ -82,7 +93,13 @@ public class FaceRecognitionServer
upperFacePoints
.
AddRange
(
landmarks
[
FacePart
.
RightEyebrow
]);
upperFacePoints
.
AddRange
(
landmarks
[
FacePart
.
LeftEye
]);
upperFacePoints
.
AddRange
(
landmarks
[
FacePart
.
RightEye
]);
upperFacePoints
.
AddRange
(
landmarks
[
FacePart
.
NoseBridge
]);
//假设额外的额头点是从编号60到81
for
(
int
pointIndex
=
60
;
pointIndex
<=
81
;
pointIndex
++)
{
var
foreheadPoint
=
GetLandmarkPoint
(
landmarks
,
pointIndex
);
// 获取编号为pointIndex的特征点
upperFacePoints
.
Add
(
foreheadPoint
);
}
// 计算上半脸特征点的边界
var
minX
=
upperFacePoints
.
Min
(
point
=>
point
.
Point
.
X
)
+
Roi
.
X
;
...
...
@@ -132,6 +149,21 @@ public class FaceRecognitionServer
}
}
private
FacePoint
GetLandmarkPoint
(
IDictionary
<
FacePart
,
IEnumerable
<
FacePoint
>>
landmarks
,
int
pointIndex
)
{
foreach
(
var
item
in
landmarks
.
Values
)
{
foreach
(
var
point
in
item
)
{
if
(
point
.
Index
==
pointIndex
)
{
return
point
;
}
}
}
throw
new
KeyNotFoundException
();
}
// Helper method to load known faces
Dictionary
<
string
,
FaceEncoding
>
LoadKnownFaces
(
FaceRecognition
faceRecognition
,
string
faceDataPath
)
{
...
...
@@ -161,6 +193,14 @@ public class FaceRecognitionServer
upperFaceLandmarks
.
AddRange
(
faceLandmarks
[
FacePart
.
LeftEye
]);
upperFaceLandmarks
.
AddRange
(
faceLandmarks
[
FacePart
.
RightEye
]);
//假设额外的额头点是从编号60到81
for
(
int
pointIndex
=
60
;
pointIndex
<=
81
;
pointIndex
++)
{
var
foreheadPoint
=
GetLandmarkPoint
(
faceLandmarks
,
pointIndex
);
// 获取编号为pointIndex的特征点
upperFaceLandmarks
.
Add
(
foreheadPoint
);
}
// Calculate the bounding box for the upper face landmarks
var
minX
=
upperFaceLandmarks
.
Min
(
point
=>
point
.
Point
.
X
);
var
minY
=
upperFaceLandmarks
.
Min
(
point
=>
point
.
Point
.
Y
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment