|
@@ -29,12 +29,12 @@ namespace ImpulseVision
|
|
|
public FormGuard()
|
|
|
{
|
|
|
InitializeComponent();
|
|
|
- captureTimer = new Timer()
|
|
|
+ CaptureTimer = new Timer()
|
|
|
{
|
|
|
Interval = Config.TimerResponseValue
|
|
|
|
|
|
};
|
|
|
- captureTimer.Tick += CaptureTimer_Tick;
|
|
|
+ CaptureTimer.Tick += CaptureTimer_Tick;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -45,16 +45,16 @@ namespace ImpulseVision
|
|
|
#region <Переменные>
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
private VideoCapture Capture;
|
|
|
- private CascadeClassifier haarCascade;
|
|
|
- private Image<Bgr, Byte> bgrFrame = null;
|
|
|
- private Image<Gray, Byte> detectedFace = null;
|
|
|
- private List<FaceData> faceList = new List<FaceData>();
|
|
|
- private VectorOfMat imageList = new VectorOfMat();
|
|
|
- private List<string> nameList = new List<string>();
|
|
|
- private VectorOfInt labelList = new VectorOfInt();
|
|
|
+ private CascadeClassifier HaarCascade;
|
|
|
+ private Image<Bgr, Byte> BgrFrame = null;
|
|
|
+ private Image<Gray, Byte> DetectedFace = null;
|
|
|
+ private List<FaceData> FaceList = new List<FaceData>();
|
|
|
+ private VectorOfMat ImageList = new VectorOfMat();
|
|
|
+ private List<string> NameList = new List<string>();
|
|
|
+ private VectorOfInt LabelList = new VectorOfInt();
|
|
|
|
|
|
private EigenFaceRecognizer recognizer;
|
|
|
- private Timer captureTimer;
|
|
|
+ private Timer CaptureTimer;
|
|
|
#region FaceName
|
|
|
private string faceName;
|
|
|
public string FaceName
|
|
@@ -136,29 +136,29 @@ namespace ImpulseVision
|
|
|
//haar cascade classifier
|
|
|
if (!File.Exists(Config.HaarCascadePath))
|
|
|
{
|
|
|
- string text = "Cannot find Haar cascade data file:\n\n";
|
|
|
+ string text = "Не удаётся найти файл данных каскад Хаара:\n\n";
|
|
|
text += Config.HaarCascadePath;
|
|
|
- DialogResult result = MessageBox.Show(text, "Error",
|
|
|
+ DialogResult result = MessageBox.Show(text, "Ошибка",
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
}
|
|
|
|
|
|
- haarCascade = new CascadeClassifier(Config.HaarCascadePath);
|
|
|
- faceList.Clear();
|
|
|
+ HaarCascade = new CascadeClassifier(Config.HaarCascadePath);
|
|
|
+ FaceList.Clear();
|
|
|
string line;
|
|
|
- FaceData faceInstance = null;
|
|
|
+ FaceData FaceItem = null;
|
|
|
|
|
|
// Create empty directory / file for face data if it doesn't exist
|
|
|
if (!Directory.Exists(Config.FacePhotosPath))
|
|
|
{
|
|
|
Directory.CreateDirectory(Config.FacePhotosPath);
|
|
|
}
|
|
|
-
|
|
|
+ //
|
|
|
if (!File.Exists(Config.FaceListTextFile))
|
|
|
{
|
|
|
- string text = "Cannot find face data file:\n\n";
|
|
|
+ string text = "Не удается найти файл с данными о лице:\n\n";
|
|
|
text += Config.FaceListTextFile + "\n\n";
|
|
|
- text += "If this is your first time running the app, an empty file will be created for you.";
|
|
|
- DialogResult result = MessageBox.Show(text, "Warning",
|
|
|
+ text += "Если вы впервые запускаете приложение, для вас будет создан пустой файл.";
|
|
|
+ DialogResult result = MessageBox.Show(text, "Предупреждение",
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
|
|
switch (result)
|
|
|
{
|
|
@@ -169,30 +169,58 @@ namespace ImpulseVision
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- StreamReader reader = new StreamReader(Config.FaceListTextFile);
|
|
|
+ //
|
|
|
+ //получить из БД инфо о пользователе (id, имя, фамилия, путь до фото)
|
|
|
+ SCon.Open();
|
|
|
+ string QueryGetInfoAboutUser = $@"select Users.ID ,Users.Lastname, Users.Firstname, Users.Patronymic, FaceImages.Picture
|
|
|
+ from Users join FaceImages on Users.ID = FaceImages.UserID";
|
|
|
+ SqlCommand Cmd = new SqlCommand(QueryGetInfoAboutUser, SCon);
|
|
|
+ SqlDataReader Res = Cmd.ExecuteReader();
|
|
|
+ if(Res.HasRows)
|
|
|
+ {
|
|
|
+ FaceItem = new FaceData();
|
|
|
+ while (Res.Read())
|
|
|
+ {
|
|
|
+ FaceItem.FaceImage = new Image<Gray, byte>(Res["Picture"].ToString());
|
|
|
+ FaceItem.PersonName = Res["Firstname"].ToString();
|
|
|
+ FaceItem.LastName = Res["Lastname"].ToString();
|
|
|
+ FaceItem.Patronymic = Res["Patronymic"].ToString();
|
|
|
+ FaceItem.UserID = Res["ID"].ToString();
|
|
|
+ FaceList.Add(FaceItem);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SCon.Close();
|
|
|
+ MessageBox.Show("Данные о пользователях отсутствуют!", "ImpulseVision", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ SCon.Close();
|
|
|
int i = 0;
|
|
|
+ /*
|
|
|
+ StreamReader reader = new StreamReader(Config.FaceListTextFile);
|
|
|
while ((line = reader.ReadLine()) != null)
|
|
|
{
|
|
|
string[] lineParts = line.Split(':');
|
|
|
- faceInstance = new FaceData();
|
|
|
- faceInstance.FaceImage = new Image<Gray, byte>(Config.FacePhotosPath + lineParts[0] + Config.ImageFileExtension);
|
|
|
- faceInstance.PersonName = lineParts[1];
|
|
|
- faceList.Add(faceInstance);
|
|
|
+ FaceItem = new FaceData();
|
|
|
+ FaceItem.FaceImage = new Image<Gray, byte>(Config.FacePhotosPath + lineParts[0] + Config.ImageFileExtension);
|
|
|
+ FaceItem.PersonName = lineParts[1];
|
|
|
+ FaceList.Add(FaceItem);
|
|
|
}
|
|
|
- foreach (var face in faceList)
|
|
|
+ reader.Close();
|
|
|
+ */
|
|
|
+ foreach (var face in FaceList)
|
|
|
{
|
|
|
- imageList.Push(face.FaceImage.Mat);
|
|
|
- nameList.Add(face.PersonName);
|
|
|
- labelList.Push(new[] { i++ });
|
|
|
+ ImageList.Push(face.FaceImage.Mat);
|
|
|
+ NameList.Add(face.PersonName);
|
|
|
+ LabelList.Push(new[] { i++ });
|
|
|
}
|
|
|
- reader.Close();
|
|
|
|
|
|
- // Train recogniser
|
|
|
- if (imageList.Size > 0)
|
|
|
+ // Тренировка распознавания
|
|
|
+ if (ImageList.Size > 0)
|
|
|
{
|
|
|
- recognizer = new EigenFaceRecognizer(imageList.Size);
|
|
|
- recognizer.Train(imageList, labelList);
|
|
|
+ recognizer = new EigenFaceRecognizer(ImageList.Size);
|
|
|
+ recognizer.Train(ImageList, LabelList);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -201,26 +229,26 @@ namespace ImpulseVision
|
|
|
/// </summary>
|
|
|
private void ProcessFrame()
|
|
|
{
|
|
|
- bgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
|
|
|
+ BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
|
|
|
|
|
|
- if (bgrFrame != null)
|
|
|
+ if (BgrFrame != null)
|
|
|
{
|
|
|
try
|
|
|
{//for emgu cv bug
|
|
|
- Image<Gray, byte> grayframe = bgrFrame.Convert<Gray, byte>();
|
|
|
+ Image<Gray, byte> grayframe = BgrFrame.Convert<Gray, byte>();
|
|
|
|
|
|
- Rectangle[] faces = haarCascade.DetectMultiScale(grayframe, 1.2, 10, new System.Drawing.Size(50, 50), new System.Drawing.Size(200, 200));
|
|
|
+ Rectangle[] faces = HaarCascade.DetectMultiScale(grayframe, 1.2, 10, new System.Drawing.Size(50, 50), new System.Drawing.Size(200, 200));
|
|
|
|
|
|
//detect face
|
|
|
FaceName = "No face detected";
|
|
|
foreach (var face in faces)
|
|
|
{
|
|
|
- bgrFrame.Draw(face, new Bgr(53, 23, 247), 2);
|
|
|
- detectedFace = bgrFrame.Copy(face).Convert<Gray, byte>();
|
|
|
+ BgrFrame.Draw(face, new Bgr(53, 23, 247), 2);
|
|
|
+ DetectedFace = BgrFrame.Copy(face).Convert<Gray, byte>();
|
|
|
FaceRecognition();
|
|
|
break;
|
|
|
}
|
|
|
- CameraCapture = bgrFrame.ToBitmap();
|
|
|
+ CameraCapture = BgrFrame.ToBitmap();
|
|
|
}
|
|
|
catch (Exception ex)
|
|
|
{
|
|
@@ -236,12 +264,12 @@ namespace ImpulseVision
|
|
|
/// </summary>
|
|
|
private void FaceRecognition()
|
|
|
{
|
|
|
- if (imageList.Size != 0)
|
|
|
+ if (ImageList.Size != 0)
|
|
|
{
|
|
|
//Eigen Face Algorithm
|
|
|
- FaceRecognizer.PredictionResult result = recognizer.Predict(detectedFace.Resize(100, 100, Inter.Cubic));
|
|
|
- FaceName = nameList[result.Label];
|
|
|
- CameraCaptureFace = detectedFace.ToBitmap();
|
|
|
+ FaceRecognizer.PredictionResult result = recognizer.Predict(DetectedFace.Resize(100, 100, Inter.Cubic));
|
|
|
+ FaceName = NameList[result.Label];
|
|
|
+ CameraCaptureFace = DetectedFace.ToBitmap();
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -584,7 +612,7 @@ namespace ImpulseVision
|
|
|
Capture.SetCaptureProperty(CapProp.Fps, 30);
|
|
|
Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
|
|
|
Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
|
|
|
- captureTimer.Start();
|
|
|
+ CaptureTimer.Start();
|
|
|
}
|
|
|
|
|
|
|
|
@@ -635,7 +663,7 @@ namespace ImpulseVision
|
|
|
Capture.SetCaptureProperty(CapProp.Fps, 30);
|
|
|
Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
|
|
|
Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
|
|
|
- captureTimer.Start();
|
|
|
+ CaptureTimer.Start();
|
|
|
}
|
|
|
|
|
|
private void TimerCam_Tick(object sender, EventArgs e)
|