Replace Your Face Just Like The Laughing Man

Updates below!

I’d like to share two things with all of you.  The first is a dark, personal secret.  The second is a toy I made.

The secret is that for the past few months I have been harboring an unhealthy obsession with the Japanese television series ‘Ghost in the Shell: Standalone Complex.’

What I love about this show the most is one of the recurring bad guys, an impossibly-skilled hacker called the Laughing Man who exhibits a number of extremely bad-ass qualities.

First and foremost, he can hack in to people’s minds and control them.  In the show, he uses this to carry out a series of political assassinations.

During these attacks, he also simultaneously hacks in to all security cameras and news feeds in the surrounding area, and blocks out the face of the person he’s currently controlling with a custom graphic.

This graphic is a smiley face with a baseball cap and a quote from Catcher in the Rye: “I thought what I’d do was, I’d pretend I was one of those deaf-mutes…”

Watching this show the other day, I suddenly realized that I could write a program that did face detection and substitution quite easily.  Once I realized I could do it, I had to.

So I quickly whipped up a program in Processing that does the following:

1)  Opens up a video camera (for example, the web cam in your MacBook).

2) Finds all faces in the frame using the OpenCV library for Processing (installation instructions here).

3) Replaces all faces with the Laughing Man graphic, borrowed from elmex over at ta-sa.org.

Try it out yourself!  It’s minutes of fun for the whole family.  Also, it could be useful in case you ever find yourself in control of some kind of video feed.

The hack-in-to-your-mind thing will have to wait for the time being…

Once you’ve got Processing and OpenCV for Processing installed, download laugh-0.2.tgz.

Update: I’ve merged in changes from the comments!  Text now rotates and the image scales!  Thanks to Josh, Brett, and Deltadesu!

