Exporting data

edited October 2013 in How To...

hi there; So I have a PVector that holds lots of position datas.I want to export these datas in to a txt file.I ve already tried the saveStrings() but i got error everytime.So what can i do? Thank you

Answers

  • what error? how are you trying saveStrings()? what kind of data are you trying to export. give us some code! :)

    seriously though, saveStrings() should be the right way, but without some of your code everything is just a shot in the dark to try and troubleshoot.

    ak

  • edited October 2013 Answer ✓

    Got an old example here from the old forum:

    // forum.processing.org/one/topic/saving-mouseevent-data-in-an-array
    // forum.processing.org/two/discussion/160/exporting-data
    
    import java.util.List;
    
    final static List<PVector> coords = new ArrayList();
    
    final static color BG = -1, FG = 0300, BORDER = 0;
    final static short DIM = 20, BOLD = 2, FPS = 100;
    
    void setup() {
      size(640, 480);
      smooth();
      noLoop();
      frameRate(FPS);
    
      fill(FG);
      stroke(BORDER);
      strokeWeight(BOLD);
      background(BG);
    }
    
    void draw() {
      print(coords.size() + " - ");
    }
    
    void mouseDragged() {
      redraw();
      coords.add( new PVector(mouseX, mouseY) );
      ellipse(mouseX, mouseY, DIM, DIM);
    }
    
    void keyTyped() {
      if (key != ' ' & key != RETURN & key != ENTER)  return;
    
      final String archive = dataPath("MouseCoords.txt");
    
      final int num = coords.size();
      final String[] coordsTxt = new String[num];
    
      for (int i = 0; i != num; ++i) {
        //final PVector coord = coords.get(i);
        //coordsTxt[i] = coord.x + "," + coord.y;
    
        final int[] coord = int( coords.get(i).array() );
        coordsTxt[i] = coord[0] + "," + coord[1];
      }
    
      saveStrings(archive, coordsTxt);
      println("\n\nMOUSE COORDS SAVED!\n");
    }
    
  • So code thath I am using is;

            void draw() {
            kinect.update();
            PImage depth = kinect.depthImage();
            image(depth, 0, 0);
            // make a vector of ints to store the list of users
            IntVector userList = new IntVector();
            // write the list of detected users
            // into our vector
            kinect.getUsers(userList);
            // if we found any users
            if (userList.size() > 0) {
            // get the first user
            int userId = userList.get(0);
            // if we’re successfully calibrated
            if ( kinect.isTrackingSkeleton(userId)) {
            // make a vector to store the left hand
            PVector rightHand = new PVector();
            PVector leftHand=new PVector();
    
            // put the position of the left hand into that vector
            float confidence = kinect.getJointPositionSkeleton(userId,
            SimpleOpenNI.SKEL_RIGHT_HAND,
            rightHand);
            float confidence1=kinect.getJointPositionSkeleton(userId,
            SimpleOpenNI.SKEL_LEFT_HAND,leftHand);
            println(confidence1);
            println("Right Hand");
            saveStrings("hey.txt",rightHand); !!!!!!!!!!!!!
            exit();                                        !!!!!!!!!!!!!
            // convert the detected hand position
            // to "projective" coordinates
            // that will match the depth image
            PVector convertedRightHand = new PVector();
            PVector convertedLeftHand=new PVector();
            kinect.convertRealWorldToProjective(rightHand, convertedRightHand);
            kinect.convertRealWorldToProjective(leftHand,convertedLeftHand);
            //println("Converted");
            println(convertedRightHand);
            // and display it
            fill(255,0,0);
            if(confidence>0.5){
            float ellipseSize1=map(convertedLeftHand.z,700,5000,50,1);
            ellipse(convertedLeftHand.x,convertedLeftHand.y,
            ellipseSize1,ellipseSize1);}
            //ellipse(convertedRightHand.x, convertedRightHand.y, 10, 10);
            if (confidence>0.5){
            float ellipseSize = map(convertedRightHand.z, 700, 5000, 50, 1);
            ellipse(convertedRightHand.x, convertedRightHand.y,
            ellipseSize, ellipseSize);}
            }
            }
            }
    

    righthand 's content is :[-124.671906, -1083.6913, 2173.4915] etc. And the error is:__the method saveString(String,String[]) in the type PApplet is not applicable for the arguments (String,PVector)_ _ Thank for your responses!!

  • edited October 2013

    Have you really looked at my example above? Especially within keyTyped()'s for loop block?
    Where a List<PVector> is converted into int[]. And finally into String[]? :-w

    And if you really need float, use the comment out part instead.

  • Yes you are right!!Sorry.I worked it out it is fine now.But I have another question?I would be very pleased if you answer!!

    PVector rightHand = new PVector();
    float confidence1= kinect.getJointPositionSkeleton(userId,
    SimpleOpenNI.SKEL_RIGHT_HAND,
    rightHand);
    if(confidence1 < 0.5){
    rightHand=(PVector) append(rightHand,new PVector(0,0,0));
    return; 
    }
    

    For only this row I want to change the PVector to [0,0,0] when confidence1<0.5 So how can I do that?Thank you !!

  • edited October 2013

    I'm puzzled by your code above! 8-| You're using append() on a non-Array variable -> rightHand. X_X
    Moreover, I don't think Array is the right structure for dynamic-sized lists! /:)
    That's only appropriate when we know in advance how many units we're gonna use!

    Take notice I've chosen List in my own example. More specifically, an ArrayList<PVector> structure. ;;)
    Since saveStrings() demands a String[], only at that point we'd need to temporarily convert our main structure to that 1!

    For only this row I want to change the PVector to [0,0,0] when confidence1 < 0.5.

    When a PVector is instantiated, its default values are [0, 0, 0] already! (~~)
    And to change the values of an existing PVector object, use its set() method!

Sign In or Register to comment.