Augmented Reality marker problem
in
Contributed Library Questions
•
11 months ago
Hello folks,
I'm currently working with AR using processing, ARToolkit and GSVideo, the problem is that when I run the program, it seems to be doing great, but my .obj (my 3D model) appears in the upper left corner of the program's window and
is not linked with the markers, it just walks randomly and disappears into oblivion.
I am using the code found at this webpage:
http://eu.wiley.com/WileyCDA/WileyTitle/productCd-1118036638,miniSiteCd-SYBEX,descCd-DOWNLOAD.html (chapter 6)
also I am using the nyartoolkit library by cpbotha that can be found here:
http://cpbotha.net/files/nyar4psg_multimarker/
I have changed the code so it runs with the newest version of processing (marked in red)
Any comment will be much appreciated.
My code is:
import codeanticode.gsvideo.*;
import jp.nyatla.nyar4psg.*;
import processing.opengl.*;
import saito.objloader.*;
import codeanticode.gsvideo.*;
import java.io.*;
GSCapture cam;
NyARMultiBoard nya;
OBJModel annie ;
PFont font;
PVector move;
PVector xypos;
OBJModel[] anim;
int animFrames = 20;
int animFrame;
boolean animOn= true;
float turn = 0.0;
float prevangle = 0.0;
void setup() {
size(800,600,OPENGL);
cam=new GSCapture(this,width,height);
cam.start();
font=createFont("FFScala", 32);
String[] patts = {"samarker16.pat", "walkmarker16.pat", "turnmarker16.pat"};
double[] widths = {80,80,80};
nya=new NyARMultiBoard(this,width,height,"camera_para.dat",patts,widths);
print(nya.VERSION);
nya.gsThreshold=120;//(0<n<255) default=110
nya.cfThreshold=0.4;//(0.0<n<1.0) default=0.4
int i;
String filename = "";
anim = new OBJModel[animFrames];
for(i = 1; i <= animFrames; i++){
if(i < 10){
filename = "shootinannie-superlowpoly-tri_00000" + i + ".obj";
}else{
filename = "shootinannie-superlowpoly-tri_0000" + i + ".obj";
}
anim[i-1] = new OBJModel(this, filename, "relative", TRIANGLES);
anim[i-1].enableDebug();
anim[i-1].scale(15);
anim[i-1].translateToCenter();
anim[i-1].enableTexture();
anim[i-1].translateToCenter();
}
xypos = new PVector(0,0);
move = new PVector(0, -1);
}
void drawMarkerPos(int[][] pos2d)
{
textFont(font,10.0);
stroke(100,0,0);
fill(100,0,0);
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]);
}
}
void draw() {
if (cam.available() !=true) {
return;
}
background(255);
cam.read();
background(cam);
image(cam, 0, 0, width, height);
PImage cSmall = cam.get();
nya.detect(cSmall); // detect markers in the image
if (nya.detect(cam))
{
for (int i=0; i < nya.markers.length; i++)
{
if (nya.markers[i].detected)
{
drawMarkerPos(nya.markers[i].pos2d);
}
}
if(nya.markers[1].detected){
animOn = true;
}else{
animOn = false;
}
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
perspective();
if (nya.markers[0].detected){
noStroke();
rotateX(radians(-90));
if(nya.markers[2].detected){
turn = nya.markers[2].angle.z;
rotate2D(move, turn-prevangle);
prevangle = turn;
}
translate(xypos.x, xypos.y, 50);
rotateY(turn);
if(animOn){
anim[animFrame].draw();
xypos.add(move);
animFrame++;
if(animFrame == animFrames){
animFrame = 0;
}
}else{
anim[17].draw();
}
}
}
}
void rotate2D(PVector v, float theta) {
float xTemp = v.x;
v.x = v.x*cos(theta) - v.y*sin(theta);
v.y = xTemp*sin(theta) + v.y*cos(theta);
}
1