Topics
Table of Contents
OSC communication
Το πρωτόκολλο επικοινωνίας OSC είναι το πλέον καθιερωμένο για εφαρμογές πολυμέσων. Η βιβλιοθήκη που μας δίνει την δυνατότητα στην Processing, να στέλνουμε και να λαμβάνουμε OSC μηνύματα είναι η oscP5.
- Useful links
- Βασικό sketch για OSC communication
/**
* oscP5plug by andreas schlegel
* example shows how to use the plug service with oscP5.
* the concept of the plug service is, that you can
* register methods in your sketch to which incoming
* osc messages will be forwareded automatically without
* having to parse them in the oscEvent method.
* that a look at the example below to get an understanding
* of how plug works.
* oscP5 website at http://www.sojamo.de/oscP5
*/
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
void setup() {
size(400,400);
frameRate(25);
/* start oscP5, listening for incoming messages at port 12000 */
oscP5 = new OscP5(this,12000);
/* myRemoteLocation is a NetAddress. a NetAddress takes 2 parameters,
* an ip address and a port number. myRemoteLocation is used as parameter in
* oscP5.send() when sending osc packets to another computer, device,
* application. usage see below. for testing purposes the listening port
* and the port of the remote location address are the same, hence you will
* send messages back to this sketch.
*/
myRemoteLocation = new NetAddress("127.0.0.1",57120);
/* osc plug service
* osc messages with a specific address pattern can be automatically
* forwarded to a specific method of an object. in this example
* a message with address pattern /test will be forwarded to a method
* test(). below the method test takes 2 arguments - 2 ints. therefore each
* message with address pattern /test and typetag ii will be forwarded to
* the method test(int theA, int theB)
*/
oscP5.plug(this,"test","/test");
}
public void test(int theA, int theB) {
println("### plug event method. received a message /test.");
println(" 2 ints received: "+theA+", "+theB);
}
void draw() {
background(0);
}
void mousePressed() {
/* createan osc message with address pattern /test */
OscMessage myMessage = new OscMessage("/test");
myMessage.add(123); /* add an int to the osc message */
myMessage.add(456); /* add a second int to the osc message */
/* send the message */
oscP5.send(myMessage, myRemoteLocation);
}
- Κώδικας στο SuperCollider για αποστολή και λήψη μηνυματων.
//:OSC Responder
OSCresponder(nil, "/test", { |t, r, msg| msg[1].postln;}).add; //Create a Responder
n = NetAddr("127.0.0.1", 12000);
n.sendMsg("/test", 1,2);
OpenCV
Για δημιουργία εφαρμογών στην Processing που χρησιμοποιούν Όραση Υπολογιστών, χρησιμοποιούμε την βιβλιοθήκη OpenCV.
- Βασικό sketch για OpenCV
Ένα απλό sketch που κάνει blob detection είναι το ακόλουθο:
import hypermedia.video.*; import java.awt.*; OpenCV opencv; int w = 320; int h = 240; int threshold = 80; boolean find=true; PFont font; void setup() { size( w*2+30, h*2+30 ); opencv = new OpenCV( this ); opencv.capture(w,h); font = loadFont( "AndaleMono.vlw" ); textFont( font ); println( "Drag mouse inside sketch window to change threshold" ); println( "Press space bar to record background image" ); } void draw() { background(0); opencv.read(); opencv.absDiff(); opencv.threshold(threshold); image( opencv.image(OpenCV.GRAY), 20+w, 20+h ); // absolute difference image Blob[] blobs = opencv.blobs( 400, w*h/3, 1, false ); noFill(); for( int i=0; i<blobs.length; i++ ) { Point centroid = blobs[i].centroid; println(centroid.y); } } void keyPressed() { if ( key==' ' ) opencv.remember(); } void mouseDragged() { threshold = int( map(mouseX,0,width,0,255) ); } public void stop() { opencv.stop(); super.stop(); }
ProcessingJS
Η ProcessingJS είναι η μικρή αδελφή της Processing (P5).
Date: <2011-07-15 Fri>
HTML generated by org-mode 7.4 in emacs 23