Sending value through osc

Hello everyone,

I am working on a project and i would like to understand how to write if value = 0, don’t send osc message, or instead send another value.

if anyone could help me with this, it would mean a lot .

Have all good day everyone

1 Like

Please post the code of the function.

1 Like
//librairies requises
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
PImage img;

int rouge;
int vert;
int bleu;
int v = 200;
int s = 500;
import gab.opencv.*;
import processing.video.*;
import java.awt.*;

//creation des objets des classes
Capture video;
OpenCV opencv;


/////////////////////////////////////debut du setup
void setup() {
  size(640, 480);
  video = new Capture(this, 640, 480);
  opencv = new OpenCV(this, 640, 480);
  opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE); 
  //rectMode(CORNER);

  video.start();
  oscP5 = new OscP5(this, 12000);
  myRemoteLocation = new NetAddress("127.0.0.1", 9999);
}


////////////////////////////debut du draw
void draw() {

  opencv.loadImage(video);

  image(video, 0, 0 );
  noFill();
  stroke(0, 255, 0);
  strokeWeight(1);

  Rectangle[] faces = opencv.detect();
  println(faces.length);




  for (int i = 0; i < faces.length; i++) {
    println(faces[i].x + ", " + faces[i].y);
    if ( (faces[i].width > 50)  && (faces[i].height > 50)
      && (faces[i].width < s)  && (faces[i].height < s) ) { 
      ellipse(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
      ellipseMode(CORNER);
      



      
      color c=get( faces[i].x+faces[i].width/2, faces[i].y);
     // fill(0);
      noStroke();
      ellipse( faces[i].x+faces[i].width/2, faces[i].y, 20, 20);
      rouge=int(red(c));
      vert=int(green(c));
      bleu=int(blue(c));
      println(rouge+" "+vert+" "+bleu);
      OscMessage myMessage = new OscMessage("/colors");
      myMessage.add(rouge); 
      myMessage.add(vert); 
      myMessage.add(bleu); 
      oscP5.send(myMessage, myRemoteLocation);

      delay(v);

      color c2=get(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height);
    //  fill(0);
      ellipse(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height, 20, 20);
      rouge=int(red(c2));
      vert=int(green(c2));
      bleu=int(blue(c2));
      println(rouge+" "+vert+" "+bleu);
      OscMessage myMessage1 = new OscMessage("/colors");
      myMessage.add(rouge); 
      myMessage.add(vert); 
      myMessage.add(bleu); 
      oscP5.send(myMessage1, myRemoteLocation);

      delay(v);

      color c3=get(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*2);
    //  fill(0);
      ellipse(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*2, 20, 20);
      rouge=int(red(c3));
      vert=int(green(c3));
      bleu=int(blue(c3));
      println(rouge+" "+vert+" "+bleu);
      OscMessage myMessage2 = new OscMessage("/colors");
      myMessage.add(rouge); 
      myMessage.add(vert); 
      myMessage.add(bleu); 
      oscP5.send(myMessage2, myRemoteLocation);

      delay(v);

      color c4=get(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*3);
   //   fill(0);
      ellipse(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*3, 20, 20);
      rouge=int(red(c4));
      vert=int(green(c4));
      bleu=int(blue(c4));
      println(rouge+" "+vert+" "+bleu);
      OscMessage myMessage3 = new OscMessage("/colors");
      myMessage.add(rouge); 
      myMessage.add(vert); 
      myMessage.add(bleu); 
      oscP5.send(myMessage3, myRemoteLocation);

      delay(v);

      color c5=get(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*4);
    //  fill(0);
      ellipse(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*4, 20, 20);
      rouge=int(red(c5));
      vert=int(green(c5));
      bleu=int(blue(c5));
      println(rouge+" "+vert+" "+bleu);
      OscMessage myMessage4= new OscMessage("/colors");
      myMessage.add(rouge); 
      myMessage.add(vert); 
      myMessage.add(bleu); 
      oscP5.send(myMessage4, myRemoteLocation);

      delay(v);

      color c6=get(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*5);
   //   fill(0);
      ellipse(faces[i].x+faces[i].width/2, faces[i].y+faces[i].height*5, 20, 20);
      rouge=int(red(c6));
      vert=int(green(c6));

      bleu=int(blue(c6));
      println(rouge+" "+vert+" "+bleu);
      OscMessage myMessage5= new OscMessage("/colors");
      myMessage.add(rouge); 
      myMessage.add(vert); 
      myMessage.add(bleu); 
      oscP5.send(myMessage5, myRemoteLocation);

      delay(v);


      noFill();
      stroke(0, 255, 0);
      strokeWeight(3);
    }
  }
}///////////fin du draw



void captureEvent(Capture c) {
  c.read();
}
1 Like

I would like to know how to make an argument saying that if the values Rouge, Vert, Bleu are 0, then no need to send the osc message, or just use the previous OSC message

I see that you had difficulties in formatting your code. Maybe it is easier to just type ´´´ at the beginning and at the end of the code.
Please try to edit.
I don’t see the receiver code here.
On the remoteLocation device you need to extract the values from the message like something as code below. Then you can use these extracted global colors in an if block.

void oscEvent(OscMessage myMessage) {
   if(m.checkAddrPattern("/colors") == true) {
     if(m.checkTypetag("iii")) {  // Three integers in message
      vert = myMessage.get(0).intValue(); 
      rouge = myMessage.get(1).intValue();
      bleu = myMessage.get(2).intValue();
     }  
   }
}
2 Likes

Thank you so much Noel! i am still new to Processing, i don’t know much about how to formate my code but i will do some research about it. and yeah the extracting the values now is really helpful. again i really appreciate your help!