52 thoughts on “Replace Your Face Just Like The Laughing Man”

  1. I made an ettercap filter that accomplishes the same thing, but with all img tags in HTML code. Great project though

  2. Excellent work! I thoroughly enjoyed GITS:SAC many times and had always wondered if someone had written code to do exactly what The Laughing Man had done, but with web cameras. Many thanks and keep up the good work!

  3. Love your sketch, and definately love all of GitS! =D

    After pulling up your sketch on my macbook, I just HAD to muck with it a little ^.^

    I modified it so that the laughing man is scaled to match the face rectangle (with a little extra to account for the round nature of the image). I just wish OpenCV’s face tracking could also do side-views.. I’d love to setup my laptop in the living room and just record all the laughing men at my New Years party tonight ;D

    http://sroz.net/~jnw4775/files/laugh.tgz

  4. i luv it.

    two questions:

    1. it says known bugs: text doesn’t rotate. never, or just in some cases?

    2. How do I get it running in skype?

  5. I messed with your script a bit. It works better for me.
    Mine has to use a square image, though, so I made and uploaded one (http://i39.tinypic.com/2qban3s.png – save as “laugh.png” in the same folder as the script.)

    Changes basically are – the image scales to fit the face, it draws a maximum of one face, and the image is offset slightly so it centers better (for me, anyway).

    The formatting got messed up – see pastebin for proper formatting.

    http://pastebin.com/f66759bd4

  6. I had actually been thinking about trying this idea, but putting it on a digital camera that had face recognition. Nice work 🙂

  7. Can’t get it to work :/
    Using Windows XP… says it can’t find the openCV library after I installed it.

    Hopefully I can manage to figure this out… sick of my Mac friends showing off with Quartz Composer 😛

  8. I’m trying to use this, and I’ve got all the necessary files, as well as Processing installed, but I keep getting the same error:

    !!! library OpenCV not found

    Exception in thread “Animation Thread” java.lang.UnsatisfiedLinkError: hypermedia.video.OpenCV.capture(III)V
    at hypermedia.video.OpenCV.capture(Native Method)
    at hypermedia.video.OpenCV.capture(OpenCV.java:917)
    at laugh.setup(laugh.java:63)
    at processing.core.PApplet.handleDraw(PApplet.java:1383)
    at processing.core.PApplet.run(PApplet.java:1311)
    at java.lang.Thread.run(Unknown Source)

    Any idea what the problem is? This looks like a really neat project.

  9. It would be better if the text rotated just like in the show. Then it would be the ultimate.

  10. Ah, yes, there seems to be a problem for windows xp users. :-/ I wonder if it’s actually a problem with the opencv libraries for Processing.. it seems that way.

    I’ll keep looking for a solution and post it up if I find it. I want to modify this code for use with Instant Messengers. =D

  11. I saw this on hack-a-day and had to pop down and see it. I loved GitS, I was wondering how long it would take till someone made a hack or program with the laughing man image.

  12. If you flip the image, it becomes more like a mirror, and your right-left movement is a bit easier.

    To do this, I added the following line to the code, at line number 67 (below the opencv.brightness( brightness_value ); line):

    opencv.flip( OpenCV.FLIP_HORIZONTAL );

    This is the first time I use Processing, so there might be a better way to do it, but it works for me.

  13. for all windows xp users experiencing
    !!! library OpenCV not found’ problem there is such solution:

    RMB on My Computer, then go to ‘Advanced’ tab, there click ‘enviroment variables’ button, and in the bottom dialog box search for ‘Path’ variable. Click ‘Edit’ and add something like this to the end of what you get in ‘Edit System Variable’ window (it shows up right after clicking ‘Edit’ button):
    ‘;C:\Program Files (x86)\OpenCV\bin’

    IT MUST BE PATH CORRESPONDING TO YOUR OPENCV INSTALL DIR and there ‘\bin’ folder. add it without quotes. cheers.

  14. Hey, I stumbled upon this through Hack a Day and thought it was pretty cool. I’m having an issue with it though. I’m not sure if its due to my ignorance of the program, or if Vista has failed me once again, but, I’m getting this :
    UnsatisfiedLinkError: hypermedia.video.OpenCV.capture(III)V

    !!! library OpenCV not found

    Exception in thread “Animation Thread” java.lang.UnsatisfiedLinkError: hypermedia.video.OpenCV.capture(III)V
    at hypermedia.video.OpenCV.capture(Native Method)
    at hypermedia.video.OpenCV.capture(OpenCV.java:917)
    at laugh.setup(laugh.java:62)
    at processing.core.PApplet.handleDraw(PApplet.java:1383)
    at processing.core.PApplet.run(PApplet.java:1311)
    at java.lang.Thread.run(Unknown Source)

    And, It highlights line 43 :
    opencv.capture( width, height ); // open video stream

    Just wondering if I maybe installed something wrong or don’t have everything I need for it to work correctly.
    If anyone has any suggestions, please email me at error503.0@gmail.com
    Thanks 😀

  15. Same problem as Jake Maheu. I would love to get this working. Any help would be appreciated.

    AIM/Skype/Y!: ItsBlueB

  16. This error on windows xp

    OpenCV face detection sample

    !!! library OpenCV not found

    Exception in thread “main” java.lang.UnsatisfiedLinkError: hypermedia.video.OpenCV.capture(III)V
    at hypermedia.video.OpenCV.capture(Native Method)
    at hypermedia.video.OpenCV.capture(OpenCV.java:917)
    at FaceDetection.(FaceDetection.java:52)
    at FaceDetection.main(FaceDetection.java:128)
    Java Result: 1

    anyone any idea?? 🙂

  17. i have the same “library openCV not found” in windows but i solved it when i read all the instalations instructions http://ubaa.net/shared/processing/opencv/

    “Download, unzip, and move the OpenCV Processing Library into your Processing libraries folder, or for Java users copy the content of the library folder in one of your Java Extensions folder.”

    and them reboot !

    the problem is that i dont have a web cam 😛
    i try whit “fake cam” and get this :

    Error while starting capture : device 0
    OpenCV could not define source dimensions.

    i try replacing opencv.capture by opencv.movie

    and them dont show red lines but this:
    “The haar classifier cascade file ‘haarcascade_frontalface_alt.xml’ can not be found in folders, you must specify the full path instead.”

    dont have any idea where is this xml file

  18. ok, my bad, the file is in the opencv directory , i just copy it to the “sketch directory” and it works ^_^

    but i dont understand at all the script, why it “translate” the face y+140 and x+140? i change it because my faces dont apears in her place

    pd: sorry for my horrible english :S

  19. This is pretty awesome! Works like a charm and is right up my GitS alley. A question that indicates my ineptitude, however. Can this be used to edit video being streamed via IMs or chatrooms? If so, how?

  20. I have gotten this pretty close to working. Being a complete beginner with this software, I got as far as getting this highlighted
    p1.resize(360,0);
    The file “ltext.png” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    The file “limg.png” is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
    Exception in thread “Animation Thread” java.lang.NullPointerException
    at sketch_jan20a.setup(sketch_jan20a.java:66)
    at processing.core.PApplet.handleDraw(PApplet.java:1383)
    at processing.core.PApplet.run(PApplet.java:1311)
    at java.lang.Thread.run(Unknown Source)
    any help would be awesome, thx!

  21. Pretty cool! One thing has been bothering me: the image does not stay centered on the face when auto-scaling is implemented.

    The solution was to replace the line:
    translate(lastfaces[i].x+110, lastfaces[i].y+110);

    with something more like this:
    float transX = lastfaces[i].x + (lastfaces[i].width / 2);
    float transY = lastfaces[i].y + (lastfaces[i].height / 2.3);
    translate(transX, transY);

    The I found that using 2.3 above gave slightly better vertical positioning. I also changed the scaling on the overlay, but that is probably just personal preference.

    If anyone is interested in trying the changes, the files can be downloaded here: http://www.filedropper.com/laughalt

    Thanks again for the cool app!

  22. isnt the rotating text is REVERSED? O_o

    if i remember correctly, it should rotate counter-clockwise.

    btw THAAAAANKS a lot for this fun hack.

    btw is there a way to use this directly on IM?

    i currently use webcam+handycam+second LCD monitor to stream my THe Laughing Man face on IM >_<

    thanks

  23. btw the apps run very slow on my laptop. the video look very low fps, the spinning text also spin slowly.

    is there any minimum cpu speed to be able to produce the laughing man?

    it eat 100% on my 1.8GHz coreduo cpu core 0 >_<

    thanks a lot. creative work

  24. btw i edited your script to make the text move counter-clockwise and run more smoothly on my slow CPU.

    here :

    import processing.xml.*;
    import hypermedia.video.*;

    /*

    REQUIRES:
    OpenCV library for Processing

    CHANGELOG:
    1/5/09 – Incorporated fixes from Josh, Brett, & Deltadesu: Text now rotates and image scales! Thanks guys!

    KNOWN BUGS:
    1) Fast movement head movement will lose the head-tracker for a second.
    2) Still some flicker issues, but better than it was…
    3) Must tinker with OpenCV a bit to get profiles working as well as frontal faces!

    No express purpose is intended or implied, use at own risk.

    Ben Kurtz
    awgh@awgh.org
    12/15/08

    */

    OpenCV opencv;

    // contrast/brightness values
    int contrast_value = 0;
    int brightness_value = 0;

    Rectangle[] lastfaces;

    PFont font;
    String s;
    PImage img;
    float angle;
    PImage p1;
    PImage p2;
    float n = 1;

    void setup()
    {
    size(640,480);
    frameRate( 7 );

    smooth();
    stroke(255);
    fill(255);

    p1 = loadImage(“ltext.png”);
    p2 = loadImage(“limg.png”);
    p1.resize(360,0);
    p2.resize(360,0);
    //I thought what I’d do was, I’d pretend I was one of those deaf-mutes

    opencv = new OpenCV( this );
    opencv.capture( width, height ); // open video stream
    opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); // load detection description, here-> front face detection : “haarcascade_frontalface_alt.xml”

    // print usage
    println( “Drag mouse on X-axis inside this sketch window to change contrast” );
    println( “Drag mouse on Y-axis inside this sketch window to change brightness” );

    }

    public void stop() {
    opencv.stop();
    super.stop();
    }

    void draw() {
    angle = angle – 0.3;

    try{

    // grab a new frame
    // and convert to gray
    opencv.read();
    //opencv.convert( GRAY );
    opencv.contrast( contrast_value );
    opencv.brightness( brightness_value );

    // proceed detection
    Rectangle[] faces = opencv.detect( 1.2, 2, OpenCV.HAAR_DO_CANNY_PRUNING, 40, 40 );

    // display the image
    image( opencv.image(), 0, 0 );

    // to smooth it out
    if( faces.length > 0 ) {
    lastfaces = faces;
    }

    if( lastfaces != null ) {
    for( int i=0; i scaleFactorH) ? scaleFactorW : scaleFactorH;
    if( scaleFactor < 0 ) scaleFactor = -scaleFactor;
    scale(scaleFactor * 1.2);

    ellipse(0,0,280,280);

    rotate(angle);
    image(p1,0,0);

    rotate(-angle);
    image(p2,0,0);

    imageMode(CORNER);
    rectMode(CORNER);
    }

    popMatrix();
    }
    }

    } catch(Exception e) { e.printStackTrace(); }
    }

    /**
    * Changes contrast/brigthness values
    */
    void mouseDragged() {
    contrast_value = (int) map( mouseX, 0, width, -128, 128 );
    brightness_value = (int) map( mouseY, 0, width, -128, 128 );
    }

  25. hi all,

    i am running ubuntu 8.10 intrepid using opencv 1.0 library and latest processing version (processing-1.0.1).
    I am having also the “”!!! library OpenCV not found” error. I’ve tried other version of processing as well as older versions of opencv. Still couldn’t manage to execute it?

    Are there any Linux user who’ve tried opencv and processing together?

  26. Hi there,

    awsome project 🙂

    I’m using Windows, have already gone trough all the tips given here by both you and the users. But I still couldn’t manage to get everything working. The error message is:

    The package “hypermedia” does not exist. You might be missing a library.

    I also created a libraries-folder in the sketchbook-folder etc. but the error is still there 🙁

    Any suggestions?

    Greetings

  27. I changed the translate line so if the face is far away the image will still be on top of the face.

    From this:
    translate(lastfaces[i].x+110, lastfaces[i].y+110);

    to this:
    int blah = (lastfaces[i].width)/2;
    translate(lastfaces[i].x+blah, lastfaces[i].y+blah);

  28. Note that release 1.0, libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.

    what does this mean and how do I fix it?

  29. Wow this is pretty amazing =) I think its cool someone took the time to create something from an anime since the majority of the times the ideas are pretty far fetched =)

  30. Love the hack. Can’t wait to impliment it.

    Now if only there was a way to hack my school’s security cameras to see the image…

  31. Hi there, this sounds like a fun project, I’m a BIG Masamune Shirow fan and I loved the GITS series. Nyx- told me to try this out, unfortunately I’ve encountered what the other Windows users here experienced even though I’ve tried the solutions suggested by the other members here:

    ‘Note that release 1.0, libraries must be installed in a folder named ‘libraries’ inside the ‘sketchbook’ folder.’

    I’m not very familiar with this language and tinkering with it seems to make it worse. 🙁

    I’m using XP. Will just keep on checking back here. Thank you. 🙂

  32. Well I want to use this so bad. But so far it is not working,
    BUT to answer some questions there is a second link in the OpenCV library. It is listed as #2. You download that and un-zip it and paste it to the folder that says \libraries at wherever you installed it. For me that solved the hypermedia problem and OpenCV library not found. I am running Windows Vista. (I know right)

    My problem is that when I try to run it I says
    Cannot find a class or type named “Rectangle”

  33. IT works.!

    problems encountered. With Solutions!

    Problem:
    Cannot find a Class or type named “Rectangle”

    Solution:
    paste this without the quotes up by the other import commands.
    “import java.awt.Rectangle;”


    Problem:
    The haar classifier cascade file missing?

    “haarcascade_frontalface_alt.xml” can not be found

    solution:
    Copy the”haarcascade_frontalface_alt.xml” file from
    C:\Program Files\OpenCV\data\haarcascades .

    and paste it Into the folder you are working out of.
    (I.E. The Laughing folder where all the images are)
    C:\Program Files\Projects\processing-1.2.1\libraries\laugh

    or

    replace “OpenCV.CASCADE_FRONTALFACE_ALT ” with the directory for the .XML file

    Example.

    “C:\\Program Files\\OpenCV\\data\\haarcascades\\haarcascade_frontalface_alt.xml” .

    remember to Double \ and INCLUDE the Quotes”!

    —–
    running
    prosessing 1.2.1 with java.
    openCV 1.0
    OpenCV library from the blog.

    special note. Open CV only runs on a 32 bit OS. i tried it on windows 7 (installed in to the X84 program files) and openCV failed to launch.
    currently using windows XP.

    good luck
    hope this helps
    and enjoy.

  34. Hi all,

    i am using windows 7 and trying to run OpenCV facedetection example using netbeans 6.9.1 but no success 🙁 …

    Exception in thread “main” java.lang.UnsatisfiedLinkError: video.OpenCV.capture(III)V
    at video.OpenCV.capture(Native Method)
    at ideo.OpenCV.capture(OpenCV.java:925)
    at opencv_facedetection.Detector.(Detector.java:51)
    at opencv_facedetection.Main.main(Main.java:19)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 2 seconds)

    any suggestions ???
    thanks.

  35. you should put a video on Youtube, you know, for those of us that are not as good with the program. we would greatly appreciate it.

Leave a Reply

Your email address will not be published.