To create an augmented reality application you do need:
1. Processing 1.5.1 stable or Processing 2
2. Quicktime 7 (Apple video software)
3. Video digitalizer for Quicktime WinVDIG1.0.5.exe, also known as QTCap Basic Quicktime Video Capture
4. Library GSVideo-1.00windows.zip
5. Library NyAR4psg
Execute SimpleLite in examples (there are problems!)
Execute SimpleLite3 given by the teacher with changes in code!
Arduino code:
void setup() {
Serial.begin(9600);
} void loop() {
Serial.println(analogRead(A0));
}
Processing code
The Processing code
import codeanticode.gsvideo.*;
import jp.nyatla.nyar4psg.*;
import processing.serial.*;
Serial myPort;
GSCapture cam;
NyARMultiBoard nya;
PFont font;
String inString = null;
float low = 3.0;
float high = 32.0;
float weight;
void setup() {
size(640,480,P3D);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1],
9600);
myPort.bufferUntil(‘n’);
font = loadFont(“crystal-lightning-64.vlw”);
cam=new GSCapture(this,width,height);
cam.play();
String[] patts = {“scale16.pat”};
double[] widths = {80};
nya = new NyARMultiBoard(this, width, height,
“camera_para.dat”, patts, widths);
print(nya.VERSION);
nya.gsThreshold=120;
nya.cfThreshold=0.4;
}
void draw(){
if (cam.available() !=true) {
return;
}
cam.read();
hint(DISABLE_DEPTH_TEST);
image(cam,0,0);
hint(ENABLE_DEPTH_TEST);
if(nya.detect(cam)){
if (nya.markers[0].detected){
nya.markers[0].beginTransform();
textFont(font,25.0);
textAlign(CENTER);
fill(50, 255, 0);
translate(0,50,80);
rotateX(radians(180));
rotateX(radians(90));
text(weight, 0, 0, 0);
nya.markers[0].endTransform();
}
}
}
void serialEvent (Serial myPort) {
inString = myPort.readStringUntil(‘n’);
if (inString != null) {
inString = trim(inString);
float val = float(inString);
weight = 100+((val-low)*(100/(high-low)));
}
http://www.slideshare.net/slideshow/embed_code/29742603
Video recorded by our teacher assistant Hattie I’Anson under the tuition of professor Francisco Pérez
www.learnar.org Online augmented reality with markers.
www.augmentaty.com Offline free augmented reality with markers.
Augmented reality simple lite
A simple example of NyAR4psg (processing.org augmented reality library)
CODE + folder data (patt.hiro, patt.kanji, camera_para.dat)+ folder code (NyARpsg.jar, NyARToolkit.jar)
/**
NyARToolkit for proce55ing/ v.1.x, 2.x
This sample program is most small sample as simpleLite.
The marker is “patt.hiro”.
*/
import codeanticode.gsvideo.*;
import jp.nyatla.nyar4psg.*;
GSCapture cam;
MultiMarker nya;
void setup() {
size(640,480,P3D);
colorMode(RGB, 100);
println(MultiMarker.VERSION);
cam=new GSCapture(this,640,480);
cam.start();
nya=new MultiMarker(this,width,height,”camera_para.dat”,NyAR4PsgConfig.CONFIG_PSG);
nya.addARMarker(“patt.hiro”,80);
}
void draw()
{
if (cam.available() !=true) {
return;
}
cam.read();
nya.detect(cam);
background(0);
nya.drawBackground(cam);//frustum?????????
if((!nya.isExistMarker(0))){
return;
}
nya.beginTransform(0);
fill(0,0,255);
translate(0,0,20);
box(40);
nya.endTransform();
}
AUGMENTED REALITY ROTATION
Student testing in class NyAR4psg with processing.
/**
NyARToolkit for proce55ing v. 1.x, 2.x
This sample program shows rotation of 2 coordinate system.(left and right).
The marker is “patt.hiro” and “patt.kanji”
*/
import codeanticode.gsvideo.*;
import jp.nyatla.nyar4psg.*;
GSCapture cam;
MultiMarker nya_r;
MultiMarker nya_l;
PFont font=createFont(“FFScala”, 32);
void setup() {
size(640,480,P3D);
colorMode(RGB, 100);
println(MultiMarker.VERSION);
//????????
cam=new GSCapture(this,640,480);
cam.start();
nya_l=new MultiMarker(this,width,height,”camera_para.dat”,new NyAR4PsgConfig(NyAR4PsgConfig.CS_LEFT_HAND,NyAR4PsgConfig.TM_NYARTK));
nya_l.addARMarker(“patt.hiro”,80);
nya_r=new MultiMarker(this,width,height,”camera_para.dat”,new NyAR4PsgConfig(NyAR4PsgConfig.CS_RIGHT_HAND,NyAR4PsgConfig.TM_NYARTK));
nya_r.addARMarker(“patt.kanji”,80);
}
int c=0;
void drawgrid()
{
pushMatrix();
stroke(0);
strokeWeight(2);
line(0,0,0,100,0,0);
textFont(font,20.0); text(“X”,100,0,0);
line(0,0,0,0,100,0);
textFont(font,20.0); text(“Y”,0,100,0);
line(0,0,0,0,0,100);
textFont(font,20.0); text(“Z”,0,0,100);
popMatrix();
}
void draw()
{
c++;
if (cam.available() !=true) {
return;
}
cam.read();
nya_r.detect(cam);
nya_l.detect(cam);
background(0);
nya_r.drawBackground(cam);//frustum?????????
//right
if((nya_r.isExistMarker(0))){
nya_r.beginTransform(0);
fill(0,0,255);
drawgrid();
translate(0,0,20);
rotate((float)c/100);
box(40);
nya_r.endTransform();
}
//left
if((nya_l.isExistMarker(0))){
nya_l.beginTransform(0);
fill(0,255,0);
drawgrid();
translate(0,0,20);
rotate((float)c/100);
box(40);
nya_l.endTransform();
}
}
Augmented reality multimarker
Using NyAR4psg
FIRST CODE
/**
example from nyar4psg modified to demonstrate NyARMultiBoard + NyARMultiBoardMarker by
Charl P. Botha <http://cpbotha.net/>
updated on 20110305 to use the new P3D / OPENGL adaptation I hacked into NyARMultiBoard,
and to show framerate in top-left corner. On this machine, P3D is faster.
*/
// we want to use the gsvideo camera support stack
import codeanticode.gsvideo.*;
// multiple marker tracking
import jp.nyatla.nyar4psg.*;
// only necessary if you’re using the OPENGL renderer (see the size() call in setup())
import processing.opengl.*;
GSCapture cam;
NyARMultiBoard nya;
PFont font, font2d;
void setup() {
// our display is 640×480
size(640,480,P3D);
colorMode(RGB, 100);
font=createFont(“FFScala”, 32);
font2d = createFont(“FFScala”, 10);
// I’m using the GSVideo capture stack, we’re capturing at
// the same size as the display, which should be 640×480
// on Linux with the Sony PS3 Eye
cam=new GSCapture(this,width,height);
cam.start();
// array of pattern file names, these have to be in the data subdir of this sketch
String[] patts = {“patt.hiro”, “patt.kanji”};
// array of corresponding widths in mm
double[] widths = {80,80};
// initialise the NyARMultiBoard
// the camera parameter file is also in the data subdir
nya=new NyARMultiBoard(this,width,height,”camera_para.dat”,patts,widths);
print(nya.VERSION);
// marker detection algorithm parameter
nya.gsThreshold=120;//(0<n<255) default=110
// a marker has to be detected with a confidence greater than
// this threshold for it to be considered a true detection
nya.cfThreshold=0.4;//(0.0<n<1.0) default=0.4
}
// draw marker corners and also position in text
void drawMarkerPos(int[][] pos2d)
{
textFont(font,10.0);
stroke(100,0,0);
fill(100,0,0);
// draw ellipses at outside corners of marker
for(int i=0;i<4;i++){
ellipse(pos2d[i][0], pos2d[i][1],5,5);
}
fill(0,0,0);
for(int i=0;i<4;i++){
text(“(“+pos2d[i][0]+”,”+pos2d[i][1]+”)”,pos2d[i][0],pos2d[i][1]);
}
}
// standard processing event handler that’s called for display updates
void draw() {
// we only do something when the camera input is available
if (cam.available() !=true) {
return;
AUGMENTED REALITY LEDS