Using Processing2 as backend video processing library (no graphical user interface)

edited March 2014 in Using Processing

Hello there,

I'm wondering (have tried and search but did not succeeded) if it is possible to use Processing2 without a GUI. I have already accomplished working with it directly inside a java app, with a swing GUI, to show a video or capture a webcam and do my manipulation. But is it possible to use it without a GUI?

Thanks!

Answers

  • I don't understand the question at all... what are you referring to as the GUI?

  • edited March 2014

    I wonder if what you meant by the term GUI was Processing's canvas screen? :-?
    Know that the canvas is created only after setup() has finished.
    Just call your program module from setup() then, and create your own swing canvas from there:

    void setup() {
      myProgram();
      exit();
    }
    
    void myProgram() {
      // Your program lives here!
    }
    
  • Yeah, indeed I didn't explain myself properly. Let me rephrase.

    I'm using Processing 2 to process a video, do some analysis and take some snapshots. But there is no need (actually I don't want) to someone see things happening. I'm going to write a standalone java app that the user, or another process, will call passing some parameters (like the video path) and the application will save the snapshots in defined directory.

    So what I call GUI is the window (awt or swing) that the users sees. And I need to be able to process this video, frame by frame, do my analysis, take some snapshots of it and end the process.

  • OK, you did your search, and I agree it isn't necessarily an easy topic to search if you don't know the keywords to search (and even if you know them!).

    This topic has been asked a few time, eg. to run Processing on a Web server. One keyword is headless. Another one is Xvfb, if you run on a Unix-like system.

  • Hello , I need to implement the same. I am also searching for handling the video rotation at the server end . Are you able to find any way to do this ?

  • Hello

    Not sure, it's relevant but you can link 2 sketch together with Client and Server objects. Then your main app should be the server and your tool a client (actually, the opposite work in the exact same way)

    You just need to run the server before the client. But after that, the client can run as a background-process and it's very easy to manage.

    An example :

    1) the sketch that contains the server side

    import processing.net.*;
    
    Server s;
    Client c;
    String input;
    
    int serverId;
    int otherAppId;
    
    void setup() 
    {
      size(500,500);
      serverId = 0;
      otherAppId = 1;
      s = new Server(this, 12345); // Start a simple server on a port
    }
    
    void mousePressed(){
         //send message to every client including server
         //that's why you need to pass the id of the app 
         //at the beginning of each message
         //then the server could know if it receive a message from itself
         //or from a client ; and then, a client know when the server talk to it
         s.write(serverId+"#multiplyByTwo#"+12);
    }    
    
    void draw() 
    {
      c = s.available();
      if (c != null) {
        input = c.readString();
        //check if we receive a message from an other app
        if(int( input.substring(0,1) ) == otherAppId){
            input = input.substring(2);
            float result = float(input);
        }
      }
    }
    

    2) the sketch that contains the client-side only

    import processing.net.*;

    Client c;
    String input;
    
    int serverId;
    int appId;
    
    String multiplyByTwo;
    String multiplyByThree;
    
    void setup() 
    {
      size(500,500);
      serverId = 0;
      appId = 1;
    
    
      multiplyByTwo= "multiplyByTwo";
      multiplyByThree= "multiplyByThree";
    
      c = new Client(this, 12345); // 
    }
    
    void draw() 
    {
      c = s.available();
      if (c != null) {
        input = c.readString();
    
        //check if we receive a message from the server
        if(int( input.substring(0,1) ) == serverId){
            input = input.substring(2);
    
           float val;
           switch(true){
               case input.subtring(0,multiplyByTwo.length() ).equals(multiplyByTwo):
                    val = float( input.subtring(multiplyByTwo.length() ) );
                    c.write(appId+"#"+val*2.0);
                    break;
               case input.subtring(0,multiplyByThree.length() ).equals(multiplyByThree):
                    val = float( input.subtring(multiplyByTwo.length() ) );
                     c.write(appId+"#"+val*3.0);
                    break;
           }
    
        }
      }
    }
    

    I didn't test the code, but I think it should work

  • edited October 2014

    kanchan2mj, have you read the whole thread before posting? Have you done the searches suggested here? Have you a specific problem about a specific implementation?

Sign In or Register to comment.