You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
5.2 KiB
Java
169 lines
5.2 KiB
Java
import org.firmata.*;
|
|
import gab.opencv.*;
|
|
import processing.video.*;
|
|
import processing.serial.*;
|
|
import cc.arduino.*;
|
|
import controlP5.*;
|
|
|
|
OpenCV opencv; // One opencv object needed per region of interest with unique dimension
|
|
|
|
/* CONSTANTS */
|
|
/////////////////// Program Controls
|
|
final long ledDelay = 5000; // Duration of light from LED during LED sequence
|
|
final int recordDelay = 0; // Time delay befoe taking next xcoord in case of lag
|
|
final int paintSize = 100; // Number of xcoord taken in limited paint activity
|
|
|
|
|
|
//////////////////// Image Processing for doodle exploration
|
|
final int roiWidth = 500; // Width of ROI
|
|
final int roiHeight = 500; // Height of region of interest
|
|
final int roiCornerX = 610;
|
|
final int roiCornerY = 290;
|
|
|
|
|
|
final int centerY = 540; // Center Y coordinate
|
|
final int centerX = 860; // Center X coordinate
|
|
|
|
/* Global Variables */
|
|
///////////////// Miscellaneaous Variables
|
|
boolean load = false; // Boolean to determine if user wants to load previously saved led sequences or paint
|
|
long ledTime; // Temporary time storage used to keep LED's on for certain period of time
|
|
long paintTime; // Temporary time storage used to determine when paint "runs out"
|
|
|
|
////////////////// Image Processing Variables
|
|
boolean showcv = false; // Show image tracking during doodle mode
|
|
PImage roiFrame; // Region of interest
|
|
PImage dst; // Backend computer vision
|
|
ArrayList<Contour> contours; // Stores outlines of moving objects within region of interest
|
|
int count; // Equivalent to number of outline
|
|
|
|
///////////////////////// Color Variables
|
|
int iColor=0;//current color
|
|
|
|
float lagTime = 1;
|
|
int totalTime = 15000;
|
|
|
|
|
|
//////////////////// Storage Variables
|
|
IntList paintLimit = new IntList(); // Stores finite limit of XCoord of points drawn. Once limit is reached "drawing" is stopped
|
|
IntList ledDirections = new IntList(); // Stores a certain number of LED pins in the order they will be turned on
|
|
IntList storedColor = new IntList(); // Stores color of each point
|
|
FloatList storedXCoord = new FloatList(); // Stores x-coordinate of each point
|
|
FloatList storedYCoord = new FloatList(); // Stores y-coordinate of each point
|
|
IntList storedPenWidth = new IntList(); // Stores stroke weight of each point
|
|
IntList storedLED = new IntList(); // Stores ledPin numbers
|
|
IntList tempLED = new IntList(); // Duplicates storedLED so the intList can be called again and again without losing any data points
|
|
|
|
|
|
////////////////////// Game Variables
|
|
// Image processing of goal regions in game
|
|
ArrayList<Contour> plusContours; // Stores outlines of moving objects
|
|
ArrayList<Contour> minusContours;
|
|
ArrayList<Contour> euglenaCount;
|
|
PImage o1; // Backend computer vision to make sure image is being processed correctly
|
|
PImage o2;
|
|
PImage o3;
|
|
PImage goal1; // Region of interest
|
|
PImage goal2;
|
|
PImage gameScreen;
|
|
PImage entireScreen;
|
|
PImage cvscreen;
|
|
|
|
static float densityThreshold = 6;
|
|
boolean densityMeasured = false;
|
|
|
|
FloatList fadeXCoord = new FloatList(); // Stores x-coordinate of each point
|
|
FloatList fadeYCoord = new FloatList();
|
|
|
|
Shrink shrink = new Shrink();
|
|
Expand expand = new Expand();
|
|
Translate translate = new Translate();
|
|
Rotate rotate = new Rotate();
|
|
|
|
|
|
void setup() {
|
|
count = 1;
|
|
totalCount = 1;
|
|
background(200);
|
|
|
|
smooth();
|
|
|
|
clearDisplay();
|
|
}
|
|
|
|
/* Runs contionous display of mouse in the background; keeps
|
|
track of what mode app is in and where mouse is on the screen */
|
|
void draw() {
|
|
|
|
if (showcv) { // Show image tracking when CTRL is pressed
|
|
identifyEuglena();
|
|
showCV();
|
|
}
|
|
|
|
recordTimelapse(lagTime, totalTime); //Note: the maximum fps is around 5
|
|
|
|
|
|
for (int i=0; i < shrinkwindows.size(); i++) {
|
|
shrinkwindows.get(i).draw();
|
|
}
|
|
|
|
for (int i=0; i < expandwindows.size(); i++) {
|
|
expandwindows.get(i).draw();
|
|
}
|
|
|
|
for (int i=0; i < translatewindows.size(); i++) {
|
|
translatewindows.get(i).draw();
|
|
}
|
|
|
|
for (int i=0; i < rotatewindows.size(); i++) {
|
|
rotatewindows.get(i).draw();
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/*Uses keys to create uniform movement in the Euglena by turniing LEDs on
|
|
and off with standard directional keys. It also allows calibration of
|
|
the projectorApplet field of view */
|
|
|
|
void keyPressed() {
|
|
|
|
case CONTROL:
|
|
if(showcv) showcv = false;
|
|
else showcv = true;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
} else if (startSession != 7 && startSession != 9) {
|
|
|
|
// Control LED with standard directional keys
|
|
switch(key) {
|
|
|
|
case ENTER: // Takes a snapshot of the FOV
|
|
snapshot();
|
|
break;
|
|
|
|
case 'r': // Toggles between recording timelapse and not recording
|
|
record = !record;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/* Listens for user dragging mouse and draws points of appropriate
|
|
color and width on the screen */
|
|
void mouseDragged() {
|
|
if(mouseX < displayWidth-menu.width){ // Determines if mouse is in drawing area
|
|
stroke(color(rVal, gVal, bVal)); // Sets pent to current color
|
|
strokeWeight(penWidth); // Sets pen to current Width
|
|
|
|
point(convertXCoord(mouseX), convertYCoord(mouseY)); // Moves points on to second monitor with correct sizing
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|