<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Face Detection in Static Images with Python</title>
	<atom:link href="http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/feed/" rel="self" type="application/rss+xml" />
	<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/</link>
	<description>A blog by Robert (Marty) McGuire</description>
	<lastBuildDate>Thu, 27 Oct 2011 03:23:20 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
	<item>
		<title>By: A Walk with Love and Data &#171; Quædam cuiusdam</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-439</link>
		<dc:creator>A Walk with Love and Data &#171; Quædam cuiusdam</dc:creator>
		<pubDate>Thu, 27 Oct 2011 03:23:20 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-439</guid>
		<description>[...] on their travel. The documents include photographs; Sherratt’s inspiration was to use open-source facial recognition software to crop the faces out of the scanned documents and present them as a waterfall, with more faces [...]</description>
		<content:encoded><![CDATA[<p>[...] on their travel. The documents include photographs; Sherratt’s inspiration was to use open-source facial recognition software to crop the faces out of the scanned documents and present them as a waterfall, with more faces [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: discontents - the real face of white australia</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-425</link>
		<dc:creator>discontents - the real face of white australia</dc:creator>
		<pubDate>Tue, 20 Sep 2011 14:42:23 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-425</guid>
		<description>[...] didn&#8217;t take long to find a python script that used the OpenCV library to detect faces in photographs. I tried the script on a few of the NAA [...]</description>
		<content:encoded><![CDATA[<p>[...] didn&#8217;t take long to find a python script that used the OpenCV library to detect faces in photographs. I tried the script on a few of the NAA [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Toby Skinner</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-422</link>
		<dc:creator>Toby Skinner</dc:creator>
		<pubDate>Mon, 12 Sep 2011 12:42:52 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-422</guid>
		<description>If you are using Python(X,Y) with Open CV 2 then you&#039;ll need to make a few tweaks.  I couldn&#039;t find the Haar classifier data in the standard install so I needed to download OpenCV, extract it and the data folder can be found in there (no need to actually build or install OpenCV).

My version that works, I&#039;m not a Python dev so I&#039;m sure there are optimisations etc:

import sys, os
import cv2.cv as cv

image = cv.LoadImage(sys.argv[1])

grayscale = cv.CreateImage((image.width, image.height), 8, 1)
cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY)

storage = cv.CreateMemStorage(0)
cv.EqualizeHist(grayscale, grayscale)
cascade = cv.Load(&#039;&#039;)
faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING, (50,50))

if faces:
	for f in faces:
	  print(f)

Note I&#039;m not sure where the ClearMemStorage function has gone and whether del does the same thing or not, someone better at Python might be able to help.

Also the data structures returned are slightly different, each &#039;face&#039; is a tuple containing a rect and an int.

Hope that helps someone.</description>
		<content:encoded><![CDATA[<p>If you are using Python(X,Y) with Open CV 2 then you&#8217;ll need to make a few tweaks.  I couldn&#8217;t find the Haar classifier data in the standard install so I needed to download OpenCV, extract it and the data folder can be found in there (no need to actually build or install OpenCV).</p>
<p>My version that works, I&#8217;m not a Python dev so I&#8217;m sure there are optimisations etc:</p>
<p>import sys, os<br />
import cv2.cv as cv</p>
<p>image = cv.LoadImage(sys.argv[1])</p>
<p>grayscale = cv.CreateImage((image.width, image.height), 8, 1)<br />
cv.CvtColor(image, grayscale, cv.CV_BGR2GRAY)</p>
<p>storage = cv.CreateMemStorage(0)<br />
cv.EqualizeHist(grayscale, grayscale)<br />
cascade = cv.Load(&#8221;)<br />
faces = cv.HaarDetectObjects(grayscale, cascade, storage, 1.2, 2, cv.CV_HAAR_DO_CANNY_PRUNING, (50,50))</p>
<p>if faces:<br />
	for f in faces:<br />
	  print(f)</p>
<p>Note I&#8217;m not sure where the ClearMemStorage function has gone and whether del does the same thing or not, someone better at Python might be able to help.</p>
<p>Also the data structures returned are slightly different, each &#8216;face&#8217; is a tuple containing a rect and an int.</p>
<p>Hope that helps someone.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leigh</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-309</link>
		<dc:creator>Leigh</dc:creator>
		<pubDate>Wed, 11 May 2011 17:06:38 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-309</guid>
		<description>1. install
# apt-get install python-opencv libcv-dev opencv-doc

2. extract
# cd /usr/share/doc/opencv-doc/examples/haarcascades/haarcascades/
# cp *.gz ..
# gunzip *.gz

3. Run (this changes your images and renames the old ones)

#!/usr/bin/python

# face_detect.py

# Face Detection using OpenCV. Based on sample code from:
# http://python.pastebin.com/m76db1d6b

# Usage: python face_detect.py 

import sys,os
from opencv.cv import *
from opencv.highgui import *

CLASSIFIER=&#039;/usr/share/doc/opencv-doc/examples/haarcascades/haarcascade_frontalface_default.xml&#039;


def detectObjects(fn, image):
  &quot;&quot;&quot;Converts an image to grayscale and prints the locations of any
     faces found&quot;&quot;&quot;
  grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
  cvCvtColor(image, grayscale, CV_BGR2GRAY)

  storage = cvCreateMemStorage(0)
  cvClearMemStorage(storage)
  cvEqualizeHist(grayscale, grayscale)
  cascade = cvLoadHaarClassifierCascade(CLASSIFIER, cvSize(1,1))
  faces = cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2,
                             CV_HAAR_DO_CANNY_PRUNING, cvSize(50,50))

  if faces:
    for f in faces:
      newfn = fn + &quot;.output.jpg&quot;
      os.system(&quot;convert %s -stroke red -fill none -draw &#039;rectangle %d,%d %d,%d&#039; %s&quot; % (fn, f.x, f.y, f.x+f.width, f.y+f.height, newfn))
      os.system(&quot;mv %s %s.orig&quot; % (fn, fn))
      os.system(&quot;mv %s %s&quot; % (newfn, fn))

def main():
  image = cvLoadImage(sys.argv[1]);
  detectObjects(sys.argv[1], image)

if __name__ == &quot;__main__&quot;:
  main()</description>
		<content:encoded><![CDATA[<p>1. install<br />
# apt-get install python-opencv libcv-dev opencv-doc</p>
<p>2. extract<br />
# cd /usr/share/doc/opencv-doc/examples/haarcascades/haarcascades/<br />
# cp *.gz ..<br />
# gunzip *.gz</p>
<p>3. Run (this changes your images and renames the old ones)</p>
<p>#!/usr/bin/python</p>
<p># face_detect.py</p>
<p># Face Detection using OpenCV. Based on sample code from:<br />
# <a href="http://python.pastebin.com/m76db1d6b" rel="nofollow">http://python.pastebin.com/m76db1d6b</a></p>
<p># Usage: python face_detect.py </p>
<p>import sys,os<br />
from opencv.cv import *<br />
from opencv.highgui import *</p>
<p>CLASSIFIER=&#8217;/usr/share/doc/opencv-doc/examples/haarcascades/haarcascade_frontalface_default.xml&#8217;</p>
<p>def detectObjects(fn, image):<br />
  &#8220;&#8221;"Converts an image to grayscale and prints the locations of any<br />
     faces found&#8221;"&#8221;<br />
  grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)<br />
  cvCvtColor(image, grayscale, CV_BGR2GRAY)</p>
<p>  storage = cvCreateMemStorage(0)<br />
  cvClearMemStorage(storage)<br />
  cvEqualizeHist(grayscale, grayscale)<br />
  cascade = cvLoadHaarClassifierCascade(CLASSIFIER, cvSize(1,1))<br />
  faces = cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2,<br />
                             CV_HAAR_DO_CANNY_PRUNING, cvSize(50,50))</p>
<p>  if faces:<br />
    for f in faces:<br />
      newfn = fn + &#8220;.output.jpg&#8221;<br />
      os.system(&#8220;convert %s -stroke red -fill none -draw &#8216;rectangle %d,%d %d,%d&#8217; %s&#8221; % (fn, f.x, f.y, f.x+f.width, f.y+f.height, newfn))<br />
      os.system(&#8220;mv %s %s.orig&#8221; % (fn, fn))<br />
      os.system(&#8220;mv %s %s&#8221; % (newfn, fn))</p>
<p>def main():<br />
  image = cvLoadImage(sys.argv[1]);<br />
  detectObjects(sys.argv[1], image)</p>
<p>if __name__ == &#8220;__main__&#8221;:<br />
  main()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: matias</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-308</link>
		<dc:creator>matias</dc:creator>
		<pubDate>Wed, 11 May 2011 14:51:50 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-308</guid>
		<description>I&#039;ve started this project about an year ago and uploaded to github when didn&#039;t had time to work on it, I guess it might be interesting to somebody.

It&#039;s python, of course, and uses opencv too.

https://github.com/omab/faces</description>
		<content:encoded><![CDATA[<p>I&#8217;ve started this project about an year ago and uploaded to github when didn&#8217;t had time to work on it, I guess it might be interesting to somebody.</p>
<p>It&#8217;s python, of course, and uses opencv too.</p>
<p><a href="https://github.com/omab/faces" rel="nofollow">https://github.com/omab/faces</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Face detection with Python &#171; Python Adventures</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-307</link>
		<dc:creator>Face detection with Python &#171; Python Adventures</dc:creator>
		<pubDate>Wed, 11 May 2011 03:35:20 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-307</guid>
		<description>[...] I found an interesting post: Face Detection in Static Images with Python. You give an image as input and the program draws a rectangle around the face(s) on the [...]</description>
		<content:encoded><![CDATA[<p>[...] I found an interesting post: Face Detection in Static Images with Python. You give an image as input and the program draws a rectangle around the face(s) on the [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: AnandOka</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-306</link>
		<dc:creator>AnandOka</dc:creator>
		<pubDate>Tue, 10 May 2011 02:47:21 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-306</guid>
		<description>Hi Marius, 
you need to make sure that in:
 cascade = cvLoadHaarClassifierCascade(
    &#039;path/to/haarcascade_frontalface_default.xml&#039;,
    cvSize(1,1))
  the path of the file is correct. Otherwise the returned value is a None which causes the abort.

In my ubuntu 11.04, the file is in 
/usr/share/doc/opencv-doc/examples/haarcascades/haarcascades/haarcascade_frontalface_default.xml.gz
I just copied it to my working directory and extracted it there.
The code worked after that.</description>
		<content:encoded><![CDATA[<p>Hi Marius,<br />
you need to make sure that in:<br />
 cascade = cvLoadHaarClassifierCascade(<br />
    &#8216;path/to/haarcascade_frontalface_default.xml&#8217;,<br />
    cvSize(1,1))<br />
  the path of the file is correct. Otherwise the returned value is a None which causes the abort.</p>
<p>In my ubuntu 11.04, the file is in<br />
/usr/share/doc/opencv-doc/examples/haarcascades/haarcascades/haarcascade_frontalface_default.xml.gz<br />
I just copied it to my working directory and extracted it there.<br />
The code worked after that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marius</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-296</link>
		<dc:creator>marius</dc:creator>
		<pubDate>Sun, 03 Apr 2011 12:41:35 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-296</guid>
		<description>Hi Robert, very late reply... :) I was just playing with stuff again and found the exact same website as last year.

I&#039;m using Ubuntu 10.10 with everything installed from repository. Still get the same error, even with ryanhaigh’s change. The script never gets to that line, so that doesn&#039;t surprise me.

Cheers!</description>
		<content:encoded><![CDATA[<p>Hi Robert, very late reply&#8230; <img src='http://creatingwithcode.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  I was just playing with stuff again and found the exact same website as last year.</p>
<p>I&#8217;m using Ubuntu 10.10 with everything installed from repository. Still get the same error, even with ryanhaigh’s change. The script never gets to that line, so that doesn&#8217;t surprise me.</p>
<p>Cheers!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wasuaje</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-294</link>
		<dc:creator>wasuaje</dc:creator>
		<pubDate>Tue, 15 Mar 2011 20:36:25 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-294</guid>
		<description>Hello there, i prefer to do the image changes (draw the rectangles) right in python so i paste my code all python based:

#!/usr/bin/python

# face_detect.py

# Face Detection using OpenCV. Based on sample code from:
# http://python.pastebin.com/m76db1d6b

# Usage: python face_detect.py 

import sys, os
from opencv.cv import *
from opencv.highgui import *
import Image, ImageDraw

def detectObjects(image):
  &quot;&quot;&quot;Converts an image to grayscale and prints the locations of any 
     faces found&quot;&quot;&quot;
  grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)
  cvCvtColor(image, grayscale, CV_BGR2GRAY)

  storage = cvCreateMemStorage(0)
  cvClearMemStorage(storage)
  cvEqualizeHist(grayscale, grayscale)
  cascade = cvLoadHaarClassifierCascade(&#039;/usr/share/doc/opencv-doc/examples/haarcascades/haarcascades/haarcascade_frontalface_alt.xml&#039;,cvSize(1,1))
  faces = cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2,CV_HAAR_DO_CANNY_PRUNING, cvSize(50,50))

  if faces.total &gt; 0:
    for f in faces:
      x1,y1,x2,y2=f.x,f.y,f.x+f.width,f.y+f.height
      print(&quot;[(%d,%d) -&gt; (%d,%d)]&quot; % (x1,y1,x2,y2))
      print_rectangle(x1,y1,x2,y2)	      #call to a python pil


def print_rectangle(x1,y1,x2,y2):		#function to modify the img
	im = Image.open(sys.argv[1])
	draw = ImageDraw.Draw(im)
	draw.rectangle([x1,y1,x2,y2])
	im.save(sys.argv[1])
	
def main():
  image = cvLoadImage(sys.argv[1]);
  detectObjects(image)

if __name__ == &quot;__main__&quot;:
  main()</description>
		<content:encoded><![CDATA[<p>Hello there, i prefer to do the image changes (draw the rectangles) right in python so i paste my code all python based:</p>
<p>#!/usr/bin/python</p>
<p># face_detect.py</p>
<p># Face Detection using OpenCV. Based on sample code from:<br />
# <a href="http://python.pastebin.com/m76db1d6b" rel="nofollow">http://python.pastebin.com/m76db1d6b</a></p>
<p># Usage: python face_detect.py </p>
<p>import sys, os<br />
from opencv.cv import *<br />
from opencv.highgui import *<br />
import Image, ImageDraw</p>
<p>def detectObjects(image):<br />
  &#8220;&#8221;"Converts an image to grayscale and prints the locations of any<br />
     faces found&#8221;"&#8221;<br />
  grayscale = cvCreateImage(cvSize(image.width, image.height), 8, 1)<br />
  cvCvtColor(image, grayscale, CV_BGR2GRAY)</p>
<p>  storage = cvCreateMemStorage(0)<br />
  cvClearMemStorage(storage)<br />
  cvEqualizeHist(grayscale, grayscale)<br />
  cascade = cvLoadHaarClassifierCascade(&#8216;/usr/share/doc/opencv-doc/examples/haarcascades/haarcascades/haarcascade_frontalface_alt.xml&#8217;,cvSize(1,1))<br />
  faces = cvHaarDetectObjects(grayscale, cascade, storage, 1.2, 2,CV_HAAR_DO_CANNY_PRUNING, cvSize(50,50))</p>
<p>  if faces.total &gt; 0:<br />
    for f in faces:<br />
      x1,y1,x2,y2=f.x,f.y,f.x+f.width,f.y+f.height<br />
      print(&#8220;[(%d,%d) -&gt; (%d,%d)]&#8221; % (x1,y1,x2,y2))<br />
      print_rectangle(x1,y1,x2,y2)	      #call to a python pil</p>
<p>def print_rectangle(x1,y1,x2,y2):		#function to modify the img<br />
	im = Image.open(sys.argv[1])<br />
	draw = ImageDraw.Draw(im)<br />
	draw.rectangle([x1,y1,x2,y2])<br />
	im.save(sys.argv[1])</p>
<p>def main():<br />
  image = cvLoadImage(sys.argv[1]);<br />
  detectObjects(image)</p>
<p>if __name__ == &#8220;__main__&#8221;:<br />
  main()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: wasuaje</title>
		<link>http://creatingwithcode.com/howto/face-detection-in-static-images-with-python/comment-page-1/#comment-293</link>
		<dc:creator>wasuaje</dc:creator>
		<pubDate>Tue, 15 Mar 2011 20:19:43 +0000</pubDate>
		<guid isPermaLink="false">http://creatingwithcode.com/?p=16#comment-293</guid>
		<description>Sorry found the solution myself here

https://bugs.launchpad.net/opencv/+bug/698016</description>
		<content:encoded><![CDATA[<p>Sorry found the solution myself here</p>
<p><a href="https://bugs.launchpad.net/opencv/+bug/698016" rel="nofollow">https://bugs.launchpad.net/opencv/+bug/698016</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>

