Hello all.
So my code is now advancing but it's still laggy. It receives the data in Ableton but it's very temperamental. I've avoided using delay functions as it delays the entire thing. If anyone has any suggestions or can see any anomalies it would be much appreciated! Thank you :)
import gab.opencv.*;
import processing.video.*;
import ipcapture.*;
import org.opencv.core.Rect;
import themidibus.*; //Import the library
OpenCV opencv;
IPCapture cam;
MidiBus midi;
int lastMillis;
int [] timestamps = new int [128];
void setup() {
size(640, 480);
//video = new Movie(this, "street.mov"); MUTED
cam = new IPCapture(this, "http://153.201.66.43:60001/mjpg/video.mjpg?resolution=640x480", "", "");
cam.start();
opencv = new OpenCV(this, 640, 480);
opencv.startBackgroundSubtraction(5, 3, 0.5);
MidiBus.list();
midi = new MidiBus(this, -1, "Bus 1");
//video.loop();
//video.play();
}
void draw() {
if (cam.isAvailable()) {
cam.read();
image(cam, 0, 0);
opencv.loadImage(cam);
opencv.updateBackground();
opencv.dilate();
opencv.erode();
noFill();
stroke(255);
strokeWeight(1);
int rx = 300;
int ry = 150;
int rw = 30;
int rh = 15;
rect(rx, ry, rx+rw, ry+rh);
int rx2 = 10;
int ry2 = 10;
int rw2 = 15;
int rh2 = 15;
rect(rx2, ry2, rx2+rw2, ry2+rh2);
stroke(255, 0, 0);
strokeWeight(10);
for (Contour contour : opencv.findContours()) {
println(contour.getBoundingBox().x);
println(contour.getBoundingBox().y);
int x = contour.getBoundingBox().x;
int y = contour.getBoundingBox().y;
contour.draw();
{
int [] numbers = new int [128];
if (( x > rx && x < rx + rw) && (y > ry && y < ry + rh))
for (int i = -1; i < timestamps.length; i++)
midi.sendNoteOn(0, 62, 127);
timestamps[62] = millis();
if (millis()>lastMillis+40)
midi.sendNoteOff(0, 62, 127);
println(timestamps);
}
}
}
}