Averaging data

edited January 2018 in Library Questions

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 two 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
};
}
Tagged:

Answers

  • if you have a follow-on question about the same piece of code it's a good idea to keep it in the same thread.

  • ok, will post in the old one... but as the question was different, thought it was better to create a new thread. thanks

Sign In or Register to comment.