We are about to switch to a new forum software. Until then we have removed the registration on this forum.
http://www.creativeapplications.net/processing/augmented-reality-with-processing-tutorial-processing/ corrected code
import java.io.*; // for the loadPatternFilenames() function
import processing.opengl.*;
import jp.nyatla.nyar4psg.*;
String camPara = "camera_para.dat";
String patternPath = "/patterns";
int arWidth = 1280;
int arHeight = 720;
int numMarkers = 10;
MultiMarker nya;
float displayScale;
color[] colors = new color[numMarkers];
float[] scaler = new float[numMarkers];
PImage input, inputSmall;
void setup() {
size(1280, 720, OPENGL);
textFont(createFont("Arial", 80));
input = loadImage("input.jpg");
inputSmall = input.get();
inputSmall.resize(arWidth, arHeight);
displayScale = (float) width / arWidth;
nya = new MultiMarker(this, arWidth, arHeight, camPara, NyAR4PsgConfig.CONFIG_DEFAULT);
nya.setLostDelay(1);
String[] patterns = loadPatternFilenames(patternPath);
// for the selected number of markers, add the marker for detection
// create an individual color and scale for that marker (= box)
//for (int i=0; i nya.addARMarker(patternPath + "/" + patterns[i], 80); i++){
for (int i=0; i < numMarkers; i++){
nya.addARMarker(patternPath + "/" + patterns[i], 80);
colors[i] = color(random(255), random(255), random(255), 160); // random color, always at a transparency of 160
scaler[i] = random(0.5, 1.9);
}
}
void draw() {
background(0);
image(input, 0, 0, width, height);
nya.detect(inputSmall);
drawMarkers();
drawBoxes();
}
void drawMarkers() {
textAlign(LEFT, TOP);
textSize(10);
noStroke();
scale(displayScale);
//for (int i=0; i PVector[] pos2d = nya.getMarkerVertex2D(i);){
// for (int j=0; j String s = "(" + int(pos2d[j].x) + "," + int(pos2d[j].y) + ")";){
for (int i=0; i < numMarkers; i++ ) {
PVector[] pos2d = nya.getMarkerVertex2D(i);
for (int j=0; j < pos2d.length; j++ ){
String s = "(" + int(pos2d[j].x) + "," + int(pos2d[j].y) + ")";
fill(255);
rect(pos2d[j].x, pos2d[j].y, textWidth(s) + 3, textAscent() + textDescent() + 3);
fill(0);
text(s, pos2d[j].x + 2, pos2d[j].y + 2);
fill(255, 0, 0);
ellipse(pos2d[j].x, pos2d[j].y, 5, 5);
}
}
}
void drawBoxes() {
nya.setARPerspective();
textAlign(CENTER, CENTER);
textSize(20);
//for (int i=0; i++){
for (int i=0; i < numMarkers; i++ ) {
if ((!nya.isExistMarker(i))) { continue; }
setMatrix(nya.getMarkerMatrix(i));
scale(1, -1);
scale(scaler[i]);
translate(0, 0, 20);
lights();
stroke(0);
fill(colors[i]);
box(40);
noLights();
translate(0, 0, 20.1);
noStroke();
fill(255, 50);
rect(-20, -20, 40, 40);
translate(0, 0, 0.1);
fill(0);
text("" + i, -20, -20, 40, 40);
}
perspective();
}
String[] loadPatternFilenames(String path) {
File folder = new File(path);
FilenameFilter pattFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".patt");
}
};
return folder.list(pattFilter);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
I still get java.lang.NullPointerException error.
I copied pattern renamed them as 01...10 and kept in pattern folder in /data folder....
Help please !
Answers
I get gray screen !