Face Detection in VB.NET

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to navigation Jump to search

This example requires Emgu CV 1.5.0.0

Imports Emgu.CV
Imports Emgu.CV.Structure
Imports Emgu.Util
Imports System.Windows.Forms
Imports System.Drawing


Module Module1

   Sub Main()
      'Load the image from file
      Dim img As New Image(Of Bgr, Byte)("lena.jpg")

      'Load the object detector
      Dim objectToDetect As New HaarCascade("haarcascade_frontalface_alt2.xml")

      'Convert the image to Grayscale
      Dim imgGray As Image(Of Gray, Byte) = img.Convert(Of Gray, Byte)()

      For Each face As MCvAvgComp In imgGray.DetectHaarCascade(objectToDetect)(0)
         img.Draw(face.rect, New Bgr(Color.White), 1)
      Next

      'Show the image
      UI.ImageViewer.Show(img)

   End Sub

End Module
Face Detection using VB.NET