Categories: Uncategorized

[AR]Try to use NyARToolkit

Background

There is the library for developing maker base AR program.
It’s called ARToolKit.
It’s processing version is NyARToolkit.

Implementation

Download library is from
here.
And copy it to processing’s home directory’s libraries directory.
Then, change the library’s directory name is “nyar4psg”. Program is following.
import jp.nyatla.nyar4psg.*;
import processing.video.*;

// Definition camera device interface
Capture cam;
MultiMarker ar;
// Marker ID
int id;

void setup() {
  // Set size
  size(640,480,P3D);
  // Create camera device interface
  cam = new Capture(this, width, height);
  ar = new MultiMarker(this, width, height, "camera_para.dat", NyAR4PsgConfig.CONFIG_PSG);
  // Register marker
  id = ar.addARMarker("patt.hiro", 60);
}

void draw() {
   // Check whether camera is available
  if (cam.available() == false) return;
  // Get camera image
  cam.read();
  // Draw camera image
  background(0);
  ar.drawBackground(cam);
  // Detect marker
  ar.detect(cam);
  if (ar.isExistMarker(id)) {
    // Draw box
    ar.beginTransform(id);
    fill(116,163,241,100);
    translate(0,0,15);
    box(30);
    ar.endTransform();
  }
}
After save the program, copy nyar4ps/data to the directory.

Result

We can get the following result when we pass printed the marker over a camera.

zuqqhi2