|
@@ -47,6 +47,8 @@ namespace T_FaceRecognizer
|
|
|
/// тип операции 1 - вход, 0- выход
|
|
|
/// </summary>
|
|
|
private int TypeOperation = 0;
|
|
|
+
|
|
|
+ private bool IsMenuOpened = true;
|
|
|
#endregion
|
|
|
#region <Свойства>
|
|
|
|
|
@@ -152,8 +154,14 @@ namespace T_FaceRecognizer
|
|
|
/// </summary>
|
|
|
private void ProcessFrame()
|
|
|
{
|
|
|
- BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
|
|
|
-
|
|
|
+ try
|
|
|
+ {
|
|
|
+ BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (BgrFrame != null)
|
|
|
{
|
|
|
try
|
|
@@ -163,10 +171,10 @@ namespace T_FaceRecognizer
|
|
|
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";
|
|
|
+ FaceName = "Лицо не обнаружено";
|
|
|
foreach (var face in faces)
|
|
|
{
|
|
|
- BgrFrame.Draw(face, new Bgr(255, 255, 0), 2);
|
|
|
+ BgrFrame.Draw(face, new Bgr(0, 0, 255), 2);
|
|
|
DetectedFace = BgrFrame.Copy(face).Convert<Gray, byte>();
|
|
|
FaceRecognition();
|
|
|
break;
|
|
@@ -202,31 +210,7 @@ namespace T_FaceRecognizer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// Convert bitmap to bitmap image for image control
|
|
|
- /// </summary>
|
|
|
- /// <param name="bitmap">Bitmap image</param>
|
|
|
- /// <returns>Image Source</returns>
|
|
|
- private Bitmap BitmapToImageSource(Bitmap bitmap)
|
|
|
- {
|
|
|
- using (MemoryStream memory = new MemoryStream())
|
|
|
- {
|
|
|
- bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
|
|
|
- memory.Position = 0;
|
|
|
- BitmapImage bitmapimage = new BitmapImage();
|
|
|
- bitmapimage.BeginInit();
|
|
|
- bitmapimage.StreamSource = memory;
|
|
|
- bitmapimage.CacheOption = BitmapCacheOption.OnLoad;
|
|
|
- bitmapimage.EndInit();
|
|
|
- //конвертация BitmapImage в Bitmap
|
|
|
- BitmapEncoder Enc = new BmpBitmapEncoder();
|
|
|
- Enc.Frames.Add(BitmapFrame.Create(bitmapimage));
|
|
|
- Enc.Save(memory);
|
|
|
- Bitmap Btm = new Bitmap(memory);
|
|
|
|
|
|
- return new Bitmap(Btm);
|
|
|
- }
|
|
|
- }
|
|
|
/// <summary>
|
|
|
/// добавление лица в систему
|
|
|
/// </summary>
|
|
@@ -293,12 +277,11 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
/// </summary>
|
|
|
public void GetFacesList()
|
|
|
{
|
|
|
- //haar cascade classifier
|
|
|
if (!File.Exists(Config.HaarCascadePath))
|
|
|
{
|
|
|
string text = "Файл каскада Хаара не обнаружен:\n\n";
|
|
|
text += Config.HaarCascadePath;
|
|
|
- DialogResult result = MessageBox.Show(text, "Error",
|
|
|
+ DialogResult result = MessageBox.Show(text, "Ошибка",
|
|
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
}
|
|
|
|
|
@@ -338,14 +321,15 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
|
|
|
private void PbxMenu_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
+ IsMenuOpened = !IsMenuOpened;
|
|
|
if(SplitContainer.Panel1.Width != 45)
|
|
|
{
|
|
|
SplitContainer.SplitterDistance = 45;
|
|
|
- PanHome.BackColor = Color.FromArgb(243, 243, 243);
|
|
|
- PanAdd.BackColor = Color.FromArgb(243, 243, 243);
|
|
|
- PanIdentification.BackColor = Color.FromArgb(243, 243, 243);
|
|
|
- PanJournal.BackColor = Color.FromArgb(243, 243, 243);
|
|
|
- PanSettings.BackColor = Color.FromArgb(243, 243, 243);
|
|
|
+ PanHome.BackColor = Color.FromArgb(206, 208, 223);
|
|
|
+ PanAdd.BackColor = Color.FromArgb(206, 208, 223);
|
|
|
+ PanIdentification.BackColor = Color.FromArgb(206, 208, 223);
|
|
|
+ PanJournal.BackColor = Color.FromArgb(206, 208, 223);
|
|
|
+ PanSettings.BackColor = Color.FromArgb(206, 208, 223);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -358,10 +342,25 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+ /// <summary>
|
|
|
+ /// котроль размеров меню
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="isMenuOpened">открыто меню или нет</param>
|
|
|
+ private void ControlSizeMenu(bool isMenuOpened)
|
|
|
+ {
|
|
|
+ if (isMenuOpened)
|
|
|
+ {
|
|
|
+ SplitContainer.SplitterDistance = 250;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ SplitContainer.SplitterDistance = 45;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
private void FormMain_Resize(object sender, EventArgs e)
|
|
|
{
|
|
|
- //PbxMenu_Click(sender, e);
|
|
|
+ ControlSizeMenu(IsMenuOpened);
|
|
|
}
|
|
|
|
|
|
private void FormMain_ResizeEnd(object sender, EventArgs e)
|
|
@@ -371,6 +370,11 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
|
|
|
private void BtnMain_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ RecognizeOff();
|
|
|
+ });
|
|
|
+
|
|
|
TabPages.SelectTab(4);
|
|
|
}
|
|
|
|
|
@@ -384,14 +388,18 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
};
|
|
|
CaptureTimer.Tick += CaptureTimer_Tick;
|
|
|
|
|
|
- GetFacesList();
|
|
|
- Capture = new VideoCapture(Config.ActiveCameraIndex);
|
|
|
+ if (ImageList.Size == 0)
|
|
|
+ {
|
|
|
+ GetFacesList();
|
|
|
+ }
|
|
|
+ TabPages.SelectTab(0);
|
|
|
+
|
|
|
+ Capture = new VideoCapture(SelectedCameraID);
|
|
|
Capture.SetCaptureProperty(CapProp.Fps, 30);
|
|
|
Capture.SetCaptureProperty(CapProp.FrameHeight, 450);
|
|
|
Capture.SetCaptureProperty(CapProp.FrameWidth, 370);
|
|
|
CaptureTimer.Start();
|
|
|
|
|
|
- TabPages.SelectTab(0);
|
|
|
}
|
|
|
|
|
|
private void BtnIdent_Click(object sender, EventArgs e)
|
|
@@ -402,14 +410,14 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
};
|
|
|
CaptureTimerIdent.Tick += CaptureTimerIdent_Tick;
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- RecognizeOff();
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
- }
|
|
|
+ //try
|
|
|
+ //{
|
|
|
+ // RecognizeOff();
|
|
|
+ //}
|
|
|
+ //catch (Exception ex)
|
|
|
+ //{
|
|
|
+ // MessageBox.Show(ex.Message, "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
|
|
|
+ //}
|
|
|
|
|
|
GetFacesListForIdentification();
|
|
|
|
|
@@ -430,11 +438,19 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
{
|
|
|
if (BgrFrame != null)
|
|
|
{
|
|
|
- BgrFrame = null;
|
|
|
- Capture.Dispose();
|
|
|
+ if (Capture != null)
|
|
|
+ {
|
|
|
+ Capture.Dispose();
|
|
|
+ Capture = null;
|
|
|
+ }
|
|
|
+ //BgrFrame = null;
|
|
|
if (CaptureTimer != null)
|
|
|
{
|
|
|
- CaptureTimer.Tick -= CaptureTimer_Tick;
|
|
|
+ CaptureTimer.Enabled = false;
|
|
|
+ }
|
|
|
+ if(CaptureTimerIdent != null)
|
|
|
+ {
|
|
|
+ CaptureTimerIdent.Enabled = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -449,8 +465,14 @@ values (@last,@first,@patr,@phone,@snils,@photo)
|
|
|
/// </summary>
|
|
|
private void ProcessFrameIndentification()
|
|
|
{
|
|
|
- BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
|
|
|
-
|
|
|
+ try
|
|
|
+ {
|
|
|
+ BgrFrame = Capture.QueryFrame().ToImage<Bgr, Byte>().Flip(FlipType.Horizontal);
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (BgrFrame != null)
|
|
|
{
|
|
|
try
|
|
@@ -626,7 +648,10 @@ where UsersID = '{CurrentUserID}' and [Date] = cast(GETDATE() as date)";
|
|
|
|
|
|
private void BtnJournal_Click(object sender, EventArgs e)
|
|
|
{
|
|
|
- RecognizeOff();
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ RecognizeOff();
|
|
|
+ });
|
|
|
GetInformationAboutVisiting();
|
|
|
TabPages.SelectTab(2);
|
|
|
}
|
|
@@ -672,5 +697,26 @@ from Users";
|
|
|
FVisiting.ShowDialog();
|
|
|
this.Show();
|
|
|
}
|
|
|
+
|
|
|
+ private void BtnSettings_Click(object sender, EventArgs e)
|
|
|
+ {
|
|
|
+ Task.Factory.StartNew(() =>
|
|
|
+ {
|
|
|
+ RecognizeOff();
|
|
|
+ });
|
|
|
+
|
|
|
+ TabPages.SelectTab(3);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void PanelMenu_Paint(object sender, PaintEventArgs e)
|
|
|
+ {
|
|
|
+ Invalidate();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
|
|
|
+ {
|
|
|
+ RecognizeOff();
|
|
|
+ Application.ExitThread();
|
|
|
+ }
|
|
|
}
|
|
|
}
|