processing AR

processing AR

augmented reality
拡張現実 - Wikipedia
Augmented reality - Wikipedia, the free encyclopedia

cf.
セカイカメラ
セカイカメラ - Wikipedia

AR三兄弟
トルク with AR三兄弟
AR三兄弟 - Wikipedia



library
nyar4psg + controlP5
NyAR4psg - NyARToolkit
processing GUI, controlP5

import processing.video.*;
import jp.nyatla.nyar4psg.*;

import controlP5.*;

Capture cam;
MultiMarker nya;

ControlP5 cp5;

int Red = 0;
int Green = 127;
int Blue = 255;

int W = 40;
int H = 40;
int D = 40;

void setup() {
  size(640, 480, P3D);
  colorMode(RGB);
  println(MultiMarker.VERSION);
  
  int ss = 12; // SliderSize
  
  cam=new Capture(this, 640, 480);
  nya=new MultiMarker(this, width, height, "camera_para.dat", NyAR4PsgConfig.CONFIG_PSG);
  nya.addARMarker("patt.hiro", 80);
  cam.start();

  cp5 = new ControlP5(this);
  
  // color slider
  cp5.addSlider("Red").setPosition(20, 20).setSize(256, ss).setRange(0, 255);
  cp5.addSlider("Green").setPosition(20, 35).setSize(256, ss).setRange(0, 255);
  cp5.addSlider("Blue").setPosition(20, 50).setSize(256, ss).setRange(0, 255);
  
  // box slider
  cp5.addSlider("W").setPosition(20,75).setSize(100,ss).setRange(1,200);
  cp5.addSlider("H").setPosition(20,90).setSize(100,ss).setRange(1,200);
  cp5.addSlider("D").setPosition(20,105).setSize(100,ss).setRange(1,200);
  
}

void draw()
{
  if (cam.available() !=true) {
    return;
  }
  cam.read();
  nya.detect(cam);
  background(0);
  nya.drawBackground(cam);
  
  strokeWeight(2);
  stroke(255);
  fill(Red, Green, Blue);
  rect(320,20,42,42);
  
  if ((!nya.isExistMarker(0))) {
    return;
  }
  nya.beginTransform(0);
  stroke(0);
  strokeWeight(1);
  translate(0, 0, D*0.5);
  box(W,H,D);
  nya.endTransform();
}