JitterとProcessing+JMyronで映像を扱う

本日の予定

前回のFlashでの映像処理に引き続いて、今回はJitterとProcessingでのリアルタイム映像処理について学びます。扱う開発環境に違いによって、向き不向きなどがあるので、どのようなことをやりたいのかによって使いわけるようにすると、効率的に作品の制作ができるのではないかと思います。

本日のスライド

サンプルファイル

目次

本題の前に…

書籍の紹介

Jitterを用いたリアルタイム映像処理

Jitterでのビデオ取り込み

fig01

fig02

Jitter:ビデオ映像の加工、変形

fig03

fig04

RybczynskiエフェクトJitter版

fig05

fig06

音に反応するビデオ映像

fig07

fig08

Jitterでの画像解析

fig09

ビデオ映像を3Dのテクスチャに

fig10

fig11

応用:ビデオ映像で3D形態を変形

fig12

fig13

Processing + JMyronを用いたリアルタイム映像処理

Myron(JMyron)とは

fig14

ちなみに、Myron(JMyron)の由来とは?

fig15

JMyronをインストールする

まずはシンプルに映像を取り込んでみる

fig16

import JMyron.*;

//カメラのオブジェクト
JMyron m;

void setup(){
    size(320,240);
    frameRate(15);
    //カメラのオブジェクトの
    //新しいインスタンスを作成
    m = new JMyron();
    //キャプチャ開始
    m.start(width,height);
    //フレームレートを上げるため
    //画像解析機能をoffにする
    m.findGlobs(0); 
}

void draw(){
    //カメラ映像のアップデート
    m.update(); 
    //カメラの画像をピクセルで取得
    int[] img = m.image();
    //表示画面のピクセル配列をロード
    loadPixels();
    for(int i=0;i<width*height;i++){
	//表示画面の各ピクセル配列に、
	//ビデオ画像のピクセルの配列を読み込み
	pixels[i] = img[i];
    }
    //表示画面のピクセル配列を更新
    updatePixels();
}

public void stop(){
    m.stop();
    super.stop();
}

取り込んだ映像をRGBに分解

fig17

import JMyron.*;
JMyron m;

void setup(){
    size(320*3,240);
    frameRate(15);
    m = new JMyron();
    m.start(width,height);
    m.findGlobs(0);
}
void draw(){
    background(0);
    m.update();
    int[] img = m.image();
    float[] r = new float[width*height];
    float[] g = new float[width*height];
    float[] b = new float[width*height];
    loadPixels();
    for(int i=0;i<width*height;i++){
	r[i] = red(img[i]);
	g[i] = green(img[i]);
	b[i] = blue(img[i]);
    }
    for(int y=0;y<height;y++){
	for(int x=0;x<width;x++){
	    pixels[y*width+int(x/3)]=color(r[y*width+x],0,0);
	    pixels[y*width+int(x/3)+320]=color(0,g[y*width+x],0);
	    pixels[y*width+int(x/3)+640]=color(0,0,b[y*width+x]);
	}
    }
    updatePixels();
}

public void stop(){
    m.stop();
    super.stop();
}

ビデオ映像をピクセレート:その1

fig18

import JMyron.*;
JMyron m;
int camera_width, camera_height;

void setup(){
    size(800,600);
    background(0);
    camera_width = 20;
    camera_height = 15;
    frameRate(15);
    m = new JMyron();
    m.start(camera_width, camera_height);
    m.update();
    m.adaptivity(10);
    m.adapt();
    rectMode(CENTER);
    noStroke();
    smooth();
}

void draw(){
    background(0);
    m.update();
    int col= width/camera_width;
    int row= height/camera_height;
    int[] img = m.image();
    for(int y=0;y<camera_height;y++){
	for(int x=0;x<camera_width;x++){
	    float av = (red(img[y*camera_width+x])+green(img[y*camera_width+x])+blue(img[y*camera_width+x]))/3.0;
	    fill(red(img[y*camera_width+x]),green(img[y*camera_width+x]),blue(img[y*camera_width+x]),128);
	    pushMatrix();
	    translate(x*col+col*0.5,y*row+row*0.5);
	    rotate(av/32.0);
	    rect(0,0,av/4.0, av/4.0);
	    popMatrix();
	}
    }
}

ビデオ映像をピクセレート:その2

fig19

import JMyron.*;
JMyron m;

int camera_width, camera_height;

