Please support this site!
If you found something helpful or inspiring on this site, you can help us to continue bringing you fresh and relevant content by making a small donation. This will help cover our operating costs and keep this turkey clucking.
 
 
 
VB .NET Wrapper For Face Detection



Well lately I've been kind of interested in facial recognition technology. So I've been reading up a bit and I came across the absolutely amazing OpenCV and I wanted to start playing with it. Now when I say I wanted to start playing with it, I did not say that I wanted to start porting enormous volumes of unmanaged C code to .NET and start playing with it, I meant I wanted to start playing with it pronto.

I poked around a bit to see if I could find some .NET wrappers for this rather wonderful body of code and I did actually find OpenCVDotNet. Those brave souls seem to be making a concerted effort at basically rewriting the whole library in managed code and for that I say good on 'em :-) However their offering was not quite mature enough to satisfy my hankering for tinkering. And then I came across this... jackpot baby!

My man digitals2002 was kind enough to wrap the Face Detection functionality in OpenCV for the lazy cretins of the world like myself who would not deign to do so much actual work :-) Anyhoo, so I started playing around with d's code to see how it would do at detecting faces in static images via a web interface. In the process, I found that for a number of reasons the functions exposed by the FaceDetection.Wrapper dll are extremely cumbersome if not impossible to use from VB .NET.

So, I started to code a little wrapper for the wrapper (I don't know why I find myself doing this a lot to use cool stuff in VB .NET... anyhoo...). And then it kind of snowballed and I decided to share it with the world so other VB lamers like me can trod where only intrepid C-sharpians have gone before... uh yeah. Anyways. The documentation is retarded, but I think the solution should build and you can incorporate the dll into your VB windows forms or ASP .NET apps.

You can download the solution here... It should build without any problems in VS 2005, but the results are dubios for 2003 or any version of Orcase (trust me things get screwy beyond belief with Orcas)

Email me or post here if you have questions, shout outs, requests, flames, etc.

Here is some sample ASP .NET code in VB using the wrapper...

    Private Sub TestVBFaceDetectionWrapper()

        Dim bmap As Bitmap = New Bitmap("test.gif")

        Try

            'try default frontal mode

            Dim w As New ZenTurkey.Wrappers.VBNET.VBFaceLocatorWrapper(bmap)

            If w.FoundFaces Then

                'face(s) detected in frontal mode

                Try

                    Dim g As Graphics = Graphics.FromImage(bmap)

                    Dim p As Pen = New Pen(Color.Red, 5.0F)

                    For Each f As Wrappers.VBNET.FaceCoordinates In w.FaceCoordinates

                        'draw a red rectangle for each face found in frontal mode

                        g.DrawRectangle(p, f.TopLeftXCoordinate, f.TopLeftYCoordinate, f.BottomRightXCoordinate, f.BottomRightYCoordinate)

                    Next

                    bmap.Save("frontal-face-results.bmp")

                    g.Dispose()

                    p.Dispose()

                Catch ex As Exception

                    'i dunno... maybe problems?

                End Try

            End If

            'now, try profile mode

            w = New ZenTurkey.Wrappers.VBNET.VBFaceLocatorWrapper(bmap)

            w.CurrentDetectionMode = Wrappers.VBNET.VBFaceLocatorWrapper.FaceDetectionMode.Profile

            If w.FoundFaces Then

                'face(s) detected in profile mode

                Try

                    Dim g As Graphics = Graphics.FromImage(bmap)

                    Dim p As Pen = New Pen(Color.Orange, 5.0F)

                    For Each f As Wrappers.VBNET.FaceCoordinates In w.FaceCoordinates

                        'draw a red rectangle for each face

                        g.DrawRectangle(p, f.TopLeftXCoordinate, f.TopLeftYCoordinate, f.BottomRightXCoordinate, f.BottomRightYCoordinate)

                    Next

                    bmap.Save("profile-face-results.bmp")

                    g.Dispose()

                    p.Dispose()

                Catch ex As Exception

                    'i dunno... maybe problems?

                End Try

            End If

        Catch ex As IO.FileNotFoundException

            'the wrapper constructor throws a file not found exception if any of the haar cascades files are missing

            Response.Write("Face locator prerequisites missing" & ex.Message)

        End Try

    End Sub


Hie !
I'm afraid nobody expecting me noticed your fabulous project ! But i'm having a little problem ....
In the main Try statment, an exception is found, and, in your comments, you wrote it was because of the lack of haar cascade files. But these are in the debug dir, with the VBWrappers.dll and FaceDetection.Wrapper.dll files.
Please tell me what's wrong.

Thank you very much !
Comment By CH At 11/9/2007 1:36 PM
Well, after some tries, I finaly managed to get it working. The issue was the lack of some dlls (cv100.dll, cxcore100.dll, etc). It now works, even it's infinitaly slower than the samples (written in c) in %OpenCV_installation_path%/samples/s/facedetection.exe !
But it is still a very good thing to make this wrapper.

(PS : please excuse my english, i'm a french student)
Comment By CH At 11/12/2007 10:29 AM
Hi CH,

Desoler de n'avoir pas vous repondre pendant aussi longtemps. J'etais en hiatus pendant un petit bout de temps. Je suis bien content que vous avez trouvez mon petit projet moindrement utile ;-) Si vous avez d'autre probleme avec la logiciel, n'hesitez pas de me contacter.

Et.... excusez mon francais pitoyable... je suis un mec anglais LOL.

br00t
Comment By Site Administrator At 11/13/2007 6:25 AM
Hi,
thanks for your work. Unfortunately I cannot get it working in a web app (VB.NET or C#).

I've installed OpenCV before using the project.
I can build the 2 wrapper projects without problems in VS 2005. I've added a web app to the solution and referenced the VBWrappers project.

After that I cannot build the web app (even if there's no code). On build, it brings up an error:
The specified module could not be found. (Exception from HRESULT: 0x8007007E)

The error is caused by the FaceDetection.Wrapper.dll

After removing this one from the web app the build works. Do you have any hint? How can I get this working?

Kind Regards,
Andreas
Comment By Andreas At 4/8/2009 6:12 AM
Thanks for the source. I am not able to make it work or even build. It indicates missing cv.h. I found a copy and now indicates missing cxmisc.h.
Any suggestions?
thanks in advance
Comment By Rusty At 6/10/2009 4:35 PM
Please logon or register to comment.