Weblog / Blog article: Marilena : source code of the Glasses Demo
-->

Marilena : source code of the Glasses Demo

Posted by François On May - 25 - 2009

Somebody remind me that I forgot to share the project of my demo using the Marilena project (OpenCV port).

So here is the source code, nothing fancy, nothing complicated, just a real basic use, but I guess it will help some of you who are interested.

This code is compiled with free tools as Flex SDK, Flash Develop , the optimized version of Marilena by Mario Klingemann and the AS3 Tweenlite class. If you never setup this kind of IDE before I highly recommend this tutorial which will help you with all the settings !

I’m not a programmer so this code is way too simple and not optimized at all, so feel free to re-use it as you want :)

Related Link :

Share and Enjoy:
  • Twitter
  • Facebook
  • LinkedIn
  • StumbleUpon
  • Posterous
  • Tumblr
  • Digg
  • FriendFeed
  • del.icio.us
  • Netvibes
  • RSS
  • email
  • Print
  • PDF
  • Google Bookmarks
  • Blogplay

62 Responses to “Marilena : source code of the Glasses Demo”

  1. Ameni says:

    i’m veryyyy pleased if u explain me the pictures in the link.

  2. Ameni says:

    Well for me, doing such kind ov application in ur sparetime is a very greatfull thing. really nice work Froinçois.
    but i still have a prob wich is :understanding the steps that enable “openCv to detect the face”?

    PS: http://www.cognotics.com/opencv/servo_2007_series/part_1/sidebar.html

    this link explain how openCv works but it’s written in English witch i could not well understand :(

  3. François says:

    I know exactly what you want, and I’m telling you again, if it was that easy, everyone would have done it by now :)
    you are talking about 3d tracking now ! and retrieving 3d matrix from a point cloud ! check out the try I did with KLT feature (http://www.francois-tarlier.com/blog/index.php/2009/07/klt-feature-detection-port-to-as3/) this is only feature detection. Do you see how slow it is ? well you would have to make a model of this, and compute a matrix on top of that. Heavy computation for AS3 I’m telling you. Is it possible ? maybe ! will it be slow ? for sure ! Do I know how to do it ? not a clue ! :D

    So as I told you before if you really want to dive into this, and if you are a computer vision programmer, then dive into OpenCV, take a look at what they did. Take a look at ASM and AAM. if you can try to port it to AS3.
    Otherwise, in the mean time, all you can do it’s bit of hack. I never used FaceIt, but by seeing it, well first it does give at least one more rotation, and then, you can maybe figure a kind of rotation based on the with of the cross. Again, just a hack to work things around, not accurate at all. but honestly I don’t know how you can do it otherwise in the time being !
    if it was easy or if I knew how to do it, I would have done it already for this demo :) !

    Plus I only did that for fun in the first place, I’m not a programmer and not working on this full time at all.

  4. Ameni says:

    but it’s not what i want.
    i need the Z rotation. Did u understand me?

  5. Ameni says:

    hhh it’s okay i undersdoud how to use it ^^ . i’m a little bit confused

  6. Ameni says:

    sorry, it appears “not found” ..

  7. Ameni says:

    also i can’t open the link of “how to use”. it apperes the 404 page :( (( so what shall i do ?

  8. Ameni says:

    hello,
    :( i’ve donwlaoded the faceit project but it doesn’t worked for me! what’s wrong with it ???

  9. François says:

    well if it was that easy, the same smart guy who did the Marilena would have done it already :p !

    Anyway what could be a bit of a hack would be using camshift algorithm. they already did the port here : FaceIt http://www.libspark.org/wiki/benj/FaceIt/en

    But I have said before and many times, there is a use difference between Face detection/recognition, and Face Tracking. what you want to do is more like a face tracking (which is actually a surface tracking or point tracking) in time.

    OpenCV face recognition do not track, it recognize A head at each frame, without any awareness of the previous frame and previous recognition.

  10. Ameni says:

    Hi again François,
    can u help me to know how can i rotate the glasses while turning (on the right /left side) my face?
    have u any idea ?
    thank u very much

  11. damon83 says:

    OK I think with the flash code of http://www.squidder.com/2009/02/26/realtime-face-detection-in-flash/ I can start trying it…thanks anyway!

  12. damon83 says:

    Hey François!! excellent application, is working very well for me, and that’s exactly what I needed, thanks. I’d be very interested in capture streams of video of people connected with the mask when clicking on a rec botton. I don’t know if this is possible to be integrated with your code, or how I can to achieve that feature. I’ve found loads of examples but not using CameraBitmap class…is it possible?? Thanks!

  13. Ameni says:

    okay thank u

  14. François says:

    well try his twitter account then http://twitter.com/quasimondo
    All this is based on OpenCV head detection lib, if you really want to dive into face recognition, then dive into OpenCV, read the docs and tutorial on the internet. in a previous comment, I explain to Eomer how the process of recognition with Haar file works.
    Again, if you really want to know how the low level of this works, go look at OpenCV lib. You even better get into the C version instead of playing with the Flash one :p . Anyway, if you want to get dirty, I hope you have some strong baggage with computer vision and stuff because it is complicated :)
    A good starting point would be to buy this book : http://www.amazon.com/dp/0596516134?tag=francoi-20&camp=14573&creative=327641&linkCode=as1&creativeASIN=0596516134&adid=1WCYWTDEQMPW7DT9YTWR&

  15. Ameni says:

    hi again,
    i tried to ask Mario about the marilena lib but an error has occurented : “Comments are not allowed on this entry”.

  16. Ameni says:

    have you any idea how the face detection works in this code ?if not, who am i supposed to ask ?

  17. Ameni says:

    :) me too, i’m new in this subject that’s why i have many questions…
    now, i’m trying to capture the image of the cam with the sunglasses :)

  18. François says:

    :) thx, but I am not a pro at all about this subject. I have been reading about it a lot, working with a lot of people on the subject, but I don’t exactly how all this things work. I’m not a programmer and I just have a few knowledge on the topic about how mostly those things work just by asking to the pros around me :p

    So You can keep asking, but there is probably more qualified people out there to answer your question, anyway I’ll try to answer if I can

  19. Ameni says:

    and it seems that u’r the only person tha’s able to answer me:\ so if u don’t minde tell me to continue for asking ^^

  20. Ameni says:

    i’m really sorry for disturbing u but i have many questions to ask `:\

  21. Ameni says:

    well you’re realy pro person :)

  22. François says:

    it is the same code, they are using Marilena as well :p . Except I am using the optimized version of Marilena by Mario (see link in the post) while they are using the original Marilena. I don’t know exactly all the modification that did Mario on it, but the biggest part and which improve the framerate, is to hardcode the “Haar cascade file” directly in the AS code instead of using an xml parser with an external file. But if you want more precision and more exact stuff about it, you should ask him.
    Anyway both Marilena works the same way except the optimized got the head haar file hard coded.

    So what is an Haar file ? I kind of explained it in a previous comment or previous post, but basically it’s a database of heads.
    Usually to create such a file, you get thousand of picture of heads. Then you place several markers on each of those faces (on the features : corner of mouth, corner of eyes, eyes, …). And Finally you put all those thing into a program which will give you an xml file of this database. (I cannot explain it more simply than that, but it’s actually a bit more complex :p )
    You have loads of documentation on the web about this, and how to create your own Haar!! (as http://note.sonots.com/SciSoftware/haartraining.html) But good for you, you don’t have to, since OpenCV provide several Haar cascade file, and you can also find some other around the Internet. :)

  23. Ameni says:

    okay :) thank u again, but can u explaine me what’s the “Haar cascade file”.because, i found a free code:
    http://www.squidder.com/2009/02/26/realtime-face-detection-in-flash/
    that uses “haar ccascade” in the XML file .
    the code does’nt seems like your code it’s a little bit advanced .i tryed to understand it but in vain …
    :\

  24. François says:

    Yes it is the code I’m running in FlashDevelop, but I am not using Flash as a compile engine. I’m using FlexSDK. Using both FlashDevelop & FlexSDK let you developp AS code for free. Please check out the tutorial link for more information.

    I don’t know if it will works by just copy&paste it inside Flex. I don’t use Flex directly, only the SDK to compile the code, that’s all.

    For the glasses, if I remember correctly, the detector return the center of the head with its scale. The position of the glasses’ sprite is only an offset from this position. just adjust the delta (or add one) and you’ll be good to go.

    You can’t detect eyes, at least not with this Haar cascade file. you would have to change it, but if you do so, I would recommend you use the none optimized version of Marilena, which use external XML haar cascade file.

    The one I’m using in this, only detect faces. for the glasses I’m only assuming that eyes are in the upper part of the head. All this happen in the detectionHandler() function at the bottom of the code

  25. Ameni says:

    i fixed the problem by using the marilena code and comparing it with this code and it works great but while loading the glasses, the position is mush more up to the eyes location !
    how can i get the exact location ?
    but how can i detect the eyes location using marilena?

  26. Ameni says:

    hi François,
    thank u for tring to help me.i’m very pleased.
    the problem is at line 160.i think that the probleme is coming from “detector.detect( detectionMap );”.!
    did u test the code urself in flashDevelop ?
    what if i copy it in flex ?does it return me any success?thks very much

  27. François says:

    well you got your reason here. I don’t quite remember why it does that, but I know I had this issue and probably had to tweak the code so it would work on Flex :p
    Do you know which at which line this does happen ? I don’t have Flash, that’s why I’m using FlashDevelop with FlexSDK !
    If it does happen in the CameraBitmap() Class, then please ask to Mario, this is his class I did use to grab the webcam. That’s a really nice AS Camera Lib he did which grab the camera and transform it to bitmap data with a lot of method. But I don’t know if it does work or how it does work in Flash.
    Anyway, I pretty sure just copy&paste the code like that in Flash won’t work. You will have to tweak the code a bit

  28. Ameni says:

    P.S : i’m using flash CS4 with AS3.0 and not flex
    i just copied the code and paste it in flash after exporting all the packages i need

  29. Ameni says:

    i’m very greatfull for your help

  30. Ameni says:

    Hi Admin,
    firstly, iwould like to think you for your help
    but i have a problem while trying to execute the code :
    1067: Contrainte implicite d’une valeur du type flash.display:BitmapData vers un type sans rapport flash.display:Bitmap.
    pleeeease, i need your help

  31. François says:

    depends on the database you want to use. If you want to learn the face of the user and later retrieve it into a database, you can try this : http://code.google.com/p/in-spirit/wiki/ASSURF

    But I’m not sure it is accurate enough for this kind of approach though.

  32. dontPanic says:

    hey firstly, nicely done..
    we have been working on a project which involves Marilena. we want to add face recognition part either. we will identify the faces by connecting to a database but we couldnt figure out how to do it without OpenCV on flash.you guys have any idea???

  33. eomer says:

    soory
    i cant see the picture and i cant download anything to this computer

  34. admin says:

    sure, use the form to contact me the first time, I’ll respond to your mail then
    http://www.francois-tarlier.com/blog/index.php/contact/

  35. eomer says:

    yes i wrote an if statement if the eyes rect coordinates are not in face rect coordinates it wont continue

    i also used eye cascade for detecting the eyes seperately it didnt change

    i will take a look at ASM and AAM right now
    if its ok for you can i asked my futher questions with email it wiil be easier

  36. admin says:

    are you always looking for eyes or only when you get the face ?
    Isn’t there another cascade file for just one eyes ? the issue you encounter is that if it just miss one eyes, then it won’t show any at all. But this is not exactly how it works.
    Do you know how the cascade file is working ? it’s pretty much like a tree with patches. each time it valids a patch it goes to the next one, and so on. so first it looks for a big patch and go smaller and smaller, but if it miss one step, you restart from beginning. Still not exactly how it works but give you the big picture. (there is a nice scheme explanation about haar feature here : http://www.emeraldinsight.com/Insight/ViewContentServlet?Filename=Published/EmeraldFullTextArticle/Articles/0490340109.html)

    but if you are using openCV and C, I recommand you take a look at ASM (active shape modeling) & AAM (active Apparence Model) which is so much better. (the approach of faceapi by the way)

  37. eomer says:

    haarcascade_mcs_eyepair_big.xml for eyes (takes both eyes in one rect)
    and haarcascade_frontalface_alt_tree2.xml for face

  38. admin says:

    what are you using ? which cascade file are you using ?

  39. eomer says:

    hi,
    i am writing the same project but not using flash (opencv + C)
    i detect face & eyes and put a jpeg image in detected eye
    i encountered some problems: first the detection works with very low performance detection stops when i move my head
    the second problem is eye detection work only when i look directly to CAM.
    your program works even i dont look directly to CAM

    how can i solve these problems pls help

  40. admin says:

    yes as I said, you have to download the AS3 Tweenlite here : http://blog.greensock.com/tweenliteas3/

    @Ilya : what do you want to know ? the code is pretty simple. I’m just using functions of the Marilena Lib. I start it from Mario Klingemann examples (see the link above)

  41. Ilya says:

    I am more then curious to know how you did that?

  42. Ilya says:

    This code is not full, its just one of the packeges. Need the gs packeg to run it as well as the main file

  43. [...] – Marilena.  W tym celu warto zapoznać się z kodem z dema Mario Klingemanna albo z kodem z dema Francois [...]

  44. admin says:

    sorry I didn’t answer you before, I was busy, could if you find the solution though ;)

  45. clongleung says:

    Sorry, my last question problem and error is [1067: Implicit coercion of a value of type flash.display:BitmapData to an unrelated type flash.display:Bitmap.]

    thanks a lot.

    clongleung

  46. clongleung says:

    Hi admin,

    I have tried to setup Flash developer and setup the Flex DSK already. but still have a error with:

    C:\Users\admin\Desktop\face\gs\ObjectDetectorEvent.as:1: 5001: The name of package ‘jp.maaash.ObjectDetection’ does not reflect the location of this file. Please change the package definition’s name inside this file, or move the file. C:\Users\admin\Desktop\face\gs\ObjectDetectorEvent.as

    May I know how can I fix this error, many thanks =D

  47. admin says:

    Hum, that’s weird.

    Are you using Flex SDK to compile it ? did you download all the library and stuff ?
    which line is the error ?

  48. clongleung says:

    HI Dear,

    I have try the coding but got a error:[1046: Type was not found or was not a compile-time constant: ObjectDetectorEvent.]

    may I know what am I missing? thanks a lot

    Clongleung

Leave a Reply

VIDEO

TAG CLOUD

About Me

about me..

Twitter

    Photos

    very 1rst 3d render (2002)Old tractorOld tractorDépotoirMoi tchou-tchouJulia tchou-tchouQuai gare de MauriacGare de MauriacLumière de Noël à Mauriacbuche de noelMamanDad & MeSaint CucufaJulia au lac de Saint-cucufaJulia PiscineJulia summer