-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoundcubes.pde
140 lines (117 loc) · 3.7 KB
/
soundcubes.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import processing.serial.*;
import jp.nyatla.nyar4psg.*;
import java.io.*;
import processing.video.*;
import java.util.*;
import processing.net.*;
import ddf.minim.*;
import guru.ttslib.*;
import java.lang.reflect.Method;
//Settings
boolean useSerial = true;
boolean mirrorImage = true;
String cameraName = "Microsoft LifeCam Front"; //Microsoft LifeCam Front, HD WebCam, FaceTime-HD-kamera (sisäinen), Microsoft LifeCam VX-1000, FaceTime HD Camera (Built-in)
boolean tangibleInterface = true;
boolean speakToUser = true;
//marker detection improvements
boolean markerDiaCleanup = true;
int minimum_dia = 10; //min diameter for marker, to avoid false marker recognitions
boolean markerSideCleanup = true;
int markerSideFactor = 6; //to avoid false markers
boolean limitToFive = true;
boolean showAreaBoxes = true;
//developer features
boolean developer = false;
boolean printFoundMarkers = true;
boolean drawCubeCorners = false;
int port = 5204;
// Number of markers to detect.
int numMarkers = 13;
Server server;
Server testserver;
Client testclient;
Minim minim;
AudioPlayer player;
Cubes cubes;
State state;
Timer timer;
RunOnce runonce;
TTS tts;
LedControl ledControl;
// front_camera_para.dat contains calibration data about Surface Pro 3 front camera.
// Despite calibration data being camera-specific, the same calibration data should
// more or less work with other webcams, since we're only interested in the 2D coordinates
// of the detected markers.
String cameraParameterFile = "front_camera_para.dat";
// patternPath contains data about the available tracking markers.
String patternPath = "ARToolKit_Patterns";
MultiMarker nya;
Capture cam;
// Camera image width and height
int camWidth = 640;
int camHeight = 480;
Serial serialPort;
void setup() {
if (useSerial) {
String serialPortName = Serial.list()[0];
println("Using COM port: " + serialPortName);
serialPort = new Serial(this, serialPortName, 9600);
} else {
serialPort = null;
}
cameraParameterFile = dataPath(cameraParameterFile);
patternPath = dataPath(patternPath);
size(1280, 720);
nya = new MultiMarker(this, camWidth, camHeight, cameraParameterFile, NyAR4PsgConfig.CONFIG_DEFAULT);
nya.setLostDelay(15);
String[] patterns = loadPatternFilenames(patternPath);
if (!limitToFive) {
for (int i = 0; i < numMarkers; ++i) {
println("Adding marker: " + patterns[i]);
nya.addARMarker(patternPath + "/" + patterns[i], 80);
}
}
//5 only
else {
nya.addARMarker(patternPath + "/" + "4x4_01.patt", 80);
nya.addARMarker(patternPath + "/" + "4x4_05.patt", 80);
nya.addARMarker(patternPath + "/" + "4x4_06.patt", 80);
nya.addARMarker(patternPath + "/" + "4x4_08.patt", 80);
nya.addARMarker(patternPath + "/" + "4x4_10.patt", 80);
}
// Camera name is hardcoded, since we're most likely using the Surface Pro 3 front camera.
cam = new Capture(this, camWidth, camHeight, cameraName, 30);
cam.start();
//server = new Server(this, port);
minim = new Minim(this);
player = minim.loadFile("null.wav");
cubes = new Cubes();
tts = new TTS();
this.timer = new Timer();
this.runonce = new RunOnce();
doSetup();
ledControl = new LedControl(serialPort);
}
void draw() {
//logic
if (cam.available() == true) {
cam.read();
PImage processedImage = cam.copy();
if (mirrorImage) {
for (int x = 0; x < processedImage.width; ++x) {
for (int y = 0; y < processedImage.height; ++y) {
color originalColor = cam.get(cam.width - x, y);
processedImage.set(x, y, originalColor);
}
}
}
try {
nya.detect(processedImage);
}
catch (Exception e) {
println(e);
}
doLogic(processedImage);
//serverAction();
}
}