How do I use the contour x y location data to send to a MidiBus

edited November 2017 in Questions about Code

Hello all.

I'm currently trying to create a project where Processing reads movements from a webcam to send data to Ableton to trigger sound clips. I have managed to merge two sets of code and am now able to track movement (using IPcapture and OpenCV) but I am struggling to get find the correct code that will help deal with the x y data. I shall post the code I have done and what I want to add. Thank you!

What I have:

import themidibus.*;

import gab.opencv.*;
import processing.video.*;
import ipcapture.*;
import org.opencv.core.Rect;



OpenCV opencv;
IPCapture cam;


void setup() {
  size(640, 480);
  //video = new Movie(this, "street.mov"); MUTED
  cam = new IPCapture(this, "http://153.201.66.43:60001/axis-cgi/mjpg/video.cgi?resolution=640x480", "", "");
  cam.start();
  opencv = new OpenCV(this, 640, 480);

  opencv.startBackgroundSubtraction(5, 3, 0.5);

  //video.loop();coun
  //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, 0, 0);
    strokeWeight(10);
    for (Contour contour : opencv.findContours()) {


  print(contour.getBoundingBox());
      contour.draw();

}

What I want to add:

void onGoLCellChange(boolean state, int x, int y) {
      //mapping from the GoL grid to MIDI messages
      int channel, note, velocity;
      if (y < 10) {
        channel = 0;
        note = x + 20;
        velocity = (y * 5) +30;
      } else {
        channel = 1;
        note = x + 40;
        velocity = y +30;
      }


      if (state == true) {
        midi.sendNoteOn(channel, note, velocity);
      } else {
        midi.sendNoteOff(channel, note, velocity);
      }
    }

The second part is from the Game Of Life code. I have figured this is close to what I want but cannot get it to work. I have tried void onBoundingBox(boolean state, int x, int y) and void oncoutour(boolean state, int x, int y) { but keep getting error messages.

Thank you for your time!

Answers

  • Also, sorry about the formatting. I am new to this site and do not know how to post properly. Sorry for being a noob :/

  • Updated now. I rtfm'd it ;)

  • but keep getting error messages.

    What error messages are you getting?

    Kf

  • edited November 2017

    In the red box it says "Syntax error, maybe missing a semicolon" and in the Console it says expecting SEMI, found 'BoundingBox'

  • Like I said, this new part is just copied from a Game of Life piece of code but I feel if I can get the first line working, I can figure out the rest. Thanks!

  • (Actually, I didn't say I had copied it from game of Life. I did though lol

Sign In or Register to comment.