illuA few months ago a lot of people of the Flash community talked about Marinela, a wonderduf implementation of the Haar detection face done by Ohtsuka Masakazu from the spark project community. In OpenCV, there is another face and hand detection and tracking algorithm called Camshift and described here by Gary Bradski. Camshift uses color information to track object into an image sequence. Not only it can detect object position but also retrieve information about object size and orientation. Furthermore it has the advantages to be easy to implement and computationally efficient, which are really good thing for our Flash Player and my precious time ; -) .So last week I tried to implemented it and to test if it could work in Flash.

The result is better than I thought and makes me really enthusiastic for the following. Of course there is sometimes weird behaviours but it is really a beta version and a lot of optimizations should be done. I worked into RGB color space which maybe is not the best for the sensibility of light changes and I should do image pre-processing on my source image in order to enhance the detection accuracy. I still need to document myself on those points. I also do a lot of 2D loops which are really CPU-killer in Flash!

I needed a good image sequence with a lot of head moves to try it. Gary Brolsma’s video aka “numa guy” was exactly what I wanted :-) . This video is also good for testing the sensibility of the algorithm to the noise, especially when hands and arms, which have the same color than the face, come in front of the head. I also implemented a webcam version which can work pretty well according the lighting and the background color. I notice also a bug sometimes which makes the application fails.

(PS: I also would like to thank my friend Thibault to let me use his head for this demo. Well actually I did not ask him and I do not even have the rights to use it :-P , but I am sure he does not mind, let’s assume it is like a kind of french solidarity :-) )

The Flash plugin is required to view this object.


I will try to explain it in more details and to share source code later, when actually I will have time ! :) . Feel free to talk about it in comments ;-)

Tags: ,
11 Responses to “Camshift: smile you are tracking!”
  1. Well :) What can I say :)

  2. julapy says:

    thats interesting.
    great adventage of this over haar tracking is that it copes well with tilting of the head.
    haar tracking seems to lose the face when that happens.

  3. simurai says:

    Nice! First I thought that guy would be you.. haha.. but then I remembered seeing him on youtube.

  4. Benjamin says:

    @julapy: I am not an expert in computer vision but for me haar method is more used for object detection and camshift is rather for tracking. Mario aka Quasimondo had the good idea to use haar detection for face tracking but I think it’s not the most efficient method for that, especially for Flash. Camshift works differently. It does not search a face but a probablity distribution into the image. That’s why you do not really lose the tracking object when it leaves a bit the image and comes back. But you can use at the beginning haar method to find the face and then following it by camshift. Well I will try to post this week-end more explanations cause some people asked me and I will try to improve it a bit because it is sometimes bugged ! :-)

    @simurai: thanks! Haha unfortunately (or fortunately :-) ) it is not me !

  5. [...] « Camshift: smile you are tracking! [...]

  6. [...] Proyecto Spark (una implementación de Squidder y otra de Quasimodo) implementa Haar, mientras que FaceIt, también en Spark, implementa Camshift (PDF). [...]

  7. Merlin says:

    Excelent stuff.

    Did you optimize the demo for faces somehow? I tried tracking other kinds of objects, but it failed.

  8. Benjamin says:

    @Merlin: You are true somehow camshift is optimized for face detection and tracking because skin color usually are really different of background colors and so it can be easily differentiated with a color detection algorithm. Furthermore the tracking window size in the original algorithm (not in my implementation)) is adapted to track an elliptical shape. I tried with some objects but it’s true it does not work as well with faces. I think it is also due to the fact objects are really small into the image and I had to do some optimizations which cause an important loss of accurancy. I have some ideas to try to improve accurency but I do not have time for the moment :)

  9. Og2t says:

    Nice one, I am going to implement this to try out with MJ’s Black and white head morphing, real acid test for CamShift ;)
    You can see the current result at http://play.blog2t.net/realtime-as3-face-and-eye-detection-with-michael-jackson/

  10. Og2t says:

    Forgot to say I did the haar+camshift experiment (http://play.blog2t.net/files/black-or-white/faceit.html) and it works but it’s veery dependent on the background. I am thinking of trying another approach, by narrowing the camshift area to the head area only.

    @Muki Muki
    Have you been working on anything interesting lately?

  11.  
Leave a Reply