void setup(){
    size(800,600);
    background(0);
    camera_width = width/36;
    camera_height = height/36;
    frameRate(15);
    m = new JMyron();
    m.start(camera_width, camera_height);
    m.update();
    m.adaptivity(10);
    m.adapt();
    ellipseMode(CENTER);
    noStroke();
    smooth();
}

void draw(){
    m.update();
    float col= width/camera_width;
    float row= height/camera_height;
    int[] img = m.image();
    for(int y=0;y<camera_height;y++){
	for(int x=0;x<camera_width;x++){
	    float av = (red(img[y*camera_width+x])+green(img[y*camera_width+x])+blue(img[y*camera_width+x]))/3.0;
	    fill(red(img[y*camera_width+x]),green(img[y*camera_width+x]),blue(img[y*camera_width+x]),32);
	    pushMatrix();
	    translate(x*col+col*0.5,y*row+row*0.5);
	    ellipse(0,0,(256-av)/4.0, (256-av)/4.0);
	    popMatrix();
	}
    }
}

ビデオ映像をピクセレート:その3

fig20

import JMyron.*;
JMyron m;

int camera_width, camera_height;

void setup(){
    size(800,600);
    background(255);
    camera_width = int(width/15);
    camera_height = int(height/15);
    frameRate(30);
    m = new JMyron();
    m.start(camera_width, camera_height);
    noStroke();
    smooth();
}

void draw(){
    int col= width/camera_width;
    int row= height/camera_height;
    m.update();
    //変化した部分のみ抽出
    int[] img = m.image();
    //カメラのピクセルの明度と色を線の大きさ、色、回転で表現
    for(int y=0;y<camera_height;y++){
	for(int x=0;x<camera_width;x++){
	    float av = 255-(red(img[y*camera_width+x])+green(img[y*camera_width+x])+blue(img[y*camera_width+x]))/3.0;
	    stroke(red(img[y*camera_width+x]),green(img[y*camera_width+x]),blue(img[y*camera_width+x]),128);
	    pushMatrix();
	    translate(x*col+col*0.5,y*row+row*0.5);
	    translate(random(-col,col), random(-row,row));
	    rotate(av/8.0);
	    //rotate(random(PI*2));
	    line(av/20,0,av/-20,0);
	    popMatrix();
	}
    }
}

//マウスクリックで画面クリア
void mouseReleased() {
    background(255);
}

変化した部分だけを、表示する

fig21

import JMyron.*;
JMyron m;

void setup(){
    size(320,240);
    frameRate(15);
    m = new JMyron();
    m.start(width,height);
    m.update();
    m.adaptivity(10);
    m.adapt();
    rectMode(CENTER);
    noStroke();
}

void draw(){
    m.update();
    int[] img = m.differenceImage();
    loadPixels();
    for(int i=0;i<width*height;i++){
	pixels[i] = img[i];
    }
    updatePixels();
}

変化した部分をピクセレイトする

fig22

import JMyron.*;
JMyron m;

int camera_width, camera_height;

void setup(){
  size(800,600);
  background(255);
  camera_width = 40;
  camera_height = 30;
  frameRate(15);
  m = new JMyron();
  m.start(camera_width, camera_height);
  m.update();
  m.adaptivity(10);
  m.adapt();
  noStroke();
  smooth();
}

void draw(){
  int col= width/camera_width;
  int row= height/camera_height;
  m.update();
  //変化した部分のみ抽出
  int[] img = m.differenceImage();
  //カメラのピクセルの明度と色を、四角形の大きさ、色、回転で表現
  for(int y=0;y<camera_height;y++){
    for(int x=0;x<camera_width;x++){
      float av = (red(img[y*camera_width+x])+green(img[y*camera_width+x])+blue(img[y*camera_width+x]))/3.0;
      stroke(red(img[y*camera_width+x]),green(img[y*camera_width+x]),blue(img[y*camera_width+x]),128);
      pushMatrix();
      translate(x*col+col*0.5,y*row+row*0.5);
      translate(random(-col,col), random(-row,row));
      rotate(av/8.0);
      //rotate(random(PI*2));
      line(av*0.25,0,av*-0.25,0);
      popMatrix();
    }
  }
}

//マウスクリックで画面クリア
void mouseReleased() {
  background(255);
}

Comments

コメントはありません

Add Comment

このアイテムは閉鎖されました。このアイテムへのコメントの追加、投票はできません。

トップページに戻る