Processing 2.0 release camera hardware GSvideo
in
Core Library Questions
•
1 year ago
Hi,
I am doing some work that involves processing to read QRcodes that send OSC messages to max to play certain video layers and outputs...
Here lies the problem because in the latest version I want to use the same camera in max after I have stopped the QRcode capture (and release the video camera hardware) in the processing sketch.
I have managed to stop/start the read however I have not been able to release the hardware for max to start up the qt.grab object.
If anyone has an idea of releasing without having to close the sketch down that would be great as it is also something that I want switch on again after the max patch has done its magic. In max when you close the grab object it releases the hardware so no problem there.
Thanks all in advance and I hope this makes sense
Here is the sketch
- import oscP5.*;
- import netP5.*;
- import processing.video.*;
- import com.google.zxing.*;
- import java.awt.image.BufferedImage;
- Capture cam; //Set up the camera
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- com.google.zxing.Reader reader = new com.google.zxing.qrcode.QRCodeReader();
- int WIDTH = 960;
- int HEIGHT = 540;
- String clipNumber = "";
- // Grabs the image file
- void setup() {
- size(960, 540);
- background(100);
- frameRate(25);
- oscP5 = new OscP5(this,12001); //set osc port
- cam = new Capture(this, WIDTH, HEIGHT); //set camera window
- cam.start();
- myRemoteLocation = new NetAddress("127.0.0.1",7400);
- }
- void oscEvent(OscMessage theOscMessage) {
- if(theOscMessage.checkAddrPattern("/startCam")==true) {
- println(theOscMessage);
- cam.start();
- }
- else if(theOscMessage.checkAddrPattern("/stopCam")==true) {
- println(theOscMessage);
- cam.stop();
- }
- }
- void draw() {
- if (cam.available() == true) {
- cam.read();
- image(cam, 0,0);
- try {
- // Test to see if it has a QR code
- LuminanceSource source = new BufferedImageLuminanceSource((BufferedImage)cam.getImage());
- BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
- Result result = reader.decode(bitmap);
- if (result.getText() != null) {
- println(result.getText());
- ResultPoint[] points = result.getResultPoints();
- for (int i = 0; i < points.length; i++) {
- fill(#00a1aa);
- ellipse(points[i].getX(), points[i].getY(), 20,20);
- }
- if (!result.getText().equals(clipNumber)) {
- String movieclip = result.getText();
- OscMessage myMessage = new OscMessage("/"+movieclip);
- println(myMessage);
- oscP5.send(myMessage, myRemoteLocation);
- cam.stop();
- }
- }
- }
- catch (Exception e) {
- //println(e.toString());
- }
- }
- }
1