Difference between revisions of "Face Detection from IronPython"

From Emgu CV: OpenCV in .NET (C#, VB, C++ and more)
Jump to: navigation, search
m
Line 6: Line 6:
  
 
*Create the detector by calling
 
*Create the detector by calling
<code>
+
<source lang="python">
 
detector = HaarCascade("haarcascade_frontalface_alt2.xml")
 
detector = HaarCascade("haarcascade_frontalface_alt2.xml")
</code>
+
</source>
 
*Read the image  
 
*Read the image  
<code>
+
<source lang="python">
 
image = Image[Gray, Byte]("lena.jpg")
 
image = Image[Gray, Byte]("lena.jpg")
</code>
+
</source>
 
*Detect the objects
 
*Detect the objects
<code>
+
<source lang="python">
 
objectsDetected = image.DetectHaarCascade(detector)[0]
 
objectsDetected = image.DetectHaarCascade(detector)[0]
</code>
+
</source>
 
*Draw the objects
 
*Draw the objects
<code>
+
<source lang="python">
 
for obj in objectsDetected: image.Draw[float](obj, Gray(255), 1)
 
for obj in objectsDetected: image.Draw[float](obj, Gray(255), 1)
</code>
+
</source>
 
*Display the image
 
*Display the image
<code>
+
<source lang="python">
 
ImageViewer.Show(image)
 
ImageViewer.Show(image)
</code>
+
</source>
  
 
[[image:IronPythonFaceDetect.png|300px|center|thumb|Face Detection from IronPython]]
 
[[image:IronPythonFaceDetect.png|300px|center|thumb|Face Detection from IronPython]]

Revision as of 00:57, 31 October 2008

Note: This example is base on Emgu CV 1.4.0.0

Assume that you have follow everything from Setting up Emgu CV and IronPython. This example is going to show you how to do face detection from IronPython.

First copy the lena.jpg file from OpenCV sample directory to the IronPython folder. Then copy the haarcascade_frontalface_alt2.xml file to the IronPython folder as well. Then follow the steps below:

  • Create the detector by calling
detector = HaarCascade("haarcascade_frontalface_alt2.xml")
  • Read the image
image = Image[Gray, Byte]("lena.jpg")
  • Detect the objects
objectsDetected = image.DetectHaarCascade(detector)[0]
  • Draw the objects
for obj in objectsDetected: image.Draw[float](obj, Gray(255), 1)
  • Display the image
ImageViewer.Show(image)
Face Detection from IronPython