accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.48k stars 1.99k forks source link

Make a Team for Face Recognition Engine with Accord.Net and let's build our OWN SDK/API #1779

Open blaisexen opened 5 years ago

blaisexen commented 5 years ago

well be using MulticlassSupportVector with IRadialBasisKernel(RBF) / LSVM MultinomialLogisticRegression with BroydenFletcherGoldfarbShanno/ConjugateGradient RestrictedBoltzmannMachine with ResilientBackpropagationLearning DeepNeuralNetwork with ParallelResilientBackpropagationLearning ResilientBackpropagation(RproP)

IF only CNN or PNN or FFNN was included from Accord.Net Framework then we could probably use it for a test.

after face recognition is final then we go back to face detection to hard boiled face detection

here's my 2 videos for image recognition, <> store item recognition http://ge.tt/7v3lwBp2

object recognition http://ge.tt/38qK1eo2

Who's with me?

First member will be assigned to aligned the eyes of the face, BUT with the help of our discussion from our chat board, comments here? I think that's Ok.

================================================ my C# Face Detection Code with Accord.Net

using System; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; using System.Threading; using System.IO;

using Accord; using Accord.Imaging.Filters; using Accord.Video; using Accord.Video.DirectShow; using Accord.Vision.Detection; using Accord.Vision.Detection.Cascades;

namespace winformapp {

public partial class Form1 : Form
{

    RectanglesMarker marker;
    ResizeNearestNeighbor res = new ResizeNearestNeighbor(200, 200);
    ResizeNearestNeighbor resize = new ResizeNearestNeighbor(320, 200);
    Rectangle[] faces = null;
    internal string aliasname = "Unknown";

    FilterInfoCollection videoDevices;
    private string ldevice;
    private IVideoSource videoSource = null;
    HaarObjectDetector detector;

    public Form1()
    {
        InitializeComponent();

        detector = new HaarObjectDetector(new FaceHaarCascade(), 32, ObjectDetectorSearchMode.Average, 1.5f, ObjectDetectorScalingMode.GreaterToSmaller);
        detector.MaxSize = new Size(320, 320);
        detector.UseParallelProcessing = true;
        detector.Suppression = 2;

        listlocalcamera();
    }

    public static void SetDoubleBuffered(System.Windows.Forms.Control c)
    {
        System.Reflection.PropertyInfo aProp =
              typeof(System.Windows.Forms.Control).GetProperty(
                    "DoubleBuffered",
                    System.Reflection.BindingFlags.NonPublic |
                    System.Reflection.BindingFlags.Instance);
        aProp.SetValue(c, true, null);
    }

    private void listlocalcamera()
    {
        try
        {
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (videoDevices.Count == 0) return;
            for (int i = 0; i < videoDevices.Count; i++)
            {
                cmbcamera.Items.Add(videoDevices[i].Name);
            }
            cmbcamera.SelectedIndex = 0;
        }
        catch
        {
        }
    }

    private void uselocalcamera(int camnum)
    {
        try
        {
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            if (videoDevices.Count == 0) return;
            ldevice = videoDevices[camnum].MonikerString;
            selectlocalvideodevice(ldevice);
        }
        catch
        {
        }
    }

    private void selectlocalvideodevice(string dev)
    {
        VideoCaptureDevice videoSource = new VideoCaptureDevice(dev);
        videoSource.VideoResolution = selectResolution(videoSource);
        OpenVideoSource(videoSource);
    }

    private static VideoCapabilities selectResolution(VideoCaptureDevice device)
    {
        foreach (var cap in device.VideoCapabilities)
        {
            if (cap.FrameSize.Width == 1280)
                return cap;
            if (cap.FrameSize.Height == 800)
                return cap;
        }
        return device.VideoCapabilities.Last();
    }

    private void OpenVideoSource(IVideoSource source)
    {
        CloseVideoSource();
        videoSourcePlayer1.VideoSource = source;
        videoSource = source;
        videoSourcePlayer1.Start();
    }

    private void CloseVideoSource()
    {
        videoSourcePlayer1.SignalToStop();
        while (videoSourcePlayer1.IsRunning)
        {
            Thread.Sleep(100);
        }

            videoSourcePlayer1.Stop();
    }

    private void writetoframeimage(string aliasname, Bitmap image, int linex, int liney)
    {
        Graphics g = Graphics.FromImage(image);
        g.DrawString(aliasname, this.Font, Brushes.CornflowerBlue, new PointF(linex, liney));
        g.Flush();
    }

    private void videoSourcePlayer1_NewFrame(object sender, ref Bitmap image)
    {
        Bitmap ximage = image;
        ximage = resize.Apply(ximage);
        faces = detector.ProcessFrame(ximage);
        if (faces.Length > 0)
        {
            for (var i = 0; i < faces.Length; i++)
            {
                faces[i].X -= 10;
                faces[i].Y -= 10;
                faces[i].Height += 20;
                faces[i].Width += 20;
                var faceimage = new Crop(faces[i]).Apply(ximage);
                faceimage = res.Apply(faceimage);
                pictureBox2.Image = faceimage;
                writetoframeimage("Unknown", ximage, faces[i].X - 4, faces[i].Y - 14);
            }
        }
        marker = new RectanglesMarker(faces);
        marker.MarkerColor = Color.DeepSkyBlue;
        marker.ApplyInPlace(ximage);
        image = ximage;
    }

