How to use SPOUT input with 11.10: Computer Vision: Adding Lifespan to Blobs - Processing Tutorial

Hello @marijn,

I thought I would take this out for a spin!

Steps:

  • Installed latest TouchDesigner and used the default example and changed output to TDSSyphonSpoutOut
  • Modified the SpoutDataReceiver example that comes with Spout library added to Processing. Partial code below… I only included setup() and draw().
// GLV Edit of SpoutDataReceiver in Examples
// 2023-01-29

//
//            SpoutDataReceiver
//
//      Receive texture and data from a Spout sender
//
//            Spout 2.007
//       https://spout.zeal.co
//

// IMPORT THE SPOUT LIBRARY
import spout.*;

PImage pgr, pgr1; // Canvas to receive a texture

// DECLARE A SPOUT OBJECT
Spout spout;

void setup()
  {
  // Initial window size
  size(640, 360, P3D);
  
  pgr1 = createImage(width, height, RGB);
  
  // Screen text size
  textSize(16);
  
  // CREATE A NEW SPOUT OBJECT
  spout = new Spout(this);

  frameRate(30.0);
  } 

int count = 0;

void draw() 
  { 
  background(0);  
  //
  // RECEIVE FROM A SENDER
  //
  
  if(spout.receiveTexture()) 
    {        
    pgr = spout.receiveTexture(pgr);
    
    if(pgr != null)
      {
      //image(pgr, 0, 0);  
      imageProcess1();     
      
      showInfo();
      count++;
      }   
    }
  println(frameCount, count);  //Check to see if synched 
  }
  
void imageProcess1()
  {
  // Works!  
  //image(pgr, 0, 0);
  //pgr1 = get(); // copy sketch window to pgr1
  
  // Works
  image(pgr, 0, 0);
  loadPixels();     //Required!
  arrayCopy(pixels, pgr1.pixels); // Makes a copy to work with
  
  // Fast and efficient for accessing x, y locations in pixel array
  for(int y=0; y<pgr1.height; y++)
    {
    int tmp = y*pgr1.width;  
    for(int x=0; x<pgr1.width; x++)  
      {
      int loc = x + tmp;
      if (y>height/2)
        {
        if (brightness(pgr1.pixels[loc]) < 128)
          pgr1.pixels[loc] = 0xFFFFFFFF;
        }  
      }
    }
    
  // Efficient for pixel array access
  //for(int i=0; i<pgr1.pixels.length; i++)
  //  {
  //  if (brightness(pgr1.pixels[i]) < 128)
  //      pgr1.pixels[i] = 0xFFFFFFFF;
  //  }  
  
  pgr1.updatePixels();  // Required! 
  image(pgr1, width/2, 0);
  }

And voila!

Left is spout data received.
Right is image processed… see code for details.

image

Thanks for this topic! I had fun with this.

References:
https://processing.org/tutorials/pixels

:)

1 Like