Hi everyone!
I’m quite new to processing, so please forgive me if there are any obvious/dumb mistakes here.
I’m working on a sketch where I’m trying to have the webcam read a QR code via BoofCV and have oscP5 deliver the message to an external app (Arena).
The code is working as intended, the problem is that after the QR code is read by Processing, it keeps sending the message to Arena in a loop.
What I’m trying to achieve is store the value of “myMessage” inside a variable, so that in the next loop I can verify if the new message is the same as the old one and have the loop delay the next time the QR is being read.
I tried with a string, but Processing tells me that it can not convert from OscMessage to String.
Can anyone help me out on this?
I’ll attach the code below, but as I said I’m quite new so I beg your forgiveness if anything of the following doesn’t make sense to you :')
import oscP5.*;
import netP5.*;
import processing.video.*;
import boofcv.processing.*;
import java.util.*;
import georegression.struct.shapes.Polygon2D_F64;
import georegression.struct.point.Point2D_F64;
import boofcv.alg.fiducial.qrcode.QrCode;
OscP5 oscP5;
NetAddress myRemoteLocation;
Capture cam;
SimpleQrCode detector;
void setup() {
initializeCamera(640, 480);
surface.setSize(cam.width, cam.height);
detector = Boof.detectQR();
oscP5 = new OscP5(this,12000);
myRemoteLocation = new NetAddress("127.0.0.1",7000);
}
void draw() {
if (cam.available() == true) {
cam.read();
List<QrCode> found = detector.detect(cam);
image(cam, 0, 0);
noFill();
strokeWeight(5);
stroke(255, 0, 0);
for( QrCode qr : found ) {
OscMessage myMessage = new OscMessage(""+qr.message);
myMessage.add(1);
oscP5.send(myMessage, myRemoteLocation);
println (qr.message);
beginShape();
for( int i = 0; i < qr.bounds.size(); i++ ) {
Point2D_F64 p = qr.bounds.get(i);
vertex( (int)p.x, (int)p.y );
}
// close the loop
Point2D_F64 p = qr.bounds.get(0);
vertex( (int)p.x, (int)p.y );
endShape();
}
}
}
void initializeCamera( int desiredWidth, int desiredHeight ) {
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
cam = new Capture(this, desiredWidth, desiredHeight);
cam.start();
}
}