1 import hypermedia.video.*;
2 import java.awt.Rectangle;
3 import processing.video.*;
5 boolean rec = true; // true: recording
16 PImage[] img_rotated = new PImage[360];
21 String moviePath = selectInput();
23 opencv = new OpenCV( this );
24 opencv.movie( moviePath, width, height );
25 opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT );
27 img_back = loadImage("ahegao_back.png");
30 img_ahegao = loadImage("ahegao.png");
34 mm = new MovieMaker(this, w, h, "ahegao.mov", fps, MovieMaker.VIDEO, MovieMaker.LOSSLESS);
39 void MakeRotatedImage(){
41 img_back.loadPixels();
43 int cx = (int)(img_back.width/2);
44 int cy = (int)(img_back.height/2);
46 for(int i =0; i<360; i++){
47 img_rotated[i] = createImage(img_back.width, img_back.height, ARGB);
50 for(int i =0; i<360; i ++){
52 int tmp_sin = (int)(sin(theta)*1024);
53 int tmp_cos = (int)(cos(theta)*1024);
55 for(int y2 = 0; y2 < img_back.height; y2++){
56 for(int x2 = 0; x2 < img_back.width; x2++){
57 // int x1 = (int)((x2-cx)*cos(theta) - (y2-cy)*sin(theta) +cx);
58 // int y1 = (int)((x2-cx)*sin(theta) + (y2-cy)*cos(theta) +cy);
59 int x1 = (((x2-cx)*tmp_cos - (y2-cy)*tmp_sin) >> 10) +cx;
60 int y1 = (((x2-cx)*tmp_sin + (y2-cy)*tmp_cos) >> 10) +cy;
61 if(x1 >=0 && x1 < img_back.width && y1 >= 0 && y1 < img_back.height){
62 img_rotated[i].pixels[x2+y2*img_back.width] = img_back.pixels[x1+y1*img_back.width];
71 image( opencv.image(), 0, 0 );
72 Rectangle[] faces = opencv.detect();
74 for( int i=0; i<faces.length; i++){
75 image(img_rotated[angle], faces[i].x-faces[i].width*0.2, faces[i].y-faces[i].height*0.2, faces[i].width*1.4, faces[i].height*1.4);
76 image(img_ahegao, faces[i].x+faces[i].width*0.1, faces[i].y+faces[i].height*0.1, faces[i].width*0.8, faces[i].height*0.8);