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
|