S
H
A
R
E

Monday, June 06, 2011

Detecting Face in Image (VB.net 2010)

Sample Face Detection with VB net 2010
Sample Face Detection
I write this code using VS 2010, and my OS is Windows 7. This code was used library of the Open Source Computer Vision (OpenCV) and EmguCV. see this:

Create new WindowsForm Project, and drop a PictureBox Control.
You must add the Emgu libraries, by adding reffences of this DLL:
- Emgu.CV.dll
- Emgu.CV.UI.dll
- Emgu.Util.dll

Write this code:

Imports Emgu.CV
Imports Emgu.Util
Imports Emgu.CV.Structure
Imports Emgu.CV.UI
Public Class Form1
    Private Sub Form1_Load() Handles MyBase.Load
        Dim p As String = Application.StartupPath
        PictureBox1.Image = Image.FromFile("image.jpg")
        Dim ImageBgr As New Image(Of Bgr, Byte)(PictureBox1.Image)
        Dim HaarXML As New HaarCascade("haarcascade_frontalface_alt_tree.xml")
        Dim GrayImage As Image(Of Gray, Byte) = ImageBgr.Convert(Of Gray, Byte)()
        Dim ImgGraphics As Graphics = Graphics.FromImage(PictureBox1.Image)
        Dim MPen As New Pen(Brushes.YellowGreen, 8)
        ' Will take a several minute.. please wait..
        For Each m In GrayImage.DetectHaarCascade(HaarXML)(0)
            ImgGraphics.DrawRectangle(MPen, m.rect)
        Next
    End Sub
End Class

When you execute your program, this DLL file must in the same folder of your exe file:
- cvextern.dll
- Emgu.CV.dll
- Emgu.CV.UI.dll
- Emgu.Util.dll

if you need to download this project, DOWNLOAD HERE

11 comments:

Anonymous said...

Not Working

Errer : GrayImage.DetectHaarCascade(HaarXML)

Klampok Child said...

put file "haarcascade_frontalface_alt_tree.xml" on current directory where app started.
NOTE: if you run with Netbeans, you must put xml file in PROJECT HOME FOLDER, not in "dist" directory.

Anonymous said...

broke link

Anonymous said...

broke link

MUCHLIS AMRULLOH said...

not working
Dim ImageBgr As New Image(Of Bgr, Byte)(PictureBox1.Image)

uhh said...

66666666

jaymar said...

Thanks for sharing. The rewards in joy, appreciation are probably incalculable.

www.n8fan.net

andrea chiu said...


There are times that we encounter fear and disappointments in life yet we still manage to stand up straight and face it rather than being silent. That is a very good example of being a brave and strong person. Well, I would like to thank you for sharing a very good article it is very much appreciated, good job! You can visit my site too if you want. Have a great day.Enjoy!

triciajoy.com

www.triciajoy.com

Eghy Rizky Octaviandhy said...

gan update link nya dnk, pleasee......

Cindy Dy said...

Very interesting story. I didn't find it boring to read. In fact, I really had a lot of fun reading your post. Thanks.

Bob
www.gofastek.com

lee woo said...

Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.


ufgop.org
ufgop.org

Post a Comment