We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I am working on a sketch that recognises faces and plays notes depending on the location/size of said faces. However, currently the playNote function just repeatedly plays the same note over and over, as opposed to just once.
I realise that the problem currently is that the only way I could find to use the parameters of the face detection rects is to put the playNote in the same brackets as them. Meaning that of course, as the rects are being permanently drawn, so are the notes being permanently created.
How can I have a playNote function that runs on the faces[i] parameters but doesn't have to be in the same 'for' brackets?
All help is greatly appreciated, here is my code currently
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
// audio bits
import ddf.minim.*;
import ddf.minim.ugens.*;
AudioOutput out;
Capture video;
OpenCV opencv;
void setup() {
size(640, 480);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
video.start();
Minim minim = new Minim(this);
out = minim.getLineOut();
}
void draw() {
scale(2);
opencv.loadImage(video);
image(video, 0, 0 );
noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
println(faces.length);
for (int i = 0; i < faces.length; i++) {
println(faces[i].x + "," + faces[i].y);
out.playNote(0, 1, (faces[i].width*2));
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
}
void captureEvent(Capture c) {
c.read();
}
Answers
Could you clarify when do you want to play the notes? For example, if you detect a face, you will play the note once. Would that face play a note again - ever?
For a single play, here I present a partial solution as a modified your line 49 from your posting. However, you will need to continue the implementation of this solution by defining your own way to reset the value of playOnce so for the note to play again.
I hope this helps,
Kf
That's great thank you, that plus an extra float and it's all working :)