Clipped acumulator/osc?
in
Contributed Library Questions
•
2 months ago
Hi everyone. I'm trying to complete the code for my electroacoustic music exam. The project consists in:
step 1. Isolation and tracking of the blue colour.
step 2. Distinction between straight or curvilinear motion
step 3. Implementation via osc in max/msp or Reaper.
The code is almost done but the last step is driving me crazy. My professor wants me to program a clipped accumulator between 0 and 127, which is driven by red=+increment, yellow=-increment and green=+0. After that,he wants me to send the risult via OSC in order to control a plugin vst inside MAX MSP or Reaper.
Can anyone help me?
import processing.video.*;
Capture video;
float oldbrightestX = 0;
float oldbrightestY = 0;
float oldratio=1;
float thresh = 0.1;
float vel_thresh = 30;
boolean rect_motion = false;
float coeff=0.2;
float p1r;
float p2r;
float p1g;
float p2g;
float p1b;
float p2b;
float pb;
float valore_da_mandare = 0;
//indicazione libreria
import oscP5.*;
import netP5.*;
//inizializzazioni per il client osc
OscP5 clientOscP5;
NetAddress myRemoteLocation;
void setup() {
size(640, 480, P2D);
// Uses the default video input, see the reference if this causes an error
frameRate(10); //abbasso la frameRate a 10 fps
//osc
//port_proc=12000; ???
//port_sc=57120;
clientOscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",12000);
video = new Capture(this, width, height);
video.start();
noStroke();
smooth();
}
void draw() {
if (video.available()) {
video.read();
loadPixels();
// Begin loop for width //per rispecchiare l'immagine orizzontalmente
for (int i = 0; i < width; i++) {
// Begin loop for height
for (int j = 0; j < height; j++) {
pixels[j*width+i] = video.pixels[(width - i - 1) + j*width]; // Reversing x to mirror the image
}
}
updatePixels();
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
float brightestX = 0;
float brightestY = 0;
float brightestValue = 0; // Brightness of the brightest video pixel
// Search for the brightest pixel: For each row of pixels in the video image and
// for each pixel in the yth row, compute each pixel's index in the video
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height-10; y++) {
for (int x = 0; x < video.width; x++) {
// Get the color stored in the two reference pixels
int p1=video.pixels[index];
int p2=video.pixels[video.width*10+index];
p1r=((p1 >> 16) & 0xFF);
p2r=((p2 >> 16) & 0xFF);
p1g=((p1 >> 8) & 0xFF);
p2g=((p2 >> 8) & 0xFF);
p1b=((p1 >> 0) & 0xFF);
p2b=((p2 >> 0) & 0xFF);
pb=((p1b-p1r)+(p1b-p1g))+((p2b-p2r)+(p2b-p2g));
if(pb>brightestValue){
brightestValue=pb;
brightestX=x;
brightestY=y;
}
index++;
}
}
// filtro passa-basso IIR
brightestX=oldbrightestX+(coeff*(brightestX-oldbrightestX));
brightestY=oldbrightestY+(coeff*(brightestY-oldbrightestY));
float drx=brightestX-oldbrightestX; //la derivata del movimento sull'asse x
float dry=brightestY-oldbrightestY; // e sull'asse y
// calcolo velocità del movimento
float veloc=sqrt(pow(drx,2)+pow(dry,2));
//check syntax
//clip(drx,1,100);
//clip(dry,1,100);
float ratio=atan(drx/dry)/log(10); //calcola l'angolo del vettore
float rettilineo=(ratio-oldratio);
if (veloc < vel_thresh)
fill(0, 255, 0, 128); //se il movimento è troppo lento, il pallino sarà verde
else if (rettilineo > thresh) {
rect_motion = false; //rect_motion è false se il movimento è curvilineo e true se è rettilineo
fill(255, 204, 0, 128); } //se il movimento è curvilineo il pallino sarà giallo
else {
rect_motion = true; //sennò sarà rosso
fill(255, 0, 0, 128); }
float addendo= coefficiente+rosso; //???
if (valore_da_mandare > max);
else if(valore_da_mandare < min) {
valore_da_mandare = false;
}
float valore_da_mandare=valore_da_mandare+addendo;
// aggiorno variabili
oldbrightestX = brightestX;
oldbrightestY = brightestY;
oldratio=ratio;
println(rettilineo);
ellipse(brightestX, brightestY, 200, 200);
}
}
1