ãååãProcessingで顔認識を使って強制的にアヘ顔になるソフトを作ってみたãã§Processingã§è²ã
åç»ãå¼ã£ã¦ã¿ãããã§ããã©ãåçã®å¦çã¨ãã«ãæ®éã«ä½¿ãããããç¡ãããªã¨ãµã¨æãä½ã£ã¦ã¿ã¾ããã
ãã¡ãªã¿ã«ååã¯ããã ã身ä½ãå¼µã£ãã®ã«ãããããããå
¨ãã¨ãã£ã¦ããã»ã©åé¿ããã¾ããã§ãããå¤åã¿ããªãã³å¼ãããã®ã§ãããããã£ã¦ä»åã§ãã®ã·ãªã¼ãºã¯æçµåã«ãããã¨æãã¾ããã¿ãªããçãéã§ããããæ¸
è´ãããã¨ããããã¾ããã
ã¢ãé¡ç»åçæã½ãã
ãããã§ã¯æ©éã¢ãé¡ã«ãªãã½ããã®ã³ã¼ãã§ããProcessingãOpen CVã®ã¤ã³ã¹ãã¼ã«ã¨ãã£ãæºåã¯前回の記事ãåç §ãã¦ä¸ããããã¨ã¯ä¸ã®ã³ã¼ããã³ãããã¦ãåããã©ã«ãã«ã¢ãé¡ã«ãããåçããsource.jpgãã¨ããååã§ä¿åãã¦å®è¡ããã°OKã§ãã
import hypermedia.video.*; import java.awt.Rectangle; int w = 1024; int h = 768; OpenCV opencv; PImage source_img; PImage ahegao_img; void setup() { size( w, h ); opencv = new OpenCV( this ); opencv.loadImage("source.JPG", width, height); opencv.cascade( OpenCV.CASCADE_FRONTALFACE_ALT ); ahegao_img = loadImage("ahegao.png"); imageMode(CORNER); } void draw() { opencv.read(); image( opencv.image() , 0, 0 ); Rectangle[] faces = opencv.detect(); for( int i=0; i<faces.length; i++){ image(ahegao_img, faces[i].x, faces[i].y, faces[i].width, faces[i].height ); } } void keyPressed() { if(key == 'p' || key == 'P') { // save image save("screenshot.png"); println("screen saved."); } exit(); }
ãint w = 1024; int h = 768; ã¯åçã®è§£å度ã«åããã¦è¨å®ãã¦ä¸ãããããã¾ã大ããã¨ãªã¼ãã¼ããèµ·ããã®ã§ããã®å ´åã¯2ã¨ã3ã§å²ã£ãæ°ãå
¥åãã¦ããã°ããã§ãã
ãå®è¡ãã¦ãã¾ãå
·åã«ã¢ãé¡ã«ãªã£ãããpããæ¼ãã¦ä¸ãããscreenshot.pngãã¨ããã¢ãé¡ãã¡ã¤ã«ãåãåºãã¦ããã¾ãã
å®æ½ä¾
ãå®è¡ä¾ãããã¤ãå ¬éãã¾ãã
ãåãã®ã¢ã¤ãã«ã¯ã¡ä¸¸ãã»ã»ã»
ããããããªãã¢ãé¡ã«
ãã§ãã¼ï¼ã¢ãé¡ããã¨åï¼
ãããããªã¸ã£ã¤ã¢ã³ã
ãã¢ãé¡ã¸ã£ã¤ã¢ã³ã«ï¼
ãã¾ããããªæãã«ã¢ãé¡ã«ãªãã¾ãã ãã¾ãé¡èªèããªãã¨ãã¯ãRectangle faces = opencv.detect();ã®è¡ã®detecté¢æ°ã«é©å½ãªãã©ã¡ã¼ã¿ãå¼æ°ã§ãããã¦ããã¨èªèãã¦ãããã¨ããããã¾ããä¾ãã°ã Rectangle faces = opencv.detect(1.2, 0, 1, 10, 10); ã¿ãããªæãã§ãé¡ã大ããã¨ãã¯ã1çªç®ã¨4çªç®ã¨5çªç®ã®å¼æ°ã大ãããã¦ããã¨ããã§ãã1çªç®ã®å¼æ°ã¯1.1ã2ãããã¾ã§ã®éã§è¨å®ããã®ãããããã§ããããã¾ãå°ããããã¨æéããããã®ã¨èª¤èªèå¤ããªã£ã¦ãã¾ãã詳ããã¯ãªãã¡ã¬ã³ã¹ã調ã¹ã¦ã¿ã¦ä¸ãããã¡ãªã¿ã«åã¯ããç解ã§ãã¾ããã§ããï¼ãã¡ãã¡ï¼ã
ã¢ã¶ã¤ã¯ãã©ãçæã½ãã
ããã²ã¨ã¤ãã¾ãã«ããã©ãã¢ã¶ã¤ã¯ï¼ã¢ã¶ã¤ã¯ç¶ã«ä¸¦ã¹ãåçã§åçã表ç¾ãããã¤ï¼ãã§ãããã ã£ãã®ã§ãã£ã¦ã¿ã¾ãããã¨ãããã»ã¨ãã©ã³ããã§ããã¾ãã¯ã½ã¼ã¹ã³ã¼ãã
import hypermedia.video.*; import java.awt.Rectangle; PImage img; int mosaicWidth = 20; int mosaicHeight = 10; int w = 1024; int h = 768; void setup() { size(w, h); noStroke(); background(0); img = loadImage("source.JPG"); image(img, 0, 0); loadPixels(); } void draw() { println("h="+height); println("w="+width); for(int j = 0; j < height; j+=mosaicHeight) { for(int i = 0; i < width; i+=mosaicWidth) { color c = pixels[j * width + i]; tint(red(c), green(c), blue(c)); image(img, i, j, mosaicWidth, mosaicHeight); } } println("finished!!"); } void keyPressed() { if(key == 'p' || key == 'P') { // save image save("screenshot.png"); println("screen saved."); } exit(); }
ãããã¾ãç´°ããåçã ã¨é¢ç½ããªãã®ã§ãã·ã³ãã«ãªãã®ãããã§ããint mosaicWidth = 20;
int mosaicHeight = 10;ã¯ã¾ãã¯å¤§ããã®å¤ããå¾ã
ã«å°ãããã¦ããã®ãããããªã¨æãã¾ããè¨å®å¤ã«ãã£ã¦ã¯ã¢ã¶ã¤ã¯ç¶ã®çµµãåºã¦ããã¾ã§çµæ§ãªæéããããã¾ãã
å®æ½ä¾
ããããããããã³ã®ã³ç»åã
ããã£ã¨ããéã«ã¢ã¶ã¤ã¯ç¶ã«ãã§ããã®ä¸ã¤ä¸ã¤ããã³ã®ã³ï¼
ãããããåçã©ããã£ã¦ã¤ããã®ããªã¨æã£ã¦ããã®ã§ãããæå¤ã¨åç´ãªã¢ã«ã´ãªãºã ãªãã§ããã
åè
ãProcessingで画像データを扱うã
ããã©ãã¢ã¶ã¤ã¯ã®ããã°ã©ã ã¯ã»ã¨ãã©ããã®ã³ããã§ã
ã絵心がなくても簡単に絵が描ける Processingã
ãããããããé£è¼ãã¹ã¯ãªã¼ã³ã·ã§ããã®ä¿åã®ä»æ¹ã¨ãã¯ãããåèã«ãã¾ãã
ãOpenCV detect()関数のリファレンスã
ãããèªãã§detecté¢æ°ã®å¼æ°å¼ãã°ãé¡èªè精度ãä¸ããäºãã§ããããããã¾ãããåã¯ç解ãã¤ãã¤ãã§ããã