Ask Your Question
0

Why face detection is slow?

asked 2013-04-11 13:50:12 -0500

Bahar Sahin gravatar image

Hello everyone,

I wrote simple code to perform face detection in SimpleCV. It seems to me that it is somewhat slow.

I'm pretty new to SimpleCV and computer vision. I want face detection to be little bit faster but I don't know where to start. Is there a problem with my code or is it related to SimpleCV, or face detection algorithm itself?

from SimpleCV import Camera, Display
def main():
    cam  = Camera()
    disp = Display()
    while disp.isNotDone():
        img = cam.getImage()
        faces = img.findHaarFeatures("face.xml")
        if faces:
            for face in faces:
                face.draw()
        img.show()

if __name__ == "__main__":
    main()

By the way, the video on this link is removed. http://simplecv.tumblr.com/post/8828023826/simplecv-demo-face-detection Is there another link to watch this video?

Thanks in advance

edit retag flag offensive close merge delete

Comments

Thanks for your answer Richard. SimpleCV is very simple and fascinating for me :) I need to perform face detection in a project for one of my courses. I'll take your suggestions into consideration, but I'm sure my professor will strictly recommend me to not use SimpleCV if I fail to optimize :(

Bahar Sahin gravatar imageBahar Sahin ( 2013-04-12 02:44:17 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-04-12 09:42:10 -0500

xamox gravatar image

Indeed this may very well be an issue. It's also a function of image size. One thing you could do is scale the image down, since it is using HaarCascades to do the detection it is scale invariant (meaning scale doesn't matter), but not rotation invariant (it can handle about 15 degrees of rotation both ways).

To modify your code you just need to add a scale and should notice a speed up.

from SimpleCV import Camera, Display
def main():
    cam  = Camera()
    disp = Display()
    while disp.isNotDone():
        img = cam.getImage()
        img = img.scale(0.5)
        faces = img.findHaarFeatures("face.xml")
        if faces:
            for face in faces:
                face.draw()
        img.show()

if __name__ == "__main__":
    main()

Sadly we don't hand drawing transforms, so you can't just find the face and do .draw on the original image. This is something we've been lacking for a little while and probably won't be fixed until SimpleCV 2.0 when we change the rendering engine. You could always do the transformations yourself which would add more code. So basically:

    img = cam.getImage()
    scalesize = 0.5
    scaledimg = img.scale(scalesize)
    faces = scaledimg.findHaarFeatures("face.xml")
    face = faces[0]
    img.drawRect(face.x * (1/scalesize), face.y * (1/scalesize), face.width() * (1/scalesize), face.height() * (1/scalesize)

Hope this helps.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-04-11 13:50:12 -0500

Seen: 9,830 times

Last updated: Apr 12 '13