Created
January 25, 2011 13:44
-
-
Save rafapolo/794928 to your computer and use it in GitHub Desktop.
Damnatio Memoriae is a conceptual-virus that appends a black stripe over jpeg images with faces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
====================== | |
~ Damnatio Memoriae ~ | |
====================== | |
a conceptual-virus that appends a black stripe over jpeg images with faces | |
====================== | |
author | Rafael Polo | |
====================== | |
Memefest | International festival of radical communication memefest.org | |
====================== | |
Do What The Fuck You Want To Public License | |
====================== | |
updated_at | 25.jan.2011 | |
====================== | |
*/ | |
import hypermedia.video.*; | |
import java.awt.Rectangle; | |
import javax.swing.JOptionPane; | |
OpenCV opencv; | |
void setup() { | |
opencv = new OpenCV(this); | |
opencv.capture(width, height); | |
opencv.cascade("haarcascade_frontalface_alt.xml"); // load face patterns | |
File firstPath = new File(System.getProperty("user.home")); | |
fill(0); // black blackground rectangle | |
vaiAbrindo(firstPath); | |
} | |
public void vaiAbrindo(File file) { | |
// open folders recursively | |
if (file.isDirectory()) { | |
String[] children = file.list(); | |
for (int i=0; i<children.length; i++) { | |
vaiAbrindo(new File(file, children[i])); | |
} | |
} | |
else { | |
// look file if it is an imagem with less than 1mb | |
if (file.getName().endsWith(".jpg") && (file.length()<1024*1024)) { | |
look(file); | |
} | |
} | |
} | |
public void look(File file) { | |
String path = file.getPath(); | |
// load image | |
PImage img = loadImage(path); | |
size(img.width, img.height); | |
opencv.loadImage(path); | |
image(opencv.image(), 0, 0); | |
// detect faces | |
Rectangle[] faces = opencv.detect(); | |
// has faces? | |
if (faces.length>0) { | |
// save image for latter antidote | |
File bak = new File(path+".bak"); | |
if (!bak.exists()) { | |
file.renameTo(bak); | |
// censor faces | |
censor(faces); | |
save(path); | |
} | |
} | |
} | |
public void censor(Rectangle[] faces) { | |
for( int i=0; i<faces.length; i++ ) { | |
int faceOrMount = Random.nextBololean() ? faces[i].y * 0.33 : faces[i].y * 0.11; // random | |
rect(faces[i].x, faceOrMount, faces[i].width, faces[i].height); | |
} | |
} | |
// code is poetry |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
about: http://mostre.me/damnatio-memoriae