Replace Your Face Just Like The Laughing Man

by awgh on December 15, 2008 · 52 comments

in Fun

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!

{ 47 comments… read them below or add one }

Arius December 31, 2008 at 1:14 pm

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

Matt Katz December 31, 2008 at 1:27 pm

awesome work! I just got into processing – you might want to throw this up on http://www.openprocessing.org. I think it will eventually turn into a github sort of thing for processing folks.

I’m http://openprocessing.org/portal/?userID=647 on openprocesssing.

Andy December 31, 2008 at 1:54 pm

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!

Josh December 31, 2008 at 2:30 pm

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

calin2k December 31, 2008 at 2:43 pm

any chance for a xp version? :|

noel December 31, 2008 at 4:37 pm

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?

Deltadesu December 31, 2008 at 4:44 pm

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

Deltadesu December 31, 2008 at 7:05 pm

I revised it again so it’s animated.
It’s a hack – I took an animated .gif, split it into a different file for each frame, and modified the script to load a different file each time.

Requires you download http://athingworthhaving.googlepages.com/b.zip and unzip to “b” in the script folder. Yes, it’s extremely low quality – I couldn’t find anything higher.

Revised script – http://pastebin.com/f5ba12f59

Frogon December 31, 2008 at 9:15 pm

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

Brett January 1, 2009 at 12:22 am

I just had to hack this when i saw it. Here’s an edited version of the program with rotating text.
http://depositfiles.com/files/9xclwx75t

TheKhakinator January 1, 2009 at 12:29 am

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 :P

Jake Maheu January 1, 2009 at 11:12 am

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.

Nate_the_Ace January 1, 2009 at 5:22 pm

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

minoruhackerguy January 2, 2009 at 3:01 am

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

Shanahan January 2, 2009 at 7:27 am

Way cool. I was not aware of the open source CV library. this is a great application of same.

KHobbits January 2, 2009 at 10:42 am

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.

Jan Fabry January 3, 2009 at 6:17 am

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.

sapphired January 3, 2009 at 12:39 pm

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.

Noob V2.1 January 3, 2009 at 8:12 pm

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 :D

ItsBlueB January 4, 2009 at 2:42 pm

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

AIM/Skype/Y!: ItsBlueB

Matt January 5, 2009 at 3:40 pm

Inspired by Josh’s script above, and the broken down images from the image source above, I whipped up an animated, auto-scaling version.

http://www.filedropper.com/laugh

Oni Jones January 8, 2009 at 9:06 pm

I get an error message that says:

Initializing libguide.lib but fount libguide40.lib already initialized.

How do I fix this?

Rogier January 11, 2009 at 7:36 am

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?? :-)

pepe January 12, 2009 at 8:43 am

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 :P
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

pepe January 12, 2009 at 9:44 am

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

Aoi January 18, 2009 at 3:31 am

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?

TheLaughingMan January 20, 2009 at 6:12 pm

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!

taske January 21, 2009 at 2:53 am

Got same problem like other XP user,
!!! library OpenCV not found

Which I found that it cause from install the wrong version of openCV, qoute from http://ubaa.net/shared/processing/opencv/

“download the OpenCV release version 1.0 (NOT the 1.1pre1) “

chaos February 1, 2009 at 9:05 pm

im getting this error when running unsatisfied link error

Greg Medding February 4, 2009 at 11:04 pm

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!

orangpelupa February 8, 2009 at 9:12 am

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

orangpelupa February 8, 2009 at 9:49 am

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

orangpelupa February 9, 2009 at 11:29 pm

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 );
}

ritzdank February 18, 2009 at 3:00 am

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?

Jcom February 22, 2009 at 2:22 pm

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

omi April 11, 2009 at 10:22 am

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);

Exarch July 5, 2009 at 11:42 am

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?

Nyx- August 2, 2009 at 1:20 am

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 =)

sandra407 September 9, 2009 at 9:10 am

Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

William September 30, 2009 at 12:06 am

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…

s0rath October 4, 2009 at 5:19 am

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. :)

Brown May 6, 2010 at 5:27 pm

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”

Ross July 15, 2010 at 9:23 pm

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.

thusi777mora April 19, 2011 at 10:22 am

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.

eliseo May 7, 2011 at 12:06 pm

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.

Papa Dilbert June 16, 2011 at 3:31 pm

What about substituting faces on live broadcasts? I would like to goo and substitute faces in real time tv broadcasts….similar to face substitution of some webcam softare. Would the openCV be a possible starting point?

m041633n September 10, 2011 at 1:49 pm

Cool inspiring project! Long live laughing man

Leave a Comment

{ 5 trackbacks }

Next post: