newbie: q@HaarLikeFeature

279 views
Skip to first unread message

der_tom

unread,
Mar 30, 2012, 8:58:54 AM3/30/12
to simp...@googlegroups.com
hi, im new to simplecv and was reading tru the examples and docs.
i've installed everything and shell works so far, i can run the examples.

now what i would like to do is to detect for examples eyes or the mouth on an image. does anyone have an example on how to detect and or extract the coordinates? is this even possible with simplecv?
tia
tom

Nathan Oostendorp

unread,
Mar 30, 2012, 9:18:45 AM3/30/12
to simp...@googlegroups.com
Hi,

you want to use:

eyes = image.findHaarFeature("eyes.xml")

that will give you the features with x/y and width and height.  OpenCV typically installs haar cascade files in  /usr/local/share/opencv/haarcascades/ on mac or linux -- or in c:\opencv on windows.  Look at the list of features there to get an idea.

--n

tom

unread,
Mar 30, 2012, 10:31:47 AM3/30/12
to simp...@googlegroups.com
Hi Nathan,
would u mind having a quick look?

Code:
----------------------------------
import SimpleCV
from SimpleCV import Image
from SimpleCV import ImageClass
from SimpleCV import Features
import time

def function(a, b):
    print a, b
apply(function, (1, 2 + 3))

image = Image("frontface.jpg")
imagescaled = image.copy()
imagescaled = imagescaled.scale(90,90)
imagescaled.save("C:\Users\tom\pub\frontfaceNew.jpg")

eyespath = "C:\OpenCV2.2\data\haarcascades\haarcascade_eye.xml"
fset_eyes = image.findHaarFeature(eyespath)

print fset_eyes.inspect
------------
Result:
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
1 5

Traceback (most recent call last):
  File "C:\Users\tom\pub\test.py", line 21, in <module>
    fset_eyes = image.findHaarFeature(eyespath)
AttributeError: Image instance has no attribute 'findHaarFeature'
>>> 
------------------------
1) scaled image does not get created
frontface.jpg is in the same folder as the script
2) why doesnt find it the findHaarFeature?

thx again!

Nathan Oostendorp

unread,
Mar 30, 2012, 10:44:34 AM3/30/12
to simp...@googlegroups.com
First, make sure you're running master -- I think we may have made some updates to scale()

you can just say:

imagescaled = image.scale(90,90)

you don't have to copy first.  90x90 is a bit small, btw for a haar cascade.  I'd go minimum of 300 or so.

Sorry, should have been findHaarFeatures() eg:

Image("lenna").findHaarFeatures("/usr/local/share/opencv/haarcascades/face.xml").show()

tom

unread,
Mar 30, 2012, 10:54:56 AM3/30/12
to simp...@googlegroups.com
well, i did download the windows package, assuming this is all up2date. am i better off using your ubuntu package?

1) findHaarFeatures is being found now (missing 's')

2) my scaled image is not being saved..

3) do u have an example on how to read a result from findHaarFeatures? inspect doesnt work, im all new to python ;-)

thx again!!!

Nathan Oostendorp

unread,
Mar 30, 2012, 11:01:42 AM3/30/12
to simp...@googlegroups.com
Hi Tom,

I'd recommend running through this on the SimpleCV shell, then:

fset_eyes.coordinates()
fset_eyes.width()
fset_eyes.height()
fset_eyes.show()


As far as the image not getting saved, hard to tell without access to your system -- especially since it's getting through the statement in execution.

--n

tom

unread,
Mar 30, 2012, 11:17:57 AM3/30/12
to simp...@googlegroups.com
ok,thx.
fset_eyes.show() doesnt work. (fsetis a Featureset and not an Image), 
but replacing it with this (docs) works:
>>> img = Image("logo")
>>> feat = img.findBlobs()
>>> if feat: feat.draw()
>>> img.show()

how can i force the show() fucntion to leave the window open until i close it manually? it closes automaticaly after half a second or so..

thx again

btw: this is awesome!

tom

unread,
Apr 2, 2012, 9:15:44 AM4/2/12
to simp...@googlegroups.com
hi

ok, the code below works pretty good now, eyes & mouth are being detected. 
1) on some images it shows several rectangles on an eye, why is that?
2) i would like to use this for authentication, what direction would be best to "identify the features", like measurements? shall i find the distance from topleft image to the center of a rectangle?

what would you suggest?

thx

Anthony Oliver

unread,
Apr 2, 2012, 10:24:55 AM4/2/12
to simp...@googlegroups.com
1. The reason it shows that many eyes is that it returns a feature set, or basically the list of all the "eyes" that have been found.  
If you just do:
>>> feat = img.findBlobs()
>>> len(feat)

Should show the length of the list.  If you just want the highest scoring then do:
>>> feat = img.findBlobs()[-1]

2. Using for authentication will require a much deeper understanding of computer vision.  You can get something like:
feat[0].width()

If you want to do recognition it will be more in depth than just using blobs and probably outside the scope of this e-mail.





---------------------------------
Anthony Oliver
Chief Technology Officer
---------------------------------

tom

unread,
Apr 2, 2012, 10:38:05 AM4/2/12
to simp...@googlegroups.com
thx anthony.
ill just try and see how far i get. right now one cascade file identified the mouth as a face, so i've concluded i would iterate tru all xml files to identify 'all' faces, but:

a = [all faces-xml files]
allfaces = image.findHaarFeatures(face default xml)
for x in a:
 faces = image.findHaarFeatures(x) #find faces
 if( faces is not None ):
   allfaces.append(faces)

----

allfaces = allfaces.any().sortArea()
>> AttributeError: 'FeatureSet' object has no attribute 'any'

OR

allfaces = allfaces.sortArea()
 sortArea
    return FeatureSet(sorted(self, key = lambda f: f.area()))
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

isnt FeatureSet based on pythons list?

thx
Reply all
Reply to author
Forward
0 new messages