From d83147d83eab88f47a7afe842c4e4e3dcfffdc57 Mon Sep 17 00:00:00 2001 From: karaage0703 Date: Sat, 8 Feb 2014 18:43:27 +0900 Subject: [PATCH] new version --- AhegaoMan.pde | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 AhegaoMan.pde diff --git a/AhegaoMan.pde b/AhegaoMan.pde new file mode 100644 index 0000000..e18207f --- /dev/null +++ b/AhegaoMan.pde @@ -0,0 +1,97 @@ +import hypermedia.video.*; +import java.awt.Rectangle; +import processing.video.*; + +boolean rec = true; // true: recording +int fps = 30; +int w = 1280; +int h = 720; +int angle = 0; + +OpenCV opencv; +MovieMaker mm; + +PImage img_back; +PImage img_ahegao; +PImage[] img_rotated = new PImage[360]; + +void setup() { + size( w, h ); + + String moviePath = selectInput(); + + opencv = new OpenCV( this ); + opencv.movie( moviePath, width, height ); + opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); + + img_back = loadImage("ahegao_back.png"); + MakeRotatedImage(); + + img_ahegao = loadImage("ahegao.png"); + imageMode(CORNER); + + if(rec){ + mm = new MovieMaker(this, w, h, "ahegao.mov", fps, MovieMaker.VIDEO, MovieMaker.LOSSLESS); + frameRate(fps); + } +} + +void MakeRotatedImage(){ + float theta = 0; + img_back.loadPixels(); + + int cx = (int)(img_back.width/2); + int cy = (int)(img_back.height/2); + + for(int i =0; i<360; i++){ + img_rotated[i] = createImage(img_back.width, img_back.height, ARGB); + } + + for(int i =0; i<360; i ++){ + theta = 2*PI*i/360; + int tmp_sin = (int)(sin(theta)*1024); + int tmp_cos = (int)(cos(theta)*1024); + + for(int y2 = 0; y2 < img_back.height; y2++){ + for(int x2 = 0; x2 < img_back.width; x2++){ + // int x1 = (int)((x2-cx)*cos(theta) - (y2-cy)*sin(theta) +cx); + // int y1 = (int)((x2-cx)*sin(theta) + (y2-cy)*cos(theta) +cy); + int x1 = (((x2-cx)*tmp_cos - (y2-cy)*tmp_sin) >> 10) +cx; + int y1 = (((x2-cx)*tmp_sin + (y2-cy)*tmp_cos) >> 10) +cy; + if(x1 >=0 && x1 < img_back.width && y1 >= 0 && y1 < img_back.height){ + img_rotated[i].pixels[x2+y2*img_back.width] = img_back.pixels[x1+y1*img_back.width]; + } + } + } + } +} + +void draw() { + opencv.read(); + image( opencv.image(), 0, 0 ); + Rectangle[] faces = opencv.detect(); + + for( int i=0; i 359){ + angle =0; + } +} + +void keyPressed() { + if (key == ' ') { + if(rec){ + mm.finish(); + } + exit(); + } +} + -- 2.11.0