Export CCV data to a comma separated file

Hello, I am new to the world of ccv, tuio and processing and would be greatful for any help with exporting data from blobs in ccv to a file. I have managed to set up ccv to recognize blobs on the field of my camera and would like now to export the position and size of these blobs into a text file (as a comma separated file that gets updated as the blobs move and new ones come into the field of vision). I am trying to do it with processing (i already loaded the TUIO library), but havent managed to go very far with the coding. Any ideas where to start? Thanks

Tagged:

Answers

  • If you have the data in memory and know what the CSV file should look like, then one option is to use Table.

    Create your Table, add a row for each blob, and when you are done, save the table to disk -- it will handle all the specifics of the comma-separated format.

  • Answer ✓

    Is your question about what commands to use to save data to a file? Or how to get the x/y information from the library? Can you post a MCVE of what you have so far?

    You can check the reference (https://processing.org/reference/) under the section Output>>Files related to the former. For your blobs, what library are you using?

    Kf

  • Hi jeremydouglass and kfrajer,

    Thanks for your input.

    This is what i have so far (I moved to tsps and osc in stead of ccv and tuio). So far I can see in the console the data being received, but i want now to, in addition to seeing it, to store it in a csv continuously, as the data comes in. Since i am new to processing (and programming), been trying with tables and saving to a file, but with no success. If you can point me in the right direction, maybe with some examples, I will be grateful.

    Cheers,

    import tsps.*; TSPS tspsReceiver;

    void setup(){ tspsReceiver= new TSPS(this, 12000); };

    void draw(){ TSPSPerson[] people = tspsReceiver.getPeopleArray(); // loop through people for (int i=0; i<people.length; i++){ // get person TSPSPerson person = people[i];

    println("-", person.id,"-", person.age,"-", person.centroid.x,"-",
    person.centroid.y,"-", person.velocity.x,"-", person.boundingRect.width,"-", person.boundingRect.height);

              };
    

    }

  • Look at the reference: loadTable Table etc.

  • been trying with tables and saving to a file, but with no success

    Can you share your attempt? Have you tried the Table / saveTable examples in the reference?

  • Thanks for all the input. I finally managed with output.println this is what finally works:

    import tsps.*;
    TSPS tspsReceiver;
    PrintWriter output;
    
    void setup(){
      tspsReceiver= new TSPS(this, 12000);
    
      // Create a new file in the sketch directory 
       output = createWriter("positions.txt");
       output.println("Year, Month, Day,hour,minutes,seconds,id,age,x,y,velocity,width,height");
        frameRate(10);
    };
    
    void draw()
    {
       // get array of people
        TSPSPerson[] people = tspsReceiver.getPeopleArray();
          // loop through people
         for (int i=0; i<people.length; i++){
        // get person
        TSPSPerson person = people[i];
    
    int yr  = year();
    int mont  = month();
    int dy  = day();
    int hou  = hour();
    int min  = minute();
    int sec  = second();
    
    println(    yr,mont,dy,hou,min,sec, person.id,
                person.age,
                person.centroid.x,       
                person.centroid.y,
                person.velocity.x,
                person.boundingRect.width,
                person.boundingRect.height);    
    
    
    output.println(yr+","+
                    mont+","+
                    dy+","+
                    hou+","+
                    min+","+
                    sec+","+
                    person.id+","+
                    person.age+","+
                    person.centroid.x+","+
                    person.centroid.y+","+
                    person.velocity.x+","+
                    person.boundingRect.width+","+
                    person.boundingRect.height);// Write the info to the file
    
    output.flush();  // Writes the remaining data to the file
    };
    }
    
  • Hello,

    I have the following code (new to this, so apologies for inconsistencies in the code below) that saves the raw data stream sent by TSPS communicating via OSD to a txt. Raw data is OK, but now would like to summarize the raw data to the .txt file. If anyone can help me with the following two questions, I would be very grateful:

    -I would like now to average, "person.boundingRect.width" and "person.boundingRect.width" for each of the blobs ("person.id") that show up, and send these to the txt.

    -Also, I need a conditional formula to evaluate if a person is moving right or left (I guess by subtracting the last and first position (i.e. person.centroid.x) for each person.id) and send this to the same .txt.

    Thanks in advance for any help on this.

    import tsps.*;
    TSPS tspsReceiver;
    PrintWriter output;
    
    void setup(){
      tspsReceiver= new TSPS(this, 12000);
    
      // Create a new file in the sketch directory 
       output = createWriter("positions.txt");
       output.println("Year, Month, Day,hour,minutes,seconds,id,age,x,y,velocity,width,height");
        frameRate(10);
    };
    
    void draw()
    {
       // get array of people
        TSPSPerson[] people = tspsReceiver.getPeopleArray();
          // loop through people
         for (int i=0; i<people.length; i++){
        // get person
        TSPSPerson person = people[i];
    
    int yr  = year();
    int mont  = month();
    int dy  = day();
    int hou  = hour();
    int min  = minute();
    int sec  = second();
    
    println(    yr,mont,dy,hou,min,sec, person.id,
                person.age,
                person.centroid.x,       
                person.centroid.y,
                person.velocity.x,
                person.boundingRect.width,
                person.boundingRect.height);    
    
    
    output.println(yr+","+
                    mont+","+
                    dy+","+
                    hou+","+
                    min+","+
                    sec+","+
                    person.id+","+
                    person.age+","+
                    person.centroid.x+","+
                    person.centroid.y+","+
                    person.velocity.x+","+
                    person.boundingRect.width+","+
                    person.boundingRect.height);// Write the info to the file
    
    output.flush();  // Writes the remaining data to the file
    };
    }
    
  • edited January 2018

    I would like now to average, "person.boundingRect.width" and "person.boundingRect.width"

    You want to average a number with itself? That will always be equal to the original number.

    float avg = (person.boundingRect.width + person.boundingRect.width)/2;
    output.println(avg);
    output.println(person.boundingRect.width);
    
  • hi jeremydouglass, thanks. Sorry but my question was not clear enough. I am attaching a capture of the output table, hopefully it is clearer this way. As you will see, the "id", is a new individual, and the raw output shows, for each frame, the size of the bounding rectange (width and height) and I would like to get the average bounding rectangle for each id. Hope that clarifies it...

    Capture

  • I would like to get the average bounding rectangle for each id

    Are you trying to create an avgwidth, avgheight columns in your output data? Like:

    id, width, height, avgw, avgh
    44,    10,     10,   20,   20
    44,    20,     20,   20,   20
    44,    30,     30,   20,   20
    45,     1,      1,    2,    2
    45,     2,      2,    2,    2
    45,     3,      3,    2,    2
    
  • no...something like this...

    id, av.width, av.height, direction
    44,    10,     10,   right
    45,    12,     21,   left
    46,    31,     32,   right
    47,     13,      18,   right   
    48,     21,      20,   left
    49,     32,      33,   right
    
  • edited January 2018

    One approach:

    1. Use Table (!)
    2. loop through the id column and create a list of unique ids

    Now, for each id:

    1. get all rows matching an id with matchRows https://processing.org/reference/Table_matchRows_.html
    2. loop through each width and sum them, then divide by the number of matching rows
    3. Save the result to a new Table (or an array) with id, avgWidth

    Now you know the avgWidth for each id.

    Another easy way of saving id-linked results is also with a HashMap:

    That makes it easy to build your list of unique ids, easy to store values associated with an id in your dictionary, and easy to look them up. In your case, the HashMap key could be an int (id) and the value could be a PVector (avgWidth, avgHeight). However as you start storing more and more information in the hashmap (like direction) it might be easier to just use Table.

    You could also technically store per-id width and height averages with two floatDicts, but again you end up with one new Dict per column as you add more information -- Table is probably easier.

  • will try with table. thanks!

Sign In or Register to comment.