    private void button2_Click(object sender, EventArgs e)
    {
        if (cmbcamera.Items.Count > 0)
        {
            videoSourcePlayer1.BringToFront();
            uselocalcamera(cmbcamera.SelectedIndex);
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        SetDoubleBuffered(videoSourcePlayer1);
        SetDoubleBuffered(pictureBox2);
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        videoSourcePlayer1.Dispose();
        Environment.Exit(0);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if ((videoSource != null) && (videoSource is VideoCaptureDevice))
        {
            try
            {
                ((VideoCaptureDevice)videoSource).DisplayPropertyPage(this.Handle);
            }
            catch (NotSupportedException)
            {
                MessageBox.Show("The video source does not support configuration property page.", "Error",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

    }

}

}

================================================ my VB Face Detection Code with Accord.Net

Imports System Imports System.Data Imports System.Drawing Imports System.Linq Imports System.Windows.Forms Imports System.Threading Imports System.IO Imports Accord Imports Accord.Imaging.Filters Imports Accord.Video Imports Accord.Video.DirectShow Imports Accord.Vision.Detection Imports Accord.Vision.Detection.Cascades

Public Class Form1

Private marker As RectanglesMarker
Private res As ResizeNearestNeighbor = New ResizeNearestNeighbor(200, 200)
Private resizer As ResizeNearestNeighbor = New ResizeNearestNeighbor(320, 200)
Private faces As Rectangle() = Nothing
Friend aliasname As String = "Unknown"
Private videoDevices As FilterInfoCollection
Private ldevice As String
Private videoSource As IVideoSource = Nothing
Private detector As HaarObjectDetector

Public Sub New()
    InitializeComponent()
    detector = New HaarObjectDetector(New FaceHaarCascade(), 32, ObjectDetectorSearchMode.Average, 1.5F, ObjectDetectorScalingMode.GreaterToSmaller)
    detector.MaxSize = New Size(320, 320)
    detector.UseParallelProcessing = True
    detector.Suppression = 2
    listlocalcamera()

End Sub

Public Shared Sub SetDoubleBuffered(ByVal c As System.Windows.Forms.Control)
    Dim aProp As System.Reflection.PropertyInfo = GetType(System.Windows.Forms.Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
    aProp.SetValue(c, True, Nothing)
End Sub

Private Sub listlocalcamera()
    Try
        videoDevices = New FilterInfoCollection(FilterCategory.VideoInputDevice)
        If videoDevices.Count = 0 Then Return
        For i As Integer = 0 To videoDevices.Count - 1
            cmbcamera.Items.Add(videoDevices(i).Name)
        Next
        cmbcamera.SelectedIndex = 0
    Catch
    End Try
End Sub

Private Sub uselocalcamera(ByVal camnum As Integer)
    Try
        videoDevices = New FilterInfoCollection(FilterCategory.VideoInputDevice)
        If videoDevices.Count = 0 Then Return
        ldevice = videoDevices(camnum).MonikerString
        selectlocalvideodevice(ldevice)
    Catch
    End Try
End Sub

Private Sub selectlocalvideodevice(ByVal dev As String)
    Dim videoSource As VideoCaptureDevice = New VideoCaptureDevice(dev)
    videoSource.VideoResolution = selectResolution(videoSource)
    OpenVideoSource(videoSource)
End Sub

Private Shared Function selectResolution(ByVal device As VideoCaptureDevice) As VideoCapabilities
    For Each cap In device.VideoCapabilities
        If cap.FrameSize.Width = 1280 Then Return cap
        If cap.FrameSize.Height = 800 Then Return cap
    Next

    Return device.VideoCapabilities.Last()
End Function

Private Sub OpenVideoSource(ByVal source As IVideoSource)
    CloseVideoSource()
    VideoSourcePlayer1.VideoSource = source
    videoSource = source
    VideoSourcePlayer1.Start()
End Sub

Private Sub CloseVideoSource()
    VideoSourcePlayer1.SignalToStop()
    While VideoSourcePlayer1.IsRunning
        Thread.Sleep(100)
    End While

    VideoSourcePlayer1.[Stop]()
End Sub

Private Sub writetoframeimage(ByVal aliasname As String, ByVal image As Bitmap, ByVal linex As Integer, ByVal liney As Integer)
    Dim g As Graphics = Graphics.FromImage(image)
    g.DrawString(aliasname, Me.Font, Brushes.DeepSkyBlue, New PointF(linex, liney))
    g.Flush()
End Sub

Private Sub VideoSourcePlayer1_NewFrame(sender As Object, ByRef image As Bitmap) Handles VideoSourcePlayer1.NewFrame
    Dim ximage As Bitmap = image
    ximage = resizer.Apply(ximage)
    faces = detector.ProcessFrame(ximage)
    If faces.Length > 0 Then
        For i = 0 To faces.Length - 1
            faces(i).X -= 10
            faces(i).Y -= 10
            faces(i).Height += 20
            faces(i).Width += 20
            Dim faceimage = New Crop(faces(i)).Apply(ximage)
            faceimage = res.Apply(faceimage)
            pictureBox2.Image = faceimage
            writetoframeimage("Unknown", ximage, faces(i).X - 4, faces(i).Y - 14)
        Next
    End If

    marker = New RectanglesMarker(faces)
    marker.MarkerColor = Color.DeepSkyBlue
    marker.ApplyInPlace(ximage)
    image = ximage
End Sub

Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click
    If cmbcamera.Items.Count > 0 Then
        VideoSourcePlayer1.BringToFront()
        uselocalcamera(cmbcamera.SelectedIndex)
    End If
End Sub

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
    SetDoubleBuffered(VideoSourcePlayer1)
    SetDoubleBuffered(pictureBox2)
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles MyBase.FormClosing
    VideoSourcePlayer1.Dispose()
    Environment.[Exit](0)
End Sub

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    If (videoSource IsNot Nothing) AndAlso (TypeOf videoSource Is VideoCaptureDevice) Then
        Try
            CType(videoSource, VideoCaptureDevice).DisplayPropertyPage(Me.Handle)
        Catch __unusedNotSupportedException1__ As NotSupportedException
            MessageBox.Show("The video source does not support configuration property page.", "Error", MessageBoxButtons.OK, MessageBoxIcon.[Error])
        End Try
    End If
End Sub

End Class

blaisexen commented 5 years ago

anyway, if there is NON joining, then watchout my YOUTUBE videos of Face Recognition with OpenCv https://www.youtube.com/channel/UCaH7B7KmJAe3ppesuLbcOGQ

But please join, at-least.

lindomar-marques55 commented 4 years ago

deixe-me ver se entendi voce quer criar uma nov api de reconhecimento facial sem o accord.net? é isso mesmo? se for teriamos que entender de redes neurais e outras coisas mais.

blaisexen commented 4 years ago

Sim, eu entendo, e já fiz isso usando o Accord.net, mas algumas correções talvez o tornem bom como outros sdk de reconhecimento de rosto, como alinhamento de olhos e obtenção do tamanho de rostos. obrigado por perguntar.

lindomar-marques55 commented 4 years ago

Hi. i'm setting up an ironman jarvis brand virtual assistant. I implemented voice recognition using microsoft speech and implemented facial recognition using emgucv with Haarcascade recognition but the results with emgucv didn't make me happy so I would like to use neural network because I read that it generates more accurate results but I still can't find an example Good to be able to study, you can give me one. The face detection part is already ok, what I need is an efficient and accurate mechanism to say that the face belongs to john and not to joseph. forgive my english but i am using google translator.

blaisexen commented 4 years ago

Hi, this is Accord.net implementation using SVM,HMM,HCRF and NN https://www.youtube.com/watch?v=tEUxnQ7EHZA

EmguCv is good only for Indoor Face Recognition, https://www.youtube.com/watch?v=014hHoz7jXw

For Accord Face Recognition, here I have, https://sourceforge.net/projects/face-detection-accord-net-csvb/

What I don't have is the face alignment between eyes, and may also include other face properties of face like nose, mouth distance.

I don't have much time doing anything, but I could not give time coding the face alignment, if you have it please mail me, and after the right and good result I'll give you the full source code, but take note only 2 of us is with this.

thanks for your reply


Oi, esta é a implementação do Accord.net usando SVM, HMM, HCRF e NN https://www.youtube.com/watch?v=tEUxnQ7EHZA

O EmguCv é bom apenas para o reconhecimento de faces internas, https://www.youtube.com/watch?v=014hHoz7jXw

Para o reconhecimento de rosto Accord, aqui estou eu, https://sourceforge.net/projects/face-detection-accord-net-csvb/

O que não tenho é o alinhamento do rosto entre os olhos e também pode incluir outras propriedades do rosto, como nariz, distância da boca.

Não tenho muito tempo fazendo nada, mas não pude dar tempo de codificar o alinhamento do rosto, se houver, envie-me um email e, após o resultado certo e bom, darei o código-fonte completo, mas tome nota apenas 2 de nós está com isso.

Obrigado pela sua resposta

lindomar-marques55 commented 4 years ago

Using your example link https://sourceforge.net/projects/face-detection-accord-net-csvb/ caused me the blue screen of death when switching cameras. probably still have to stop the videodevice using signaltostop ().

here is what (https://github.com/lindomar-marques55/lfm-cam-face ) I have implemented so far

blaisexen commented 4 years ago

Oi, O que não tenho é o alinhamento do rosto entre os olhos e também pode incluir outras propriedades do rosto, como nariz, distância da boca.

Não tenho muito tempo fazendo nada, mas não pude dar tempo de codificar o alinhamento do rosto, se houver, envie-me um email e, após o resultado certo e bom, darei o código-fonte completo, mas tome nota apenas 2 de nós está com isso.

Obrigado pela sua resposta