2018-09-17 15:20:28 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Forms;
|
2018-09-18 09:25:01 +02:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
using Emgu.CV;
|
|
|
|
|
using Emgu.CV.CvEnum;
|
|
|
|
|
using Emgu.CV.Structure;
|
|
|
|
|
using Emgu.CV.UI;
|
|
|
|
|
using Emgu.Util;
|
|
|
|
|
using Emgu.CV.Face;
|
2018-09-17 15:20:28 +02:00
|
|
|
|
|
|
|
|
|
namespace FaceRecognizer
|
|
|
|
|
{
|
2018-09-18 07:43:19 +02:00
|
|
|
|
public partial class MainForm : Form
|
2018-09-17 15:20:28 +02:00
|
|
|
|
{
|
2018-09-18 09:25:01 +02:00
|
|
|
|
LBPHFaceRecognizer reconizer;
|
|
|
|
|
CascadeClassifier faceCascade;
|
|
|
|
|
Image<Gray, byte> temp;
|
|
|
|
|
List<Image<Gray, byte>> imageList = new List<Image<Gray, byte>>();
|
|
|
|
|
List<string> imageLabels = new List<string>();
|
|
|
|
|
List<int> imageIndicies = new List<int>();
|
|
|
|
|
Rectangle[] detectedFaces;
|
|
|
|
|
|
2018-09-18 07:43:19 +02:00
|
|
|
|
public MainForm()
|
2018-09-17 15:20:28 +02:00
|
|
|
|
{
|
2018-09-18 09:25:01 +02:00
|
|
|
|
InitializeComponent();
|
|
|
|
|
console.AppendText("Main OK!");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
reconizer = new LBPHFaceRecognizer(1, 8, 8, 9, 65);
|
|
|
|
|
faceCascade = new CascadeClassifier("faceCascade.xml");
|
|
|
|
|
console.AppendText("created regocnizer\n" +
|
|
|
|
|
"loading cascade\n" +
|
|
|
|
|
"loading images");
|
|
|
|
|
reconizer.Read("ss");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var file in Directory.GetFiles(Application.StartupPath))
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (file.EndsWith("jpg"))
|
|
|
|
|
{
|
|
|
|
|
Image<Gray, byte> temp2 = new Image<Gray, byte>(file);
|
|
|
|
|
pictureBox1.Image = temp2.ToBitmap();
|
|
|
|
|
var result = reconizer.Predict(temp2);
|
|
|
|
|
console.AppendText(">>result:" + result.Label.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
console.AppendText("Error: " + e.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//try
|
|
|
|
|
//{
|
|
|
|
|
// foreach (var file in Directory.GetFiles(Application.StartupPath))
|
|
|
|
|
// {
|
|
|
|
|
// if (file.EndsWith("jpg"))
|
|
|
|
|
// {
|
|
|
|
|
// console.AppendText("found: " + Path.GetFileNameWithoutExtension(file));
|
|
|
|
|
// temp = new Image<Gray, byte>(file);
|
|
|
|
|
// console.AppendText("loaded: " + Path.GetFileNameWithoutExtension(file));
|
|
|
|
|
// temp._EqualizeHist();
|
|
|
|
|
|
|
|
|
|
// //var detected_faces = faceCascade.DetectMultiScale(temp
|
|
|
|
|
// // , 1.1
|
|
|
|
|
// // , 20
|
|
|
|
|
// // , new Size(24, 24)
|
|
|
|
|
// // , Size.Empty);
|
|
|
|
|
// //if (detected_faces.Length == 0) { console.AppendText("lenght zero"); continue; }
|
|
|
|
|
// //temp.ROI = detected_faces[0];
|
|
|
|
|
|
|
|
|
|
// temp = temp.Copy();
|
|
|
|
|
// temp = temp.Resize(100, 100, Inter.Cubic);
|
|
|
|
|
// imageList.Add(temp);
|
|
|
|
|
// imageLabels.Add(Path.GetFileNameWithoutExtension(file));
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
// for (int i = 0; i < imageList.Count; i++)
|
|
|
|
|
// {
|
|
|
|
|
// imageIndicies.Add(i);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// try { reconizer.Train(imageList.ToArray(), imageIndicies.ToArray()); }
|
|
|
|
|
// catch (Exception e) { console.AppendText("Error: " + e.Message); }
|
|
|
|
|
// reconizer.Write("faceRecognizer");
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
//catch (Exception e)
|
|
|
|
|
//{
|
|
|
|
|
// console.AppendText("Error: " + e.Message);
|
|
|
|
|
//}
|
|
|
|
|
|
2018-09-17 15:27:56 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void console_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
console.AppendText("\n");
|
2018-09-17 15:20:28